STRUTS2 Framework and implementation principles and workflow

Source: Internet
Author: User

Original link: http://blog.csdn.net/jdfkldjlkjdl/article/details/9946687

STRUTS2 provides a platform to quickly build applications for users.
STRUTS2 is a network engineering framework based on Opensymphony.
STRUTS2 implements the Model View controller (MVC) design pattern.
Action,result and Filterdispatcher are implemented in the STRUTS2 model, view and controller respectively.
The controller's job is to map the user's requests (request) to the appropriate action.
The Struts2 Filterdispatcher is working on the controller.
The model contains data and business logic.
In the STRUTS2 model, the action part is implemented.
The view is the display part of the MVC pattern.

The view of Struts 2 is generally implemented using jsp,velocity Template,freemaker or other presentation layer technology


The controller receives the user request (requests) and determines which Struts2 action is invoked.
The framework creates an action instance Association actioninvocation the newly created instance.
The action of the STRUTS2 call should be intercepted by interceptors defined in the XML file of a series of applications.
The framework calls the Actioninvocations invoke () method to begin executing the action.
When each invoke () method is invoked, Actioninvocation consults its status and executes the next interceptor.
Actioninvocation the interceptor in the control stack by calling the interceptors intercept () method.
The Intercept () method of the Interceptor calls the Actioninvocation Invoke () method in turn until all interceptors are invoked, the last action itself is invoked, and the corresponding result is returned to the user.
Some interceptors work before the action executes, and some interceptors work after the action executes, which is not necessary and should work every time it is invoked. These interceptors are run both before and after the call.
First, all interceptors are executed in the order they are defined in the stack.
When the action is invoked, result is generated.

Again, all interceptors are called in the reverse order of the current stack.


Another 2 important characteristics of the Strut2 are Ongl and valuestack.
Object-graph navigation Language (OGNL) is a powerful expression language used to query and manipulate data in the Valuestack.
OGNL help with data transfer and type conversion.
The OGNL expression language provides a simplified Stytax reference Java object.
OGNL is used to bind the string-based view layer of Java-side data properties.


Summary:


Client submits a (HttpServletRequest) request, which is submitted to a series of filters (mainly 3 layers) (filter), such as (Actioncontextcleanup, Other filters (Sitemesh etc.), filterdispatcher). Note: Here is the order, first Actioncontext CleanUp, and then other filters (Othter Filters, Sitemesh, etc.), and finally to Filterdispatcher. The


Filterdispatcher is the core of the controller, the core of the control layer (Controller) in the Struts 2 implementation of MVC. The


Filterdispatcher asks Actionmapper if an action needs to be invoked to handle this (HttpServlet requests) request. If Actionmapper decides to call a action,filterdispatcher, the processing of the request is given to Actionproxy.


Actionproxy through configuration Manager (Struts.xml) to ask the framework's configuration file to find the action class that needs to be invoked. For example, the user registration example will find the Userreg class. The


Actionproxy Creates a actioninvocation instance, while Actioninvocation invokes the action through proxy mode. However, before the call, Actioninvocation will load all interceptor (interceptors) associated with the action based on the configuration.


Once the action is completed, Actioninvocation is responsible for finding the corresponding return result based on the configuration in Struts.xml.

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.