OGNL expression Language (1), Ognlcontext object for the struts of the SSH framework

Source: Internet
Author: User
Tags ssh

OGNL expression Language for struts
First, overview:

OGNL-expression
OGNL is an abbreviation for the object Graphic Navigation Language, which is an open source project. The STRUTS2 framework uses OGNL as the default expression language.

OGNL Advantages
1, support the object method call, such as xxx.dosomespecial ();

2, support class static method call and value access, expression format:
@[class full name (including package path)]@[Method name | Value name], for example:
@java. Lang.string@format (' foo%s ', ' Bar ')
or @tutorial. Myconstant@app_name;

3, Support assignment operation and expression concatenation, such as price=100, discount=0.8,
Calculateprice (), this expression returns 80;

4, Access OGNL context (OGNL contexts) and actioncontext;
5. Manipulate the collection object.

Summary: OGNL has a context concept, and the context is a MAP structure that implements the Java.utils.Map interface. Ognlcontext Object

Second, analysis
1. The struts framework supports the OGNL expression language by default. (Struts must reference the package: Ognl.jar)
2. Function: Use the value of the page.

3. Compare El expressions with OGNL expressions:
1) El expression language, used for page values, JSP page value of the standard. (it can be used directly by default), and if the value is NULL, it will not appear on the page as null, but "", eliminating the hassle of handling null. (Wider range of applications).
2) OGNL expression language, the expression language supported by the struts tag by default. Must be used with struts tags and cannot be used directly from the Struts tab.

Three, Ognlcontext object (Understand)
Ognlcontext object is the core of the OGNL expression language.
1, view the source code:

2, hard-coded way to understand the Ognlcontext object:
1) using the OGNL expression language value, take the value of non-root elements, you must use the # number .

2) Use the OGNL expression language to take the value, taking the value of the root element without the # sign.

3) OGNL support for static method calls

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.