first, understand the OGNL expression:
(1) The abbreviation for object Graphic navigation language(objects graphics navigation language), which is a highly functional expression language that can be used to access arbitrary properties and invoke methods in the object. The purpose is to simplify access to the property values in the Object!
(2) The parsing of the OGNL expression is done around the OGNL context, and the OGNL expression is a map object that contains multiple Java objects, one of which is very special, and this object is called the root object.
A. If a OGNL expression does not specify a target object, the default is to start the lookup from the root object.
B. To access a property in a non-root object, you need to prefix the root object with a # before you access it.
second, understand the value stack (valuestack):
(1) Valuestack is the external interface of the value stack, the actual corresponding class is the Ognlvaluestack,ognlvaluestack object contains a ArrayList set as the stack, the default Action object position value stack top position.
A.void push (Objext o) can be used to push an object data onto the top of the stack.
B.set (String key,objext obj) puts the data into the map object and presses the map object into the top position of the stack.
(2) The OGNL expression, when fetching the data, the rule is to start from the stack top (Action object) to find the first to determine whether there is a map object, based on the value of the key, not the map object, then look for the object's Getkey () method, get its value, if there is no method, then find the key variable ( The requirement must be public decorated) is found, and the second object is searched down.
third, detailed understanding of Actioncontext:
(1) When the STRUTS2 framework resolves the OGNL expression, the OGNL context is Actioncontext, and the root object is the action object.
For example: If you give a OGNL expression: "Class.user ... Name
First of all, the OGNL expression prefix is not prefixed with #, so this one root object, the struts2 frame looks up the GetClass () method in the stack top object of the value stack, gets the class object, and finds the Getuer () method through the class object, and gets the user object , and then the value in the user object looks up the GetName () method to get the final value.
(2) For each request sent by the client, the STRUTS2 frame will automatically create a Actioncontext and value stack object, and the two objects will be destroyed automatically after the request is processed. The Actioncontext object is equivalent to a large container containing application, session, parameters, VALUESATCK, and attr attributes. (where the Valuestack object is the value stack object)
(3) Application, session, parameters, and so on in Actioncontext are not root objects, and in OGNL expressions you need to prefix the expression with the # prefixes before you can access them in an expression.
For example: ① #appliation. UserName equals Actioncontext.getcontext (). Getapplication (). Get ("UserName");
② #session. UserName is equivalent to Actioncontext.getcontext (). GetSession (). Get ("UserName");
③ #parameters. Username et actioncontext.getcontext (). GetParameters (). Get ("UserName");
Four, struts2 frame of the Actioncontext object internal structure graphic detailed: