1. Introduction to ognl
Key points: 1. New functions compared with El expressions
2. Context concept: actioncontext
2. actioncontext Structure
Note: 1. After struts2 receives a request, it will quickly create acntioncontext, valuestack, and action and store the action in valuestack. Therefore, the ognl expression can be used to access the instance variable of the action.
2. The standard ognl sets a root object (root object ). Assume that the standard ognl expression is used for evaluation (the ognl expression of struts 2 is not used). If the ognl context (ognlcontext map type) has two objects: Foo object, which is named Foo in the ognlcontext; bar object, which is named bar in ognlcontext. At the same time, the foo object is set as the root object ). Evaluate the value using the following ognl expression:
# Foo. Blah // return Foo. getblah ()
# Bar. Blah // return bar. getblah ()
Blah // return Foo. getblah () Because foo is the root object.
To access objects in the ognl context, you must use the # symbol to mark the namespace, for example, # bar. If the attribute to be accessed belongs to the root object, you can omit the namespace and directly access this attribute.
3. Use an ognl expression to obtain the attribute values of each object in the context.
The reason why the attribute of the object in valuestack can be obtained using the El expression!
The ognl expression must be used together with the struts2 property tag.
4. Create list and map set objects using ognl expressions
Determines whether an object is in a collection
Projection Function