首页 > 代码库 > el 表达式 和 ognl表达式
el 表达式 和 ognl表达式
el (expression language)
el 基础操作符
el 能够隐含对象(就是可以直接访问的)
el 的两种使用方式,第二种好像在jsp中没有什么用,主要用于jsf
el能够访问的对象(javaBean , 类集, 枚举 , 隐含对象)
在oracle官方网站上记录下来的一些我认为有用的东西:
1.
${customer}
The web container evaluates the variable that appears in an expression by looking up its value according to the behavior of PageContext.findAttribute(String), where the String argument is the name of the variable. For example, when evaluating the expression ${customer}, the container will look for customer in the page, request, session, and application scopes and will return its value. If customer is not found, a null value is returned.
web容器在处理这段代码是后台使用的是 PageContext.findAttribute(String)方法,该方法的定义如下:
该方法是抽象类PageContext继承抽象类JspContext的。
这个方法的定义和上面红色字体的描述基本相同,就是说会按照page -> request -> session -> application 的这个顺序搜寻customer属性,如果有返回,否者返回null。
2.
Where Value Expressions Can Be Used
Value expressions using the ${} delimiters can be used in
Static text
Any standard or custom tag attribute that can accept an expression
The value of an expression in static text is computed and inserted into the current output. Here is an example of an expression embedded in static text:
<some:tag>
some text ${expr} some text
</some:tag>
If the static text appears in a tag body, note that an expression will not be evaluated if the body is declared to be tagdependent.
Lvalue expressions can be used only in tag attributes that can accept lvalue expressions.
A tag attribute value using either an rvalue or lvalue expression can be set in the following ways:
With a single expression construct:
<some:tag value="http://www.mamicode.com/${expr}"/>
<another:tag value="http://www.mamicode.com/#{expr}"/>
These expressions are evaluated, and the result is converted to the attribute’s expected type.
With one or more expressions separated or surrounded by text:
<some:tag value="http://www.mamicode.com/some${expr}${expr}text${expr}"/>
<another:tag value="http://www.mamicode.com/some#{expr}#{expr}text#{expr}"/>
These kinds of expression, called composite expressions, are evaluated from left to right. Each expression embedded in the composite expression is converted to a String and then concatenated with any intervening text. The resulting String is then converted to the attribute’s expected type.
只看有颜色的字, 第一个说el可以再普通文本和作为标签的值使用,第二个和第三个颜色字分别为在普通文本和作为标签属性的实例。第四个表示el可以和文字任何搭配使用,其中的#我还不知道在jsp中有什么用。
ognl
1. The Object-Graph Navigation Language (OGNL) is a powerful expression language that is used to reference and manipulate data on the ValueStack. OGNL also helps in data transfer and type conversion.
The OGNL is very similar to the JSP Expression Language. OGNL is based on the idea of having a root or default object within the context. The properties of the default or root object can be referenced using the markup notation, which is the pound symbol.
这是摘取http://www.tutorialspoint.com/中关于ognl的定义,大概是说ognl主要是用于操作value stack中的内容和进行数据转换和类型转换,关于value stack该网站是这样描述的:
使用ognl操作value stack 有两种情况
el 表达式 和 ognl表达式