Use of the #, %, and $ symbols in struts 2

Source: Internet
Author: User

#, %, 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>

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.