Comparison content |
Struts |
Webwork2 |
Action class |
In struts All action classes need to extend org. Apache. Struts. action. Action; this will lead to some problems in Java programming, that is, the issue of multiple inheritance. |
Webwork only requires implement COM. opensymphony. xwork. action interface, you can also implement other interfaces to implement more functions, such as: Validate (verification), localware (International), etc, of course, webwork2 also provides a class actionsupport integrated with the above functions. Developers can implement different functions as needed. |
Thread Model |
Struts actions must be thread-safe. It only allows one instance to process all requests. Therefore, all resources used by action must be synchronized in a unified manner, which causes thread security issues. |
Webwork 2 actions each request corresponds to an action, so there is no thread security problem. In fact, the servlet container generates many objects for each request. The example of a request that generates many objects does not prove to have too much impact on the performance. Currently, Web containers process servlet in this way. |
Servlet dependency |
Struts must depend on servletrequest and servletresponse when processing an action. Therefore, this layer cannot get rid of the server container. Serveltrequest may be used by the context of the web layer. |
Each action in webwork2 does not depend on any layer or any container. They use request and response through actioncontext, so this is very important for the separation of the logic layer. |
Test |
Because every action of struts must use request and response, it must be tested through the web layer. This causes many tests of struts to pass the Web Container (although there are many testing methods such as cactus mock ). |
Webwork actions can be granted certain attributes. You can run the command. At the same time, you can use a mock instance for testing, instead of starting a Web container for testing. |
Formbean |
Struts requires a formbeans for each form. However, using dynabeans does not actually make much sense. The existing model cannot be well processed. |
Webwork can dynamically collect web data and assign it to bean. It can also use the formbean mode. Webwork2 also allows existing modeldrvien to be imported. It can be processed just like processing the attributes of an action. |
Front-end Expression Language |
Most of struts uses jstl El (jsp2. 0. Processing on the collection seems weak. |
The webwork front-end can use jstl or multiple forms of representation. For example, velocity freemaker jspparer XML. Webwork2 uses ongl to create a valuestack to collect data |
Type conversion |
Struts formbeans uses all data as the string type. It is very difficult to obtain a desired type and display it to the user. |
Webwork2 data is converted to Java type. This is automatically converted according to the form type. Then it is very convenient to operate these beans. |
Processing before and after actions |
Struts uses class-based hierarchies to process actions. It is difficult to perform operations before and after actions. |
Webwork2 allows you to process an action through interceptor, that is, perform other operations before or after each action is processed. |
Verification Processing |
Because the formbean attributes of struts are considered to be of the string type. Many types of verification must be converted. Formbean cannot process a verification chain. |
Webwork2 adopts the interceptor design mode for verification. This verification method determines its flexibility. In addition, a verification can be repeatedly used and only requires the definition of an XML file. In fact, the xwork verification framework is used for webwork2 verification. |
Action chain control |
Each action in struts corresponds to one processing. It is very difficult to switch an action to another. |
Webwork uses a powerful dispatcherchain to process this action chain. It is very convenient to process from one to another. |