The difference between struts1 and strut2

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Struts1 and Struts2 are two completely different frame

The working process of struts1:

Release of Struts Web services, according to the web.xml initialization ActionServlet, ActionContext and other content.

After receiving an HttpRequest request,According to the configuration of ActionServlet content in struts-config.xml,The parameters of the request to the corresponding Formbean,And set the session. and Action parameters according to the request of,Find the specified in struts-config.xml Action,And call the Action to handle the request. According to the result of Action,Returns a forward variable,This time through the mapping.findForward () to find out the corresponding forward labeled Action or JSP page,The request to the next processing. If the forward points to an JSP page,The output to the front desk.

The working process of Struts2:

(1)The client submits an HttpServletRequest request (.Action or JSP page)

(2)The request was submitted to a series of Filter filters, such as ActionCleanUp and FilterDispatcher etc.

(3)FilterDispatcher is the core of Struts2 controller, it is usually the last filter in the filter chain

(4)Request to the FilterDispatcher, FilterDispatcher ask ActionMapper if need to call a Action to the Request (according to URL suffix is.Action to judge)

(5)If ActionMapper decides to call a Action, FilterDispatcher is the request to the ActioProxy, processed by it.

(6)ActionProxy by Configuration Manager (it will access struts.xml) query framework configuration file, find the need to call the Action class.

(7)ActionProxy creates an instance of ActionInvocation, and ActionInvocation through the proxy mode called Action, (before invoking the Interceptor interceptor will all according to the configuration file loading related)

(8)Action after the execution is completed, return a result string, and then in the opposite order through the Interceptor interceptor.

(9) Finally, ActionInvocation is responsible for the result element in the struts.xml configuration, to find the corresponding result and the return value, decided the next output.


Difference:

/**The Action class

Struts1 requires the Action classes inherit from an abstract class, the use of abstract classes instead of Struts1 programming interface

Struts2 can implement the Action interface can not realize, Struts2 provides a ActionSuport class to achieve common interface. Action interface is not required, any execute identification of POJO are likely to become the object of Struts2 Action

/**Thread model

Struts1 Action is the singleton pattern and is thread safe, Action only one instance to process all requests. Single mode limits the Struts1 Action can do. In the development to the attention of Action resources must be thread safe and is synchronous.

The Struts2 Action object for each request creates an instance, so there is no thread safety issues.

/**Servlet dependent

The Struts1 Action dependent and Servlet API, for when a Action is called HttpServletRequest and HttpServletResponse is passed to the execute method.

Struts2 Action do not depend on the container, allowing Action to disengage the container was tested separately. If necessary, Struts2 can still access the initial request and response. However, other elements to reduce or eliminate the necessity for direct access to HttpServletRequest and HttpServletResponse.

/**Expression language

Struts1 JSTL integration, the use of JSTL EL. The EL has a basic object graph traversal, but for collection and index properties of the support is very fragile.

Struts2 can use JSTL, but also support a more powerful and flexible expression language --“object graph Notation Language”(OGNL)

/**Check

Struts1 support in validate in the ActionForm method of the manual calibration, or extended by Commons Validator to check. Can the same type checking different contents, but cannot verify the sub object.

Struts2 support. By the method of validate and XWork checksum verification framework. XWork verification framework used for checking and content verification attribute class type definition, to support the Chain check sub attribute.

/**The implementation of the control Action

Struts1 supports each module has a separate Request Processors (life cycle), but all of the Action modules must share the same life cycle.

Struts2 is supported by the interceptor stack (Interceptor Stacks) could not be created for each of the Action life cycle. Stack according to the need and the different Action.

/**Type conversion

The Struts1 ActionForm attribute is usually String type. Struts1 use Commons-Beanutils type conversion. Each class of a converter is not configured on a per instance

Struts2 use OGNL type conversion, to provide basic and common objects of the converter.

/**The bound value to the page(view)

Struts1 use the standard JSP mechanism. The object bound to the page to access.

Struts2 uses the ValueStack technology, the taglib can access the value without the need to make your pages (view) and object binding. ValueStack strategy allows through a series of the same name but different types of attribute weight with the page(view)

/**Capture input:

Struts1 use the ActionForm object to capture the input. All ActionForm must inherit a class. Because JavaBean cannot be used as a ActionForm, developers often create excess base not or input. Dynamic Bean (DynaBeans) can be created as traditional ActionForm choice, however, developers may be in the re description (create) existing JavaBean (still leads to a sink of JavaBean).

Struts2 directly using the Acrtion attribute as input attributes, the elimination of second input object request. The input attributes may have their own (sub) Rich object type property. The Action property can through the web page Taglibs access. Struts2 also support ActionForm mode. The Richard object types, including business object, can be used as input / output object. The ModelDriven simplifies the Taglib input to the POJO object reference.




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Ogden at November 16, 2013 - 10:26 PM