Struts 1 and 2

Source: Internet
Author: User
Apache struts 2 documentationcomparing struts 1 and 2 Edit
Page
Browse Space add
Page
Add
News
Feature Struts 1 Struts 2
Action classes Struts 1Requires (required)Action classes to extend an abstract base class.Common)Problem in struts 1 is programming to abstract classesInstead
Of (replace)
Interfaces.
An struts 2 ActionMayImplementActionInterface, along with other interfaces to enable optional and custom services. Struts 2 provides a base actionsupport class to implement commonly used interfaces. Albeit,
The action interface isNotRequired. Any pojo object with
ExecuteSignature can be used as an struts 2 Action object.
Threading model Struts 1 actions areSingletons (single)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.
Struts 2 action objects are instantiated for each request, so there are no thread-safety issues. (In practice, servlet containersGenerate)Many throw-away objectsPer (PER)Request,
And one more object does not impose a performance penalty or impact garbage collection .)
Servlet dependency Struts 1 actions haveDependencies)On the servlet API since the httpservletrequest and httpservletresponse is passed toExecuteMethod when an action is invoked. Struts 2 actions are notCoupled (coupled)To a container. Most often the servlet contexts areRepresented (Representative)As simple maps, allowing actions to beTested (detection)In
Isolation (isolation). Struts 2 actions can still accessOriginal (original)Request and response, if required. However, other login tural elements reduce or eliminate the need to access
The httpservetrequest or httpservletresponse directly.
Testability AMajor hurdle (main obstacle)To testing struts 1 actions is thatExecuteMethod
Exposes (self-exposure)The servlet API.A third-party extension (third-party software), Struts testcase, offers a set of mock object for struts 1.
Struts 2 actions can be tested by instantiating the action, setting properties, and invoking methods. Dependency Injection Support also makes testing simpler.
Harvesting Input Struts 1 uses an actionform objectCapture)Input. Like actions, all actionforms must extend a base class. Since other JavaBeans cannot be used as actionforms, developers often createRedundant (redundant)Classes
To capture input. dynabeans can used asAlternative (alternative)To creating
Conventional (traditional)Actionform classes, but, here too, developers may be redescribing existing JavaBeans.
Struts 2 uses action properties as input properties,
Eliminating (excluded)
The need for a second input object. input properties may be rich object types which may have their own properties. The action properties can be accessed from the web pageVia)The
Taglibs. Struts 2 alsoSupports (supported)The actionform pattern, as well as pojo form objects and pojo actions. Rich object types, including business orDomain (definition domain)Objects, can
Be used as input/output objects. The modeldriven feature simplifies taglb references to pojo input objects.
Expression Language Struts 1Integrates)With jstl, So it uses the jstl El. The El has basic object graph traversal,Relatively (relative)Weak (weak)
Collection and indexed property support.
Struts 2 can use jstl, but the framework also supports a morePowerful (powerful)And
Flexible (flexible) expression (expression)Language called "object graph notation language" (ognl ).
Binding values into views Struts 1 usesStandard)JSPMechanisms)For Binding objects into the page context for access. Struts 2 uses a "valuestack"Technology)So that the taglibs can access valuesCoupling)Your view to the object type it is rendering.
The valuestack strategy allowsReuse)Of views each ss a range of types which may have the same property name but different property types.
Type conversion Struts 1 actionform properties are usually all strings. Struts 1 uses commons-beanutils for type conversion. converters are per-class, and not allowed per instance. Struts 2 uses ognl for type conversion. The framework has des Converters for basic and common object types andPrimitives (basic entity).
Validation Struts 1 supportsManual (manual) Validation)ViaValidateMethod on the actionform, or through
Extension)To the commons validator. classes can have different validation contexts for the same class, but cannot chain to Validations on sub-objects.
Struts 2 supports manual validation viaValidateMethod and the xwork validation framework. The xwork validation framework supports chaining validation into sub-Properties Using the validations defined for the properties
Class type and the validation context.
Control of Action execution Struts 1 supportsSeparate (separate)RequestProcessors (processor)(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 (custom)Stacks can be created and used with different actions, as needed.

Different actionsS1: struts 1 requires action to inherit an abstract base class. The common problem is that struts1 uses an interface abstract class instead of an interface. S2: struts 2 implements the action interface or Struts provides a base class actionsupport (which implements a common interface). This action class is not required, any pojo object can be struts action objects using execute.ThreadS1: the action of struts 1 is single and must be thread-safe. Because it has only one class to process all action requests, the action must be thread-safe or synchronous S2: the action of struts 2 has been instantiated for each request, so there is no thread security. (The servlets container generates many request objects)Servlet dependencyS1: the action of struts 1 depends on the servlet thread. When an action is called, httpservletrequest and httpservletresponse pass the parameters to the execute () method. (The test depends on the Web Container.) S2: the action of struts 2 is not coupled (dependent). Most servlet contexts are included in maps. (Allow the isolation test of action ).TestabilityS1 :( an obstacle) the action for testing struts 1 is a servlet thread self-exposed by execute. A third-party software provides a set of mock objects to struts 1S2: struts 2 can be tested to pass an action instance and set its attributes and call methods. Dependencies may be simple.Harvesting InputS1: struts 1 uses an actionfrom object to capture input. For example, actions, all actionfroms must inherit a base class, and even other JavaBean cannot be used as actionform. developers often give a redundant class as the capture input dynabeans to be used as a replacement to create a regular actionform class, but developers will re-describe the existing JavaBean

S2: struts 2 uses the action attribute as the INPUT attribute and does not need the second input object. The INPUT attribute is assigned to the object type, which can be accessed from the Web tag. Struts also supports this actionform format, as well as pojo table objects and pojo action objects. This enhances the object type, including business and definition objects. Can be used as a pojo Input and Output object. (Action's own properties encapsulate request parameters to avoid using other input parameters)Bind value to viewS1: struts 1 uses the standard JSP mechanism to bind the object to the upper and lower pages for access. S2: struts 2 uses a valuestack (value stack) technology to mark access to this value. No coupling view is bound to this object, valuestack
View in use
Type conversionS1: struts
1 The actionform attribute is usually a string, and Struts 1 is converted to type S2 using commons-beanutils: struts
2. The ongl conversion type is used. This framework contains the conversion to basic and general types. Basic entities

VerifyS1: struts
1 is manually verified in actionform through the validate () method, or through an extension to this general validator. Classes have different Authentication contexts. S1: struts
2. Manual verification is supported through the validate () method and xwork verification framework. The xwork verification framework allows you to verify the sub-attributes of an object by using the class to which the object property belongs and the verification rules defined by the verification context.
Action execution controlS1: struts 1 supports separate requests to process their respective modules, but actions in this module must share the same lifecycle S2: struts 2 supports creating different lifecycles for each action through the interceptor stack. Custom interceptions can be created and can be used for different actions.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.