struts1.x vs webwork2.x

Source: Internet
Author: User

Special Levy

Struts1.1

WEBWORK2

Action class

Within struts, each action class must inherit an abstract class org.apache.struts.action.Action. This can lead to some problems in Java programming, which is about multiple inheritance issues.

The WebWork Action class only needs to implement the interface Com.opensymphony.xwork.Action, but also can implement other interfaces to achieve more functions, such as: Validate (authentication), Localware (internationalization) and so on. Of course, it also provides a class Actionsupport integrated with all of the above features, which we can choose as needed in development.

Threading model

The action of Struts must be thread-safe, and it allows only one instance to handle all requests. So all the resources that the action uses must be synchronized uniformly, which raises the issue of thread safety.

In webwork, each request corresponds to an action, so there is no thread security issue. In fact, the servlet container also produces multiple objects for each request, and it does not prove to have too many effects on performance and garbage collection.

The dependencies of the servlet

Struts must rely on servletrequest and servletresponse to handle the action, all of which will not be able to escape the servlet container.

WebWork action does not rely on the web layer and other containers. It can be accessed via actioncontext, directly to the request and response, but this is optional and is used only if required.

Test

Each action of struts is coupled with the web layer so that its tests depend on the Web container, and unit tests are difficult to implement. However, there is a junit extension tool struts testcase that can implement its unit tests.

The WebWork action can perform unit tests by giving certain properties. You can also use a mock instance to test instead of starting the Web container.

Formbean

Struts requires Formbean to correspond to each form, and Formbean must inherit the abstract class Actionform. And the use of Dynabeans actually doesn't make much sense. Can not handle the existing models very well.

WebWork can dynamically collect Web data and then assign values to the bean. It can also be in the form of Formbean, Formbean can be a normal dto and domain object, it does not have to regenerate new Formbean based on domain objects, nor does it need to inherit abstract class Actionform.

Front-end Expression language

Struts integrates jstl, so it mainly uses the JSTL expression language to get the data. However, the JSTL expression language is weak in terms of collection and indexed properties.

The WebWork expression language uses powerful OGNL. It uses OGNL to build a ognlvaluestack to search for data. The WebWork front-end can also use JSTL, but it also supports: velocity, Freemaker, Jspparer, XML.

Conversions of types

Struts Formbean all data as String types, and it can be converted using tool commons-beanutils. But its transformation is at class level, and the type of transformation is not configurable. It is also very difficult to return the error message to the user when the type is converted.

WebWork uses OGNL for type conversion, providing all the basic types of conversion functions. Type conversion can be directly to a class (class level) transformation, or the class of the field of type conversion. It can easily return the error message of type conversion to the user by using the interceptor, and the error message can correspond to a corresponding field.

Process before and after action

 

 

 

 

Struts handling action is based on class hierarchies, it is difficult to operate before and after action.

 

 

 

 

WEBWORK2 allows you to handle action through interceptors, is to perform any other action before or after each action is processed. Its interceptor can be dynamically added to the configuration file, so that the action and the interceptor completely decoupled, better implementation of the component.

 

 

 

 

Validation processing

 

 

 

 

The validation of struts is to invoke the Formbean valid Ator () method, in fact, is the verification of Formbean. It generally uses the framework commons validation for data validation processing. It uses a global configuration file Validation.xml defines Formbean authentication information. The Formbean attribute of struts is considered to be of type string, so it requires additional type conversions when validating.

 

 

 

 

webwork Use the Xwork validation framework for validation processing, which can be activated by configuring interceptors. It can specify an XML validation file for each class that needs to be validated, or you can specify different XML validation files for a class in different situations. WebWork can specify the corresponding validation file for each action class, or you can specify the validation file for the action field. The interceptor is used to assemble the action and its validation files so that they are completely decoupled.

 

 

 

 

Control of Action execution

Struts creates an action that can be very difficult if you want to control the order in which it is executed. Even you have to write the servlet again to achieve this functional requirement.

In this respect, the WebWork interceptor stack provides powerful functionality. All aspect functions of the action are implemented by interceptors (such as obtaining request requests parameters, validation processing, etc.) so that you can use the interceptor stack to organize the Interceptor execution order. For example, you would use the IOC framework to set the properties of an action before you set the action attribute with the request request parameter, and vice versa. You can then specify an interceptor stack for the package or action to implement.

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.