Sunday, October 12, 2014

Difference between Struts1.X and Struts2.X

Difference Area
               Struts 1.X
               Struts 2.X
Action Class
In Struts 1 it's mandatory to extend org.apache.struts.action.Action and implement execute() method which returns ActionForward and accept HttpServletRequest and HttpServletResponse.
This is not the case with Struts 2, here Action class can be a simple POJO or Java object with execute() method. Also execute() method returns String rather than returning ActionForward object.  You can still use  ActionSupport class or Action interface but those are completely optional.
Configuration Files

Front Controller
In struts 1.x front controller is ActionServlet
In struts 2.x front controller is FilterDispatcher
Servlet Dependency
In action class, execute() method , it has HttpServletRequest and HttpServletResponse Object, both comes from servlet API
Not needed in struts 2 execute() method
No Action Form
Struts 1 uses an ActionForm object to capture input. Like Actions, all ActionForms must extend a base class. Since  other JavaBeans cannot be used as ActionForms, developers often create redundant classes to capture input. 
Struts 2 uses Action properties as input properties, eliminating the need for a second input object
Control Of Action Execution
Struts1 supports separate Request Processor (lifecycles) for each module, but all the Actions in a module must share the same lifecycle
Struts 2 supports creating different lifecycles on a per Action basis via Interceptor Stacks.

 Threading Model

Struts 1 Actions are singletons and must be thread-safe since there will only be one instance of a class to handle all requests for that Action. The singleton strategy places restrictions on what can be done with Struts 1 Actions and requires extra care to develop. Action resources must be thread-safe or synchronized.
Struts2, Action objects are instantiated for each request, so there are no thread-safety issues

No comments:

Post a Comment