Value stack (Structs2), structs2

Source: Internet
Author: User

Value stack (Structs2), structs2

1. About Value Stack:

1). During login, $ {userName} reads the userName value. In fact, this attribute is not in the request and other domain objects, but obtained from the value stack.

2). ValueStack:

I. You can obtain value stack objects from ActionContext.

// 1. Obtain the value Stack
ValueStack valueStack = ActionContext. getContext (). getValueStack ();
// 2. Create a Test object and assign values to its attributes
Test object = new Test ();
Object. setUserName ("abc ");
Object. setUserPsw ("123 ");

// 3. Press the Test object to the top of the stack of the value stack!
ValueStack. push (object );


II. Value stack is divided into two logical parts

> Map Stack: it is actually OgnlContext type, a Map, and a reference to ActionContext. Various maps are saved in it:
RequestMap, sessionMap, applicationMap, parametersMap, attr

> Object Stack: it is actually a CompoundRoot type stack defined by ArrayList. It stores various objects related to the current Action instance.
Is a stack of data structures.

2. Struts2 uses the s: property tag and OGNL expression to read the attribute values in the value stack.

1). attribute values in the value Stack:

> For object Stack: attribute values of an object in the object Stack

> Map Stack: a request, session, application attribute value or a request parameter value.

2). Read the attributes of objects in the object Stack:

> To access the attributes of an Object in the Object Stack, you can use one of the following methods:

Object. propertyName; object ['propertyname']; object ["propertyName"]

> Objects in ObjectStack can be referenced by a subscript starting from scratch. The stack top object in ObjectStack can be referenced using [0,
The object below it can be referenced using [1.

[0]. message

> [N] indicates that the search starts from the nth object, instead of searching only the nth object.

> If you start searching from the top object of the stack, You can omit the subscript part: message

> Combined with the s: property Tag: <s: property value = "[0]. message"/> <s: property value = "message"/>

3) by default, the Action object is automatically put to the top of the value stack by Struts2.

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.