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