SSM College of Engineering and Technology Articles : Introduction of Struts 2 Framework
for contacting SSM College Of Engineering And Technology Srinagar.
Our Information Desk will be forwarding your Query / Comments to the
concerned department for an immediate response. Kindly be patient as
someone will contact you very soon to see if there is anything we can help you with
Information Desk SSM College Of Engineering And Technology Srinagar.
Message Submitted from ec2-54-167-126-106.compute-1.amazonaws.com IP.
Apache Struts 2 is an elegant, extensible framework :
Introduction of Struts 2 Framework
Apache Struts 2 is an elegant, extensible framework for creating enterprise-ready Java web applications. The framework is designed to streamline the full development cycle, from building, to deploying, to maintaining applications over time.
Apache Struts2 was originally known as WebWork 2. After working independently for several years, the WebWork and Struts communities joined forces to create Struts2. This new version of Struts is simpler to use and closer to how Struts was always meant to be.
Struts 2 is a pull-MVC framework. i.e. the data that is to be displayed to user has to be pulled from the Action.
Struts2 supports annotation based configurations which are easy to create and more intuitive. Action class in Struts 2 act as the model in the web application. Unlike Struts, Struts 2 Action class are plain POJO objects thus simplifying the testing of the code. Struts2 also comes with power APIs to configure Interceptors that reduce greatly the coupling in application. The view part of Struts 2 is highly configurable and it supports different result-types such as Velocity, FreeMarker, JSP, etc.
Architecture of Struts 2
Struts 2 Architecture is based on WebWork 2 framework. It leverages the standard JEE technologies such as Java Filters, JavaBeans, ResourceBundles, Locales, XML etc in its architecture. Following is its framework diagram.
The normal lifecycle of struts begins when the request is sent from client. This results invoke the servlet container which in turn is passed through standard filter chain.
The FilterDispatcher filter is called which consults the ActionMapper to determine whether anAction should be invoked.
If ActionMapper finds an Action to be invoked, the FilterDispatcher delegates control to ActionProxy.
ActionProxy reads the configuration file such as struts.xml. ActionProxy creates an instance ofActionInvocation class and delegates the control.
ActionInvocation is responsible for command pattern implementation. It invokes the Interceptors one by one (if required) and then invoke the Action.
Once the Action returns, the ActionInvocation is responsible for looking up the proper result associated with the Action result code mapped in struts.xml.
The Interceptors are executed again in reverse order and the response is returned to the Filter (In most cases to FilterDispatcher). And the result is then sent to the servlet container which in turns send it back to client.
Request Processing Lifecycle
The request processing lifecycle of Struts2 framework is pretty much discussed in above section where we saw the architecture of Struts 2 framework.
Request is generated by user and sent to Servlet container.
Servlet container invokes FilterDispatcher filter which in turn determines appropriate action.
One by one Intercetors are applied before calling the Action. Interceptors performs tasks such as Logging, Validation, File Upload, Double-submit guard etc.
Action is executed and the Result is generated by Action.
The output of Action is rendered in the view (JSP, Velocity, etc) and the result is returned to the user.
AJAX Support in Struts 2
AJAX is a well known term in web development. It is now possible to write desktop like web2.0 application using AJAX. Untill Struts 1.x, developer had to write and maintain the code in to add AJAX support. But now Struts 2 gives you ‘out of the box’. No writing of , no debugging against various browsers; just configure and go.