#, %, And $ symbols often appear in ognl expressions, and these three symbols are not easy to grasp and understand. Here, I will briefly introduce their respective uses.
1. # There are generally three types of symbols.
1) access non-root object attributes. For example, the # session. MSG expression in the example. Because the struts 2 mid-value stack is regarded as the root object, the # prefix is required when accessing other non-root objects. In fact, the expression # is equivalent to actioncontext. getcontext (); # session. MSG is equivalent to actioncontext. getcontext (). getsession (). getattribute ("MSG ").
2) used for filtering and projecting sets, such as persons .{? # This. age> 20 }.
3) used to construct a map. For example, # {'foo1': 'bar1', 'foo2': 'bar2'} in the example ′}.
2.% symbol
% Is used to calculate the value of the ognl expression when the flag property is of the string type. The following code is used:
Construct a map
<S: Set Name = "foobar" value = "# {'foo1': 'bar1', 'foo2': 'bar2'}"/>
<P> the value of key "foo1" is <s: property value = "# foobar ['foo1']"/> </P>
<P> do not use %: <s: URL value = "# foobar ['foo1']"/> </P>
<P> Use %: <s: URL value = "% {# foobar ['foo1']}"/> </P>
3. $ symbol
The $ symbol is mainly used in two aspects.
REFERENCE The ognl expression in the international resource file. For example, in the international resource file code: Reg. agerange = International Resource Information: The age must be between $ {min} and $ {max.
REFERENCE The ognl expression in the configuration file of the struts 2 framework, as shown in the following code snippet:
<Validators>
<Field name = "intb">
<Field-validator type = "int">
<Param name = "min"> 10 </param>
<Param name = "Max"> 100 </param>
<Message> baction-test check: The number must be between $ {min} and $ {max! </Message>
</Field-validator>
</Field>
</Validators>