The core features of the struts 2 framework:
- Pluggable framework architecture that allows request life cycles to be customized for each action.
- Flexible validation framework that allows validation rules to be decoupled from action code.
- Hierarchical approach to internationalization that simplifies localizing applications.
- Integrated dependency injection engine that manages component life cycle and dependencies. (By default, the framework utilizes Spring for dependency injection.)
- Modular configuration files that use packages and namespaces to simplify managing large projects with hundreds of actions.
- Java 5 annotations that reduce configuration overhead. (Java 1.4 is the minimum platform.)
Struts 2 request Processing:
Each and every request made using struts 2 framework fallows the same request processing as below:
- Initially the web browser requests for request. (Ex: /index.acion or /myreport.pdf .. etc)
- The filter dispatcher looks at the request and determines the appropriate action.
- The interceptors automatically apply common functionality to the request, like work flow, validation, and file upload handling.
- The action method executes, usually storing and/or retrieving information from a database.
- The request renders the output to the browser, be it HTML, images, pdf, or something else.
The features added in struts2 over the struts1:
- Programming the abstract classes instead of interfaces is one of the design problem of struts1 framework that has been resolved in struts2.
- Most of the struts2 classes are based on interfaces and most of its core interfaces are HTTP independent.
- Unlike ActionForwards, Struts2 results provide flexibility to create multiple type of outputs.
- Actions in struts1 have dependencies on the servlet API since HttpServlertRequest and HttpServletResponse objects are passed to the execute() Method. But in struts2 any Java class with execute() method can be used as an Action Class. Actions to be neutral to the underlying framework
- ActionForms feature is no more known to the struts2 framework. Simple Java Bean flavored actions are used to put properties directly.
- Struts2 actions are HTTP independent and framework neutral. This enables to test struts2 applications very easily with out resorting mock objects.
- Struts2 tags enables to add style sheet driven markup capabilities. ie. You can create consistent pages with less code. Struts2 tag markup can be altered by changing an underlying stylesheet.
- Struts tags are more capable and result oriented.
- Both JSP and Free maker tags are fully supported.
- Java 5 annotations can be used as an alternative to XML and Java properties configuration.
- Struts 2 check boxes do not require special handling for false values.
- Many changes can be done on fly without restarting the web container.
- Struts1 lets to customize the request processor per module. Struts2 lets to customize request handling per action if desired.
- Struts 2 Actions are spring aware. Just need to add spring beens.
- Struts2 extensions can be added by dropping in jar. No need of any addition XML or properties files. Metadata is expressed through convention and annotations.
Ajax support in Struts2:
- AJAX client side validation
- Remote form submission support (works with the submit tag as well)
- An advanced div template that provides dynamic reloading of partial HTML
- An AJAX-only tabbed Panel implementation
- A rich pub-sub event model
- Interactive auto complete tag
Struts1 and Struts2 at a glance:
Struts 1 vs. Struts 2
- Action Action
- ActionForm Action or POJO
- ActionForward Result
- struts-config.xml struts.xml
- ActionServlet FilterDispatcher
- RequestProcessor Interceptors
- validation.xml Action-validation.xml