Features of Struts2 and architecture
The Struts 2 is framework is used for easier web application development cycle, from building to maintaining the applications.The Struts2 provides the following features :
- POJO based Action :In Struts2 action classes act as the controller. Action classes respond to a user action, execute business logic, and then return a result that tells Struts what view to render. It acts as Model class also.
- Ajax Support :Struts2 supports AJAX with tags and which provide as appearance similar to standard Struts tag and You can design interactive user interface for Web Application. It provides all features of AJAX technology.
- Easy Integration : It provides easy integration with other Web based framework like – Spring, DWR, Tiles and SiteMesh.
- Plug-in Support : The Struts2 provides the number of in build plugging for others framework. And plugging can be created based the Struts2 API in very easy. The following are common pluggins in Struts - DWR Plug-in, JFreeChart Plug-in, JSF Plug-in, JSON Plug-in, JUnit Plug-in, Portlet Plug-in, SiteGraph Plug-in, SiteMesh Plug-in, Spring Plugin, Struts 1 Plug-in, Tiles Plug-in.
- More Expression Language for View : The Struts2 supports the various expression language to create View pages. A developer can design view pages using JSP, JSP-Expression Language, JSP Standard Tag Library, XSLT, Object-Graph Navigation Language (OGNL), FreeMarker and Velocity.
- Tag Support : The Struts2 provides the enhanced tags support to design user interface. All the Struts2 tags are available in single Tag Library Descriptor (TLD) file.
- Themes and Template support : The Struts2 provides the themes and template for common look and feel in you web page by generating HTML that appearance and controls the layout of the control. Struts 2 come with three built-in themes: simple, xhtml, and css_xhtml. If you don’t specify a theme, then Struts 2 will use the xhtml theme by default.
- Result Types : The Struts2 supports the various types of Results. These are Chain Result, Dispatcher Result, FreeMarker Result, HttpHeader Result, Redirect Result, Redirect Action Result, Stream Result, Velocity Result, XSL Result, PlainText Result, Tiles Result.
The architecture of Struts2 Framework is fully based on MVC architecture. The Struts2 architecture has the extensible control layer based on standard technologies, ex – JavaBeans, Resource Bundles, XML, Locals, Results, and Interceptors. The Struts2 architecture are shown below -
The various components of Struts2 can be categorized into the following groups, according to the Struts2 architecture.
- Servlet Filter : The FilterDispatcher, ActionContextCleanUp and SiteMesh are Servlet filter works in architecture
- Struts2 Core : The ActionProxy, ActionInvocation, ActionMapper, tagsSystem and ConfigurationManager and Results are core components of Struts2 architecture.
- Interceptors : The various interceptors are works before and after Action and Result components.
- User defined components : The configuration file struts.xml file, action classes, and templates are user defined components in architecture.
Based on the above diagram, the following steps are comes under lice cycle of Struts2 based application –
- Client sends the request to the Web Container(Tomcat). The web container hands over the request to the application requested by the client
- The Application passes the request to the front controller (FilterDispatcher or StrutsPrepareAndExecuteFilter) based on web.xml. The FilterDispatcher is deprecated after Struts2.1 version
- The StrutsPrepareAndExecuteFilter gets the Action information to be executed from ActionMapper class
- Then Controller calls the ActionProxy, The ActionProxy obtains the information of action and interceptor stack based on struts.xml and struts-default.xml file. The struts-default.xml is part of the struts2 core jar file
- The ActionProxy forwards the request to the ActionInvocation
- The ActionInvocation is responsible to execute all the interceptors and respective action and result is generated and sent back to the ActionInvocation
- The ActionInvocation hands over the response to HttpServletResponse object with the help of controller and Result is sent to the client.
- The client reads the values from ValueStack using expression language and display output on the screen