Comparing struts 1 and 2

Source: Internet
Author: User
Comparing struts 1 and 2 Edit page browse Space add page add news
Feature Struts 1 Struts 2
Action classes Struts 1 requires action classes to extend an abstract base class. acommon (General, General) Problem in struts 1 isprogramming (Design) to abstract classes instead of interfaces. An struts 2 ActionMayImplementActionInterface, along with other interfaces toenable (make .. yes) optional and custom services. struts 2 provides a base actionsupport class to implementcommonly used (commonly used) interfaces. albeit (though), the action interface isNotRequired. Any pojo object withExecuteSignature can be used as an struts 2 Action object.
Threading model Struts 1 actions are singletons (singleons) 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 (policy) places restrictions (Limitation) on what can be done with Struts 1 actions and requires extra (additional) care to develop (Extension ). 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 (in practice), servlet containers generate (generated) throw-away objects per request, and one more object does not impose a performance (performance) penalty or impact (IMPACT) garbage collection .)
Servlet dependency Struts 1 actions have dependencies (dependency) on the servlet API since the httpservletrequest and httpservletresponse is passed toExecuteMethod when an action is invoked. Struts 2 actions are not coupled (coupled) to a iner. most often (often) the servlet contexts are represented assimple (simple) maps, allowing actions to be tested in isolation (independent ). struts 2 actions can still (still available) access the original (original, initial) request and response, if required. however, other extends tural (Architecture) elements reduce (reduce) or eliminate (delete) the need to access the httpservetrequest or httpservletresponsedirectly (direct ).
Testability A major (main) hurdle (obstacle) to testing struts 1 actions is thatExecuteMethodexposes (exposed) the servlet API. A third-party extension, Struts testcase, offers (provided) 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 (dependency Injection Support) also makes testing simpler.
Harvesting Input Struts 1 uses an actionform object to capture (capture) input. like actions, all actionforms must extend a base class. since other JavaBeans cannot be used as actionforms, developers (developer) often createredundant (redundant) classes to capture input. dynabeans can used as an alternative (Optional) To creatingconventional (compliant) actionform classes, but, here too, developers may be redescribing (rewritten) Existing (existing, current) JavaBeans.
Struts 2 uses action properties as input properties, eliminating (excluded) the need for a second input object. input properties may be rich (Rich) object types which may have their own properties. the action properties can be accessed from the web page via the taglibs (TAG ). struts 2 also supports the actionform pattern (pattern), as well as pojo form objects and pojo actions. rich object types, including business (business) or domain (domain) objects, can be used as input/output objects. the modeldriven feature simplifies (simplified) taglb references to pojo input objects.
Expression Language Struts 1 integrates (combined) with jstl, So it uses the jstl el. the El has basic object graph traversal (basic object structure traversal), but relatively (relative) Weak collection and indexed property support. Struts 2 can use jstl, but the framework also supports a more powerful (powerful) and flexible (flexible) Expression Language (Expression Language) called "object graph notation language" (ognl ).
Binding values into views Struts 1 uses the standard (standard) JSP Mechanic (mechanism, principle) for binding (binding) objects into (to...) The page context for access. Struts 2 uses a "valuestack" Technology (technology) so that the taglibs can access values without coupling (combination, coupling) Your view to the object type it is rendering (performance ). the valuestack strategy allows reuse of views0000ss (pass through) A range of types (a series 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 (converter) for basic and common object types and primitives.
Validation Struts 1 supports manual validation (manual verification) viaValidateMethod on the actionform, or through an extension (extension, extension) to the commons validator (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 (Link) Validation into sub-Properties Using the validations defined for the properties class type and the validation context.
Control of Action execution Struts 1 supports separate (Allocation) Request processors (processing) (lifecycles) for each module (module, component), but all the actions in the module must share the same lifecycle. Struts 2 supports creating different lifecycles on a per (PER) action basis via interceptor stacks. Custom (custom) stacks can be created and used with different actions, as needed.

Comparing struts 1 and 2

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.