Wednesday, July 14, 2010

Advantages of struts2 over struts1.0

• Struts 1 supports separate Request Processors (lifecycles) for each module, but all the Actions in the module must share the same lifecycle, Struts 2 supports creating different lifecycles on a per Action basis via Interceptor Stacks. Custom stacks can be created and used with different Actions, as needed.Struts 1 integrates with JSTL, so it uses the JSTL EL, Struts 2 can use JSTL, but the framework also supports a more powerful and flexible expression language called "Object Graph Notation Language" (OGNL).(Object graph navigation language)( It is aimed to be used in J2EE applications with taglibs as expression language.)
• Struts 1 Actions have dependencies on the servlet API since the HttpServletRequest and HttpServletResponse is passed to the execute method when an Action is invoked. Struts 2 Actions are not coupled to a container. Most often the servlet contexts are represented as simple Maps.
• 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. Struts 2 Action objects are instantiated for each request, so there are no thread-safety issues.
• Struts 1 requires Action classes to extend an abstract base class. A common problem in Struts 1 is programming to abstract classes instead of interfaces. Struts 2 , we can use interfaces.
3. Interceptors
• These are request pre-processors or post processors
• Examples create-session, params, prepare, validation, exception and logger.
o Create-session, which creates HTTPSession.
o Prepare, to run prepare() method.
o Fileupload, to validate a file object
o Exception, handling exceptions.
o Roles, It checks the allowed roles and disallowed roles using intercept() method.
o Servlet-config sets the action properties, based on the different interface implemented.
o Validation, checks the action against all validation rules.

No comments:

Post a Comment