Struts Value Stack

Source: Internet
Author: User

First of all, the statement: This article is from the blog Park Boyou Article reprinted, I feel that the good, here attached address: http://www.cnblogs.com/jerryxing/archive/2012/04/23/2467299.html

Through a period of contact with struts2, I will talk about the core value stack of OGNL. Value Stack: Simply put, it is the stack that stores action, when we submit a request to the server-side action, there is a stack. If the action is redirected on the server side, all actions share a stack. When you need to save the data in the action, first, start searching from the top of the stack. If the same attribute name is found (the same as the attribute name of the data to be obtained), the value is retrieved, however, in this case, we may find that the value is not what we want. To solve this problem, we need to use TOP and N syntax to solve it.
When a client jumps, only one stack exists when a request is submitted to the server action. The stack stores the action of the current request, in the past, it was destroyed (my views are the same as request requests ).

As we all know, the Action class of Struts2 can obtain all relevant values through attributes, such as request parameters, Action configuration parameters, and passing attribute values to other actions (through chain results. To obtain these parameter values, the only thing we need to do is declare an attribute with the same name as the parameter in the Action class. In Struts 2, call the Action method of the Action class (the default is the execute method) previously, the corresponding Action attribute will be assigned a value.

To complete this function, Struts 2 depends on the ValueStack object to a large extent. This object runs throughout the lifecycle of the Action (each Action class object instance will have a ValueStack object ). When Struts 2 receives. after an action request, an object instance of the Action class is created, but the Action method is not called, instead, place the corresponding attributes of the Action class to the top-level node of the ValueStack object (the ValueStack object is equivalent to a stack ). Only all attribute values are default values, for example, the value of String type is null, and the value of int type is 0.

After processing the above work, Struts 2 will call the interceptor in the interceptor chain. After calling all the interceptors, it will call the Action method of the Action class. before calling the Action method, the attribute value in the top-level node of the ValueStack object is assigned to the corresponding attribute in the Action class. You should note that this gives us great flexibility. That is to say, when Struts 2 calls the interceptor, the attribute value in the ValueStack object can be changed. When a property value is changed, the corresponding property value of the Action class is changed to the value of this property in the interceptor.

From the above description, it is easy to know that in the Action class of Struts 2, parameters with the same name as the attribute can be obtained through different interceptors. For example, the interceptor for obtaining request parameters is params, the blocker for obtaining the configuration parameters of an Action is staticParams. Read the corresponding values in these interceptors and update the value of the corresponding attribute of the top-level node of the ValueStack object. The ValueStack object is like a conveyor belt, which transfers the attribute value from one Interceptor to another (of course, the attribute value may change during this period) and finally to the Action object, and assign the final value of the ValueStack pair to the corresponding attribute of the Action class.

As we all know, the Action class of Strut 2 can obtain all relevant values through attributes, such as request parameters, Action configuration parameters, and passing attribute values to other actions (through chain results. To obtain these parameter values, the only thing we need to do is declare an attribute with the same name as the parameter in the Action class. In Struts 2, call the Action method of the Action class (the default is the execute method) previously, the corresponding Action attribute will be assigned a value.

To complete this function, Struts 2 depends on the ValueStack object to a large extent. This object runs throughout the lifecycle of the Action (each Action class object instance will have a ValueStack object ). When Struts 2 receives. after an action request, an object instance of the Action class is created, but the Action method is not called, instead, place the corresponding attributes of the Action class to the top-level node of the ValueStack object (the ValueStack object is equivalent to a stack ). Only all attribute values are default values, for example, the value of String type is null, and the value of int type is 0.

After processing the above work, Struts 2 will call the interceptor in the interceptor chain. After calling all the interceptors, it will call the Action method of the Action class. before calling the Action method, the attribute value in the top-level node of the ValueStack object is assigned to the corresponding attribute in the Action class. You should note that this gives us great flexibility. That is to say, when Struts 2 calls the interceptor, the attribute value in the ValueStack object can be changed. When a property value is changed, the corresponding property value of the Action class is changed to the value of this property in the interceptor.

From the above description, it is easy to know that in the Action class of Struts 2, parameters with the same name as the attribute can be obtained through different interceptors. For example, the interceptor for obtaining request parameters is params, the blocker for obtaining the configuration parameters of an Action is staticParams. Read the corresponding values in these interceptors and update the value of the corresponding attribute of the top-level node of the ValueStack object. The ValueStack object is like a conveyor belt, which transfers the attribute value from one Interceptor to another (of course, the attribute value may change during this period) and finally to the Action object, and assign the final value of the ValueStack pair to the corresponding attribute of the Action class.

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.