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.