Summarizes the 12 differences between struts1 and struts2.

Source: Internet
Author: User

1) Complete the number in the action class comparison: struts 1 requires the action class to inherit a general base class keyword mining tool; A detailed problem of struts 1 is the use of general class programming rather than interfaces. The struts 2 Action class can complete an action interface or other interfaces to make optional and customized services possible. Struts 2 provides an actionsupport base class to complete common interfaces. Even if the action interface is not necessary, any pojo class containing the execute method can be used as the action of struts 2.

2) Comparison of the thread form: struts 1 action is a singleton form and must be thread safe, because only one instance of action is used to handle all the requests. The Singleton strategy limits what struts 1 action can do and requires extra caution during development. Action capital must be thread-safe or synchronous. Struts 2 Action targets an instance for every request, so there is no thread security problem.

3) servlet dependency comparison: struts 1 Action relies on servlet API, because the execute method of struts 1 action contains the httpservletrequest and httpservletresponse methods. Struts 2 Action no longer relies on servlet APIs, and then promises that action runs out of the Web Container, thus reducing the difficulty of test action. Of course, if the action needs to directly visit the httpservletrequest and httpservletresponse parameters, Struts 2 action can still visit them. However, most of the time, actions do not need to directly visit httpservetrequest and httpservletresponse, and then give developers more agile choices.

4) Comparison of testability: one of the primary problems in testing struts 1 action is that the execute method relies on servlet API, which enables the action test to rely on Web containers. In order to break away from the Web Container test struts 1 action, it is necessary to use a third-party Extension: struts testcase, which contains a series of mock targets (simulating the httpservetrequest and httpservletresponse targets ), then, you can get rid of the action class of struts 1 in the Web Container test. Struts 2 action can be tested through initialization, setting features, and calling methods.

5) Encapsulation of request parameters: struts 1 uses the actionform target to encapsulate user request parameters. It is necessary for all actionforms to inherit a base class: actionform. Generally, JavaBean cannot be used as an actionform. Therefore, it is necessary for developers to create many actionform classes to encapsulate user request parameters. Although struts 1 provides dynamic actionform to simplify the development of actionform, it still needs to define actionform in the equipment file; struts 2 uses the Action feature directly to encapsulate the user's request features, this avoids the hassle of developing actionform classes for developers. In fact, these features can also be rich target types that contain sub-features. If developers still miss the form of struts 1 actionform, Struts 2 provides the modeldriven form, allowing developers to use their own model targets to encapsulate user request parameters, however, the model target does not need to inherit any struts 2 base class, is a pojo, and then reduces code pollution.

6) Expression Language Comparison: struts 1 combines jstl, so jstl can be used for expression speech. This expression language has a fundamental target graph traversal, but it is not useful in support of the tuning set and index features; struts 2 can use jstl, however, it combines a stronger and more sensitive Expression Language: ognl (object graph notation language). Therefore, the expression language function under struts 2 is more powerful.

7)-Comparison of binding a value to a view: struts 1 binds a target to a view page using the standard JSP mechanism; struts 2 uses the "valuestack" skill to enable the tag library to visit the value, you do not need to bind the target with the view page.

8) Comparison of type conversion: struts 1 actionform is generally string type. Struts 1 uses commons-beanutils for type conversion. Each class has one converter and the converter is not equipped. Struts 2 uses ognl for type conversion to support the transformation between the fundamental data type and common targets.

9) comparison of data verification: struts 1 supports manual verification in the actionform override validate method, and may be completed by combining the commons alidator structure. Struts 2 supports verification by rewriting the validate method and xwork validation structure.

10) Comparison of Action fulfillment control: struts 1 supports each module corresponding to a pleading disposal (that is, the concept of lifecycle). However, it is necessary for all actions in the module to share the same lifecycle. Struts 2 supports interceptor stacks)


-Indexread arguments from command-line "http://www.shoudashou.com"

-Indexread arguments from command-line "http://www.4lunwen.cn"

-Indexread arguments from command-line "http://www.zx1234.cn"

-Indexread arguments from command-line "http://www.penbar.cn"

-Indexread arguments from command-line "http://www.whathappy.cn"

-Indexread arguments from command-line "http://www.lunjin.net"

-Indexread arguments from command-line "http://www.ssstyle.cn"

-Indexread arguments from command-line "http://www.91fish.cn"

-Indexread arguments from command-line "http://www.fanselang.com"

Creates different lifecycles for each action. Developers can create corresponding warehouses as needed and use them with different actions.

11) Capture input: struts1 uses actionform to capture the input. It is necessary for all actionforms to inherit a base class. Because other JavaBean cannot be used as an actionform, developers often create redundant classes to capture input. Dynamic beans (dynabeans) can be used as a choice to create traditional actionforms. However, developers may be describing (creating) Existing JavaBean from scratch (still leading to redundant JavaBean ). Struts 2 uses the Action feature as the input feature to eliminate the need for the second input target. The input feature may be a rich target type with its own (sub) features. Action features can be visited through taglibs on the web page. Struts2 also supports the actionform format. Rich target type, including business target, which can be used as input/output target. This modeldriven feature simplifies taglib's reference to pojo input targets.


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.