Struts2 Learning -- ValueStack

Source: Internet
Author: User

The Action class of Strut2 obtains all relevant values through attributes, such as the request parameter attribute values. To obtain these parameter values, the only thing we need to do is declare the attribute with the same name as the parameter in the Action class. Before Struts2 calls the Action method of the Action class, the Action attribute is assigned a value. To complete this function, Struts2 depends on the ValueStack object to a large extent. This object runs throughout the lifecycle of an Action. Each Action class object instance has a ValueStack object. When accessing an action, struts2 pushes the entire action to the top of valuestack. At this time, valuestack is an action object and we usually write a stack. setkey1, value1) or statck. setvalue (key2, value2) is different. The former will press a hashmap in valuestack and implant key1, value1 into the hashmap. At this time, valuestack will have two objects, with hashmap at the top, at the bottom is the action, the latter will directly implant key2 and value2 to the top object, usually action. If action does not have the corresponding set method, the execution of this method is equivalent to a white match, if you execute valuestack at this time. findvalue will be empty.]

When Struts2 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 ValueStack object of the ValueStack object, which 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 the above work is completed, Struts 2 will call the interceptor in the interceptor chain. These interceptors will update the corresponding attribute values of the top-level node of the ValueStack object based on the value of the user request parameter, finally, it is uploaded to the Action object, and the attribute value in the ValueStack object is assigned to the corresponding attribute of the Action class.

After all the interceptors are called, the Action method of the Action class is called. ValueStack is created at the beginning of the request and disappears at the end of the request.

There are "Object stack" and "map stack ".

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/16023A233-0.png "style =" float: none; "title =" 2013-09-02_155239.png "/>

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/16023CB9-1.png "style =" float: none; "title =" 2013-09-02_155303.png "/>




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.