Q. What are the similarities between Struts 1 and Struts 2 ? A. Following are the similarities between Struts 1 and Struts 2 :- Both follow the MVC 2 architecture. Both uses request handler and response handler. Both uses tag library. Q. Difference between Struts 1 and Struts 2. A. Difference between Struts 1 and Struts 2 are:- Action classes In case of Struts 1, for creating Struts controller component,  Action classes extends Abstract base class but in case of Struts 2, a base com. opensymphony. xwork 2. ActionSupport class implement the interfaces.  So no Action interface is required. Binding values into views For binding objects into page context Struts 1 uses standard JSP mechanism to access the objects while in Struts 2 by the use of ValueStack technology taglibs can access values without coupling the JSP view to the object type it is rendering. Thread Modelling In Struts 1 Actions are singleton and thread-safe but in the case of Struts 2 there are no thread safety problem because for each request Action objects are instantiated. Servlet Dependency In Struts 1 Actions have Servlet dependencies means that whenever an Action is invoked HttpServletRequest & HttpServletResponse are passed to the execute ( ) method while in Struts 2 Actions are not coupled.Servlet contexts are represented as Maps that allow Actions to be tested. Testability Struts1 action classes are not easy to test as because of Servlet API coupling but in Struts2 Action classes are like simple java classes and testing is done by instantiating the Action and setting their properties.Dependency Injection (DI) makes testing easier. Control of Action Execution For each module Struts 1 provide separate Request Processors.But struts 2 provides creation of different life-cycles on a per Action basis via Interceptor Stacks. Expression Language (EL) Struts 2 uses JSTL EL and EL has weak collection support while Struts 2 uses both EL andJSTL here EL is powerful and flexible more. Validation In Struts 1 Validation is possible by a validate method on the Action Form but in Struts 2 Validation is possible by the validate method and the XWork Validation Framework. Type Conversion In Struts 1 Commons-Beanutils performed type-conversion but in Struts 2 it is performed by OGNL. Q. Explain the Architecture of Struts 2 ? A. The architecture of Struts 2 is based on MVC architecture which is based on technologies such as JavaBeans, ResourceBundles, XML, Locales, Results, Interceptors, etc.
Struts 2 Architecture

Struts 2 Architecture

According to the Struts 2 architecture the different components of Struts 2 can be categorized into the following groups: Servlet Filter: Components that are treated as Servlet filter component are the ActionContextCleanUp, FilterDispatcher and SiteMesh including other filter also. Struts 2 Core: Components that are treated as Core Components are ActionProxy, ActionMapper, Tagsystem, ActionInvocation, ConfigurationManager and Results. Interceptors: Presented both above the Action Components and below the Result Components. User created components:The struts.xml file, The Action classes and Templates are User created components and the user change these configurations they want. The request that comes from the client passes through the Sevlet container such as Tomcat. Then request passes through the chaining system, which involves the three components of Servlet filters. In this system first the HttpServletRequest goes through the ActionContextCleanUp filter.ActionContextCleanUp works with FilterDispatcher and integrate with SiteMesh. Now the FilterDispatcher invokes the actionMapper to determine which request invoke an Action, it handles clean up and execution Actions.It serves static content such as CSS files, HTML files, etc. The ActionMapper maps the HTTP requests and action invocation requests and vice-versa.It return action or null value, if no action invocation request matches. when an Action should be invoked, The ActionProxy is called.It obtains the Action class and calls the appropriate method.This method consults the framework Configuration Manager, that is initialized from struts.xml file.After reading the struts.xml file, an ActionProxy creates an ActionInvocation and determines how the Action should be handled. ActionProxy encapsulates how an action should be obtained, and the ActionInvocation encapsulates how an action is executed. Then with the help of ActionInvocation ActionProxy invokes the Interceptors. Once the Action is determined and executed, the result is generated by Result component. The result component lookup data from the Template.The Template contain Velocity code, freeMarker and JSP which is used to generate the response.The Template uses the Struts tags also, after collecting data from the Template, the Action Invocation produces the result with the help of Intercepters.