struts1, WebWork as well as profiles and compare struts2

2010-03-29  来源:本站原创  分类:Java  人气:422 

Struts 1 Introduction and problems in perspective from the past years, Struts 1 is a MVC framework for all indisputable winner, regardless of market share, is still owned by the development of people, Struts 1 have incomparable to other MVC frameworks advantage. Struts 1's success due to its wealth of documentation, active development community. Of course, Struts 1 is the first release of MVC frameworks: Struts 1.0 in the June 2001 release, which may be to make it the main reason to be so widely embraced.
To make the reader can understand the Struts 1 of the operating mechanism, the following will briefly introduce the basic framework of Struts 1.
Struts 1 framework to ActionServlet as the core controller, the entire application driven by client requests. When a client sends a request to the Web application, the request will be the core of Struts 1 controller ActionServlet interception, ActionServlet, upon request, decide whether you need to call business logic controller handles user requests (in fact, business logic controller or a controller, it's just call model is responsible for processing user requests), when the user request processing is completed, the results of its processing through the JSP presented to the user.
For the entire Struts 1 framework, the controller is its core, Struts 1 controller consists of two parts: a core controller and business logic controller. The core controller is ActionServlet, from the Struts 1 Framework provides; business logic control is a user-defined Action, by the application developers.
For the majority of user requests, the server will need to be addressed. When a user sends a request needs to be server processing, the request is ActionServlet intercepted, ActionServlet forwards the request to the corresponding business logic controllers, business logic controller called model to handle user requests; If the user requests just want to get a certain a URL of resources will be requested from the resource ActionServlet forwards to the user.

Struts 1 Here's a concrete analysis of the program flow MVC in three roles.
(1) Model section
Struts 1 of the Model some of the major components of business logic from the underlying act, which encapsulates the underlying business logic components database access, business logic method implementations. In fact, for a mature enterprise applications, Model part is not a simple JavaBean can be completed, it may be one or more EJB components, may be a WebService service. In short, Model part of the package, the entire application for all business logic, but not for the whole part of the Struts 1 provided, Struts 1 has failed to provide any support to achieve Model component.
(2) View part of the
Struts 1 of the View part of the adoption of JSP implementation. Struts 1 provides a rich tag library, through which tag library can minimize the use of scripts. The custom tag library can output controller processing results.
Although the Struts 1 provides a framework for integration with Ties, but supported by the performance of Struts 1 is a single layer: it will neither support for FreeMarker, Velocity templates and other technologies, such statements do not support JasperReports technology.
(3) Controller part of the
Struts 1 The Controller consists of two parts.
- Core of the system controller: from Struts 1 framework provides that the system ActionServlet.
- Business logic controllers: from Struts 1 framework provides is the user's own example of achieving the Action.
Struts 1 corresponds to Figure 1.7 of the core controller in the core controller (ActionServlet). The controller is provided by the Struts 1 framework, inheritance HttpServlet class, it can be configured as a standard Servlet, the controller is responsible for intercepting all HTTP requests, and then decide whether the request based on the user need to call business logic controller, if you need to call the business logic control device, the request will be forwarded to the Action processing, or moving directly to the requested JSP page.
Business logic controller responsible for handling user requests, but the business logic controller itself does not have the processing power, but rather call the Model to complete the deal.
Struts 1 provides a system required core controller, but also to achieve the business logic controller provides a lot of support. Therefore, the controller part is the core of Struts 1 framework. Sometimes, we called the controller directly to the MVC layer layer.
Tip for any of the MVC framework, in fact only achieved a C (controller), but it's with the controller is responsible for calling business logic components, and is responsible for controller and view technologies (JSP, FreeMarker, and Velocity, etc.) integration.
For the Struts 1 framework, because it is JSP / Servlet very closely coupled, resulting in a number of unavoidable shortcomings, with the gradual expansion of Web applications, these shortcomings gradually become a major constraining factor in the development of Struts 1 - This is the Struts 2 comes into play. Struts 1 following a detailed analysis of the shortcomings that exist.
(1) support the performance of single-layer technology
Struts 1 only supports JSP as a presentation layer technology, does not provide and other presentation layer technologies such as Velocity, FreeMarker integration of technologies such as. This severely constrains the Struts 1 framework for the use of many of the current Java EE applications, not necessarily the use of JSP as the presentation layer technology.
Although the Struts 1, after processing the user requests, and did not go directly to a particular view of resources, but returns an ActionForward object (ActionForward can be understood as a logical view name), in the struts-config.xml file defines the logical view name and view The corresponding relationship between resources, when the ActionServlet to be returned ActionForword processor object may be based on logical view name and view the correspondence between resources would be the view of resources presented to the user.
From the above, the design of the designers had to admire the Struts 1 a high degree of decoupling of the design: controller and there is no direct implementation of forwarding the request, but only to return a logical view name - the actual transponder placed in the configuration file management. But because Struts 1 framework is too early an age, and was not yet FreeMarker, Velocity and other technologies, and thus not considered with these FreeMarker, Velocity other view technology integration.
Tips Struts 1 has passed the configuration file name and the actual management of the logical view of the correspondence between the view, but there is no logical view names to give its view can support more technology.
Although the Struts 1 has a very good design, but due to historical reasons, it did not provide the integration of technology with a wider view, which severely limits the use of Struts 1.
(2), coupled with the Servlet API serious and difficult to test because the Struts 1 framework is based on the Model 2 developed, so it is entirely based on Servlet API, so the business logic in the Struts 1 controller, filled with a large number of Servlet API.
Action See the following code snippet:
/ / Business logic controller must inherit Struts 1 provided by the Action class
public class LoginAction extends Action
(
/ / Execute method of handling user requests
public ActionForward execute (ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws
AuctionException
(
/ / Get package user request parameters ActionForm object
/ / Be cast to log on using ActionForm
LoginForm loginForm = (LoginForm) form;
/ / When a user named scott, password tiger returns successfully
if ( "scott". equals (loginForm.getUsername ()
& & "Tiger". Equals (loginForm.getPassword ())
(
/ / Handle success, returns an ActionForward object
return mapping.findForward ( "success");
)
else
(
/ / Handle failure, return an ActionForward object
return mapping.findForward ( "success");
)
)
)
When we need to test above the Action class execute method, the method has four parameters: ActionMapping, ActionForm, HttpServletRequest and HttpServletResponse, initialize these four parameters is difficult, especially the HttpServletRequest and HttpServletResponse two parameters, usually by the Web container is responsible for instantiation.
Since the HttpServletRequest and HttpServletResponse two parameters are Servlet API, is heavily dependent on the Web server. Therefore, once detached from the Web server, Action of the test very difficult.
(3) The code is heavily dependent on the Struts 1 API, are intrusive design as the code snippet from the above can see, Struts 1 of the Action class must inherit Struts 1 of the Action base class to achieve treatment methods, but also contains a large number of Struts 1 API: If ActionMapping, ActionForm, and ActionForward class. This invasive greatest weakness lies in the design, once the system needs reconstruction, these Action classes will have no use value, became a pile of waste.
Can be seen, Struts 1 of the Action category of such intrusive design has led to a lower code reuse.
Introduction 1.2.2 WebWork
WebWork Although there is no Struts 1 as famous, but also well-born, WebWork an excellent open-source from another organization: opensymphony, an excellent open-source organization also has developed a lot of good open source projects, such as Qutarz, OSWorkFlow so. In fact, WebWork, founder of the field is another Java Masters: Rickard Oberg (He is the author of JBoss and XDoclet).
Relative to the Struts 1 congenital lack of the existence of those terms, WebWork is even more outstanding, it uses a more loosely coupled design, the system of the Action is no longer coupled with the Servlet API. To make unit testing more convenient, allowing the system from the B / S structure to a C / S structure conversion.
Relative to the Struts 1 supports only JSP presentation layer technology, in terms of defects, WebWork support more of the presentation layer technologies such as Velocity, FreeMarker, and XSLT and so on.
WebWork be freed from the Web application to use, it does not seem much advantage, because it often starts as an application has been to determine what kind of environments. WebWork has its own control inversion (Inversion of Control) container, through the inversion of control, you can make it easier to test, test, service interface is set to achieve the completion of the Mock Objects testing, without the need to set up service registry.
WebWork 2 using OGNL this powerful expression language, can access the value stack. OGNL collection and index properties of the support is very strong.
WebWork built on top of XWork, using ServletDispatcher as the core controller of the framework to deal with HTTP responses and requests.
From the processing point of view, WebWork and Struts 1 is very similar to the composition of their core by the controller, which controller consists of two parts:
- Core controller ServletDispatcher, the controller framework provides.
- Business logic controller Action, the controller provided by the programmer.
Relative Struts 1 of the Action tightly coupled with the Servlet API is the weakness, WebWork in Action is completely separated with the Servlet API, and therefore easier to test the Action.
WebWork in Action can be separated with the Servlet API, thanks to its clever design, it uses an interceptor chain, is responsible for forwarding the user request data to the Action, and Action is responsible for processing the results translate into the user's response.
When a user sends a request to the Web application, the request through the ActionContextCleanUp, SiteMesh such as filters, from the core controller WebWork interceptor, if the user requests the business needs of WebWork processing logic controller, the controller will call the Action Mapper, the Mapper user requests will be forwarded to the corresponding business logic controller. It is noteworthy that at this time is not the business logic controller, the controller to achieve the developer, but rather to create WebWork controller agent.
Create the controller proxy, WebWork developers need to be defined by xwork.xml configuration file, the controller agent to the user as a target to achieve the controller to the interceptor in the interceptor chain, as the processing (Advice).
Tip WebWork way to create a controller agent, is a kind of AOP (Aspect Oriented Programming) programming methods, but in this AOP interceptors provided by the system, so without user intervention. If the reader need to obtain more information about AOP programming knowledge, please refer to the AOP-related information, or written by the author of "Spring 2.0 Collection," a book, Chapter 6.
Developers to achieve their own business logic controller, the controller is just WebWork business objectives - which is why the developers themselves to achieve separation of Action with Servlet API reasons. When the developer's own Action processing the HTTP request, the result is just an ordinary string will correspond to a specific view of resources.
After trying to resources designated interceptor chain processed, generate the client response to the output.
The above data flow diagram of the process shown in Figure 1.8.
With the previous Struts 1 framework for comparison, is not difficult to find in many places, WebWork does better. Relative Struts 1 in terms of the various shortcomings, WebWork There are following advantages:
(1) Action without coupling with the Servlet API and easier to test relative to the Struts 1 framework of the Action appeared a large number of Servlet API in terms of, WebWork in Action is more like an ordinary Java object, the controller code is not coupled to any Servlet API. WebWork in Action See the following example:
public class LoginAction implements Action
(
/ / The string constant as the return value of Action
private final static String LOGINFAIL = "loginfail";
/ / The request parameter 2 Action package
private String password;
private String username;
/ / password request parameters corresponding getter method
public String getPassword ()
(
return password;
)
/ / password request parameters corresponding setter method
public void setPassword (String password)
(
this.password = password;
)
/ / username request parameter corresponding getter method
public String getUsername ()
(
return username;
)
/ / username request parameter corresponding setter method
public void setUsername (String username)
(
this.username = username;
)
/ / Execute method of handling user requests
public String execute () throws Exception
(
if ( "yeeku". equalsIgnoreCase (getUsername ())
& & "Password". Equals (getPassword ()))
(
ActionContext ctx = ActionContext.getContext ();
/ / The currently logged on user name saved to the Session
Map session = ctx.getSession ();
session.put ( "username", getUsername ());
return SUCCESS;
)
else
(
return LOGINFAIL;
)
)
)
Action in the above code, we do not see any of the Servlet API, when the system needs to deal with two request parameters: username and password, when, Action through the HttpServletRequest object was not to get the request parameters, but directly call the username to access the Action and the password member property - these two properties by the Action interceptor is responsible for initialization, the user request parameters for assignment.
Even if the Action is required to access HTTP Session object, still did not appear directly in the code HttpSession API, but as a Map object representing the HTTP Session object.
When we WebWork in Action and Struts 1, when comparing the Action is not difficult to find Struts 1 of the Action is indeed too bloated, and indeed less elegant than WebWork in Action.
If you need to test the above Action code, writing test cases will be very easy, because execute method does not contain any Servlet API, not even WebWork's API.
(2) Action does not need to WebWork coupling, code reuse rate of Action in the above code, you can easily find WebWork in Action is actually a POJO, the Action is only achieved WebWork's Action interface, includes a execute method.
Struts 1 of the Action class needs to inherit Struts 1 of the Action class. We know that to achieve an interface and inherit a class is totally different concept: to achieve an interface to the class of pollution is much smaller, this class can also achieve other arbitrary interface, you can also inherit a parent class; but once a parent has inherited class, it means that the class can not inherit the other parent.
In addition, Struts 1 in Action also contains an execute method, but the method requires four parameters, namely the type ActionMapping, ActionForm, HttpServletRequest and HttpServletResponse, one containing the four parameters method, in addition to Struts 1 Framework Under the useful things, I imagine there are any out of the code re-use value. However, WebWork's execute method is completely different, the method does not appear in any Servlet API, nor any WebWork API, this method in any circumstances have reuse value.
Thanks to the design of WebWork smart, WebWork in Action without any Servlet API, WebWork API coupling, and thus have a better code reuse rates.
(3) to support more presentation layer technology, a better adaptability, as seen from Figure 1.8 of, WebWork for a variety of presentation layer technologies: JSP, Velocity and FreeMarker all have very good support to developers more choices, providing a better flexibility.
1.2.3 Struts 2 over the origin of more than five years of development, Struts 1 has become a highly sophisticated framework, whether it is the stability or reliability, have been widely proof. But because it was too "old", and some design flaws become its flawed. Large number of new MVC framework for the face of booming, Struts 1 also started the blood updates.
At present, Struts framework has been divided into two: the first a framework for Struts 1 and WebWork is that the traditional combination of the Struts 2 framework. Struts 2, though in the Struts 1 developed on the basis of the essence, however, is based on WebWork as the core, Struts 2 for the traditional Struts 1 injected into WebWork's design philosophy, the unification of Struts 1 and WebWork 2 framework that allows Struts 1 and WebWork developers are using Struts 2 framework.
Another differentiation out of Struts framework is a Shale, this framework goes far beyond the original design idea Struts 1, Struts 1 is the original little relevance, it uses a new design. Shale is more like a new framework, rather than the Struts upgrade. Shale and Struts in many ways, there is difference, two of the most prominent:
- Struts and JSF integration, while the Shale is built on top of JSF.
- Struts is essentially a huge, complex requests processor; and Shale is a group can be combined in any manner the service, simply put, Shale is a SOA (service-oriented architecture) architecture.
In the following presentation, we will find, Struts 2 is very similar to WebWork framework, rather than the Struts 1 framework, because Struts 2 is based on WebWork as the core, rather than the Struts 1 as the core. Because of this, many of WebWork developers will find that the transition from WebWork to Struts 2 is a very simple matter.
Of course, the traditional Struts 1 developers, Struts 2 also provides a good backward compatibility, Struts 2 can be organically integrated with the Struts 1 to Struts 1 developers to ensure a smooth transition to Struts 2.

1.3 Struts 2 System Description
Struts 2 and Struts 1 system, a system the difference is very large, because the Struts 2 uses the design of the core of WebWork, rather than using the design of the core of Struts 1. Extensive use of Struts 2 interceptors to handle user requests, allowing the user's business logic controller and the Servlet API separation.
1.3.1 Struts 2 framework of the structure of the data flow diagram from the point of view, Struts 2 with WebWork or less, Struts 2 interceptors use the same as the address (Advice), the user's business logic controller as the goal, to create a controller agent.
Control agents are responsible for handling user requests, handling user requests a callback when the operation controller execute method's return value will determine what kind of view of Struts 2 resources will be presented to the user.

Struts 2 framework of the general process flow is as follows:
The browser sends a request, for example, the request / mypage.action, / reports / myreport.pdf so.
Core controller FilterDispatcher decision, upon request, call the appropriate Action.
WebWork interceptors chain of automatic request for application of common features, such as workflow, validation, or file upload function.
Action to execute the callback method, the execute method first to obtain a user request parameters, and then do some kind of database operations, both the data can be saved to the database, you can also retrieve information from the database. In fact, because the Action is just a controller, it will call the business logic components to handle user requests.
Action's execute method of processing results information will be output to the browser, which can be HTML pages, images, can also be a PDF document or other documents. At this point of view of technology to support a great number of support both JSP, also supports Velocity, FreeMarker template technology and so on.
1.3.2 Struts 2 configuration file when the Struts 2 in Action to create a system agent, you need to use the Struts 2 configuration files.
Struts 2 configuration file there are two:
- Action of the struts.xml configuration file.
- Configure Struts 2 global attributes struts.properties file.
struts.xml document defines the Struts 2 series of Action, the definition of Action, specify the implementation of the Action class, and define the processing results of the Action mapping and view the relationship between resources.
The following is an example of struts.xml configuration file:
<struts>
<! - Struts 2 in Action must be configured in the package-ri - "
<package name="default" extends="struts-default">
"! - Define a Logon of Action, the implementation class for the lee.Logon ->
<action name="Logon">
"! - Action back input when configured into / pages / Logon.jsp page -"
<result name="input"> / pages / Logon.jsp </ result>
"! - Configure Action redirected to the Welcome Back to cancel when the Action ->
<result name="cancel" type="redirect-action"> Welcome </ result>
"! - Configure Action returns success when redirected to the MainMenu of the Action ->
<result type="redirect-action"> MainMenu </ result>
"! - Configure Action returns expired when the ChangePassword of Action into the chain of -"
<result name="expired" type="chain"> ChangePassword </ result>
</ action>
"! - Defined Logoff of Action, the implementation class for the lee.Logoff ->
<action name="Logoff">
"! - Configure Action returns success when redirected to the MainMenu of the Action ->
<result type="redirect-action"> Welcome </ result>
</ action>
</ package>
</ struts>
In the above struts.xml document defines two Action. The definition of Action, not only defines the Action implementation class, and the handling of the definition of Action results, specify more than one result, result element specifies the execute method returns the value and the mapping between the view of resources. For the following configuration snippet:
<result name="cancel" type="redirect-action"> Welcome </ result>
He said when the execute method returns a string cancel, jump to the Welcome to Action. The definition of result element, you can specify two attributes: type and name. Where name specifies the execute method returns a string, while the type of the resource type specified shift, where the resources can be turned to JSP, it can be FreeMarker, and even another Action - This is the Struts 2 can support a variety of views technical reasons.
In addition, Struts 2 there is a Struts 2 Configuration Properties file global attributes: struts.properties. Examples of the paper is as follows:
# Specify the Struts 2 in development status
struts.devMode = false
/ / Specify when the Struts 2 configuration file after the change, Web frameworks whether to re-load the Struts 2 configuration file
struts.configuration.xml.reload = true
As seen above, struts.properties document in the form of series of key, value pairs, which specifies the global properties of Struts 2 applications.
1.3.3 Strut 2 tag library
Struts 2 tag library is also an important component of Struts 2's, Struts 2 tag library provides a very rich set of features, these labels libraries not only provide a presentation layer for data processing, but also provides the basic process control functions, but also offers an international , Ajax support and other functions.
By using Struts 2 tags, developers can minimize the page code writing.
See the following JSP page defines a form fragment:
"! - Definition of an Action ->
<form method="post" action="basicvalid.action">
"! - The following form defines three fields -"
Name: <input type="text" name="name"/> <br>
Age: <input type="text" name="age"/> <br>
Favorite color: <input type="text" name="favorite"/> <br>
"! - The definition of an output button -"
<input type="submit" value=" Submit "/>
</ form>
The above page using HTML tags to define the form of traditional elements, we have yet to verify the information output of the function, but if changed to the following definition of the use of Struts 2 tag method:
"! - Use Struts 2 tag defines a form -"
<s:form method="post" action="basicvalid.action">
"! - Struts 2 tags use the following definition of three form fields -"
<s:textfield label=" First name " name="name"/>
<s:textfield label=" Age " name="age"/>
<s:textfield label=" Colour " name="answer"/>
"! - The definition of a submit button -"
<s:submit/>
</ s: form>
, The page code is more concise, but also a simpler error output. Figure 1.10 is the implementation of the above using the Struts 2 tag output after the data check.

Tip Struts 2 tag library function is very complex, the tag library can almost completely replace the JSTL tag library. And the Struts 2 tags support expression language, this expression language support for a strong and flexible expression language: OGNL (Object Graph Notation Language), so very powerful.
1.3.4 Struts 2 controller component
Struts 2 controller component is the core of Struts 2 framework, in fact, all the MVC frameworks are based on controller components as the core. As mentioned earlier, Struts 2's controller consists of two parts: FilterDispatcher and business controller Action.
In fact, Struts 2 applications, the business controller role is not a user-defined Action, but a system-generated Action agency, but the Action Agent to a user-defined Action goal.
Struts 2 in Action The following is sample code:
public class LoginAction
(
/ / Package, the user request parameters of the username attribute
private String username;
/ / Package, the user request parameters of the password attribute
private String password;
/ / username attribute getter method
public String getUsername ()
(
return username;
)
/ / username attribute setter methods
public void setUsername (String username)
(
this.username = username;
)
/ / password attribute getter method
public String getPassword ()
(
return password;
)
/ / password attribute setter methods
public void setPassword (String password)
(
this.password = password;
)
/ / Execute method of handling user requests
public String execute () throws Exception
(
/ / If the user named scott, password tiger, then the login is successful
if (getUsername (). equals ( "scott")
& & GetPassword (). Equals ( "tiger"))
(
return "success";
)
else
(
return "error";
)
)
)
Action by looking at the above code, found that the Action than the WebWork in Action more thoroughly, the Action without the need to achieve any of the parent interface, without any Struts 2 inherits the base class, the Action class is entirely a POJO (ordinary, traditional Java objects), and therefore has a good reusability.
To sum up, the Action class has the following advantages:
- Action class is entirely a POJO, and therefore has a good code reusability.
- Action category without the need coupled with the Servlet API, so unit testing is very simple.
- Action class execute method of treatment only to return a string as a result, the processing results can be mapped to any view, or even another Action.

1.4 Struts 2 and Struts 1 contrast through the above brief introduction, not difficult to find, Struts 2 is indeed in the Struts 1 made a huge improvement, is indeed a very practical value of the MVC framework. The following are Struts 1 and Struts 2 in all respects a brief comparison.
- In the Action implementation class in contrast: Struts 1 require an abstract Action class inherit base class; Struts 1 in a specific issue is to use an abstract class rather than the programming interface. Struts 2 Action class can implement an Action interface and other interfaces can also be achieved to enable optional and custom services possible. Struts 2 provides a ActionSupport to achieve common base class interface. Even if the Action interface is not to be achieved, and only a POJO class that contains execute method can be used as Struts 2 in Action.
- Comparison of thread models: Struts 1 Action is a single-mode cases and must be thread-safe, because only one instance of Action to handle all requests. Single cases of policy limits the Struts 1 Action can do, and to exercise particular caution in the development. Action resources must be thread-safe or synchronized; Struts 2 Action object for each instance of a request to generate a, there is no thread-safety problems.
- Servlet dependence of the contrast: Struts 1 Action depends on the Servlet API, because the Struts 1 Action's execute method with HttpServletRequest and HttpServletResponse methods. Struts 2 Action is no longer dependent on the Servlet API, to allow Action from the Web container to run, thereby reducing the difficulty of the test Action. Of course, if the Action requires direct access to HttpServletRequest and HttpServletResponse parameters, Struts 2 Action still be able to access them. However, most of the time, Action have no direct access to HttpServetRequest and HttpServletResponse, and thus to give developers more flexibility and choice.
- Can be measured in terms of comparison: Testing Struts 1 Action's execute method of one of the main problem is that depends on the Servlet API, which makes the test Action depends on the Web container. In order to test Struts 1 from the Web container of Action, to be the help of third-party extensions: Struts TestCase, this expansion includes the next series of Mock objects (simulated HttpServetRequest and HttpServletResponse objects), which can be from the Web container testing Struts 1 of the Action class. Struts 2 Action can be initialized, set properties, call methods to test.
- Package request parameter comparison: Struts 1 using the ActionForm object encapsulation parameters of the user's request, all of the ActionForm must inherit a base class: ActionForm. JavaBean not be used as an ordinary ActionForm, therefore, developers must create a large number of ActionForm class encapsulates user request parameters. Although the Struts 1 provides a dynamic ActionForm to simplify the development of ActionForm, but still need to define in the configuration file ActionForm; Struts 2 direct use of Action property to encapsulate user requests properties, avoiding the need to develop a large number of developing ActionForm class, cumbersome, in fact, These properties can also be sub-attributes contain Rich object type. If developers still miss Struts 1 ActionForm pattern, Struts 2 provides a ModelDriven model, allowing developers to use a single Model object to encapsulate a user request parameters, but the Model object without any Struts 2 inherit the base class is a POJO, and thus to reduce pollution in the code.
- Comparison of the expression language: Struts 1 integrates the JSTL, so you can use the JSTL expression language. This expression language with basic object graph traversal, but the collection and indexed property support is not strong on the function; Struts 2 can use JSTL, but it incorporates a more powerful and flexible expression language: OGNL (Object Graph Notation Language), therefore, Struts 2 under the more powerful expression language.
- Bind the value to the view of the comparison: Struts 1 using the standard JSP mechanism to bind objects to the view page; Struts 2 using the "ValueStack" technology that enables tag library to access the value without the need to bind together objects and view page .
- Comparison of type conversion: Struts 1 ActionForm properties are usually the type String. Struts 1 using the Commons-Beanutils for type conversion, each class a converter, the converter is not configured; Struts 2 to use OGNL for type conversion, support for basic data types and common objects conversion.
- Data validation comparison: Struts 1 supports the ActionForm to manually override the validate method of verification, or by integrating Commons alidator framework to complete the data validation. Struts 2 supports validation by overriding the validate method, and also supports integrated XWork validation framework to verify.
- Action comparison of executive control: Struts 1 module supporting each one corresponds to a request processing (that is, the concept of life-cycle), but all the Action module must share the same life cycle. Struts 2 interceptor stack support (Interceptor Stacks) for each Action to create a different life cycle. Developers can create a corresponding stack, which used in conjunction with different Action.

1.5 WebWork and Struts 2 compared to some degree, Struts 2 is a WebWork upgrade, rather than Struts 1 upgrade, even in the Apache's Struts 2 official documents that are mentioned: WebWork to Struts 2 is a smooth transition. In fact, Struts 2.0 is just WebWork 2.3, migrating from WebWork 2.2 to Struts 2.0 is not than from WebWork 2.1 Dao 2.2 even more complicated.
In many ways, Struts 2 is just change the name under WebWork, so if the developer has the WebWork development experience, will be able to more rapidly develop the area into the Struts 2.
The following are named Struts 2 with WebWork exist on change (see Table 1.1):
Table 1.1 Struts 2 and WebWork members of the name of the corresponding
Struts 2 members of the WebWork members of the
com.opensymphony.xwork2 .* com.opensymphony.xwork .*
org.apache.Struts2 .* com.opensymphony.webwork .*
struts.xml xwork.xml
struts.properties webwork.properties
Dispatcher DispatcherUtil
org.apache.Struts2.config.Settings com.opensymphony.webwork.config.Configuration
In addition, Struts 2 is also removed the small amount of WebWork features:
- AroundInterceptor: Struts 2 is no longer supported WebWork in AroundInterceptor. If an application is required to use AroundInterceptor, you should manually import their own WebWork in AroundInterceptor class.
- Rich text editor Tag: Struts 2 is no longer supported WebWork rich text editor, if the application needs to use the rich text editor, you should use the Dojo rich text editor.
- IoC container support: Struts 2 no longer supports the built-in IoC container, instead, full support for Spring's IoC container to Spring's IoC container as the default Object Factory.

相关文章
  • struts1, WebWork as well as profiles and compare struts2 2010-03-29

    Struts 1 Introduction and problems in perspective from the past years, Struts 1 is a MVC framework for all indisputable winner, regardless of market share, is still owned by the development of people, Struts 1 have incomparable to other MVC framework

  • Struts2 comparison with the depth of Struts1.x 2010-03-29

    Struts as the MVC 2 of the Web framework, since its introduction been sought after by developers, are widely used. As the most successful Web framework, Struts naturally has many advantages: MVC 2 model for the use of a sign of full-featured database

  • On struts1 and struts2 2010-04-04

    I think we are definitely not for the struts framework of the strange, recently studied the struts framework, where I would like to talk about their understanding of the framework. First, I want to address is struts1 framework, which is an applicatio

  • struts1和struts2详细流程与区别 2013-09-26

    1.struts1和struts2 是2个完全不同的框架,其实struts2核心就是 webwork框架 struts1以ActionServlet(org.apache.struts.action.ActionServlet)作为核心控制器,由ActionServlet负责拦截用户的所有请求.Struts 1框架有3个重要组成部分:Action.ActionForm和ActionForward对象.ActionForm必须实现ActionForm的基类,设计上并不是真正的POJO. strut

  • struts1.x comparison with struts2 2010-08-24

    1. Action class struts1.x programming for the abstract class struts2-oriented programming interface 2. Threading model struts1.x is a single case of model, an example of processing all requests, so resources must be thread-safe action. strut2 instant

  • Struts2 Tutorial 1: The first program a Struts2 2010-03-29

    http://www.linux521.com/2009/java/200904/1681.html Struts2 Tutorial 1: The first program consists of a Linux system Struts2 English (Linux521.com) editor to compile, in addition to original articles, Linux521 indicated, its belongs to original author

  • [Struts development of prudent use of global variables] 2010-07-15

    Development of the project some time ago, because the relationship between the partners, recently revamped and re-examine the original code written by a number of reconstruction processing. The result is a treatment program performance on behalf of t

  • Struts2 + Spring2 + Hibernate3 web application example (a) 2010-07-27

    Struts as a MVC 2 of the Web framework, since its introduction been sought after by developers, are widely used. As the most successful Web framework, Struts has many natural advantages: MVC 2 model for the use of fully functional Logo Library (Tag L

  • [Transfer] Struts2 and analysis of the working mechanism of -1 2011-01-14

    I. Overview This chapter describes the working principle of Struts2. Readers who have studied or have been Struts1.x Struts1.x development experience, then do not assume that this chapter can be skipped. In fact Struts1.x with Struts2 no blood relati

  • 从webwork2.2应用到struts2的移植看webwork2.x和struts2的区别 2012-03-09

    http://kimsoftware.javaeye.com/admin/show/39354(我javaeye的blog) 以下文字来自struts2官方网站. 一.变化 struts2代码始于webwork2.2.3,少许的比较大的改动可能会影响你的webwork2.2应用的移植 1.一些被Deprecated掉的方法和类已经被移除,这包括XWork Inversion of Control (IoC) 框架. 2.使用xhtml 主题的一些工具库被DOJO的工具组件替代. 3.使用FCK

  • SSH框架面试题(自己+别人的试题) 2013-04-08

    Java工程师(程序员)面题 Struts,Spring,Hibernate三大框架 1.Hibernate工作原理及为什么要用? 原理: 1.读取并解析配置文件 2.读取并解析映射信息,创建SessionFactory 3.打开Session 4.创建事务Transation 5.持久化操作 6.提交事务 7.关闭Session 8.关闭SesstionFactory 为什么要用: 1. 对JDBC访问数据库的代码做了封装,大大简化了数据访问层繁琐的重复性代码. 2. Hibernate是一个

  • Struts2 framework security flaws 2009-12-09

    Abstract This article describes the development of popular java framework for struts2, and webwork some of the security flaws, and illustrates the framework itself as well as developers use the framework, arising from security problems, and the autho

  • struts2 iterator tag related to the use of 2010-07-07

    English Title: (Turn) of label of the Iterator in Struts2 relevant use In explaining the s: iterator tag used before to understand the next struts2 in Value Stack. Here to the webwork in the description on the Value Stack, as struts2 is based on the

  • When the report loads struts2 Unable to load configuration. - Bean - jar: file: / D: / Tomcat6.0/webap 2010-07-16

    The start was to use struts1 written procedures, when run directly into the IDE directly generated struts1 of the package without any problems, Today, suddenly found, struts2 have come such a long time, and also research struts1 in out, to write a si

  • Struts2 learning experience 2010-09-22

    struts2 learning experience, slightly some records, as follows: 1. First of all, struts2 is WebWork2 evolved on the basis, but also belong to MVC framework. struts2 and struts1 some of the differences, you can try to figure out themselves, I read som

  • Struts2 (configuration Speaking) 2010-11-10

    Why should struts.xml file struts.xml file is the core of the Struts2 framework. Struts2 struts.xml document defines a series of Action, the definition of Action, specify the implementation of the Action class, and define and view the results of the

  • Use JSF development: the view (a) 2010-11-11

    Preface MVC Java Web framework is almost the structure of the Master, but the chaos have ingenious framework to achieve are different. Struts, Webwork, Spring MVC Based on C / S model design structure, not hidden on the request / response communicati

  • Pen questions part of the framework with new technology 2010-12-05

    Popular frameworks and new technologies Talk about your understanding of Struts. A: 1. Struts MVC pattern is designed by Web layer framework, in fact, it is a big servlet, the Servlet called ActionServlet, or a subclass of ActionServlet. We will meet

  • Summary 2010 J2EE interview questions 2010-12-13

    State! If identical, very happy! Popular frameworks and new technologies 1 , talk about your understanding of Struts. A: 1. Struts MVC pattern is designed by Web layer framework, in fact, it is a big servlet, the Servlet called ActionServlet, or a su

  • servlet, filter, listener, interceptor and their connection 2011-07-12

    Turn: http://queenlog.com/forum.php?mod=viewthread&tid=3271 For a class url, or url for all the various business processes to match the url and the like, find, perform the appropriate action, comparison with the action, action can only be the url for