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="${expr}"/>
<another:tag value="#{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="some${expr}${expr}text${expr}"/>
<another:tag value="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 有两种情况

时间: 2024-08-25 21:00:14

el 表达式 和 ognl表达式的相关文章

struts.xml中可以使用el表达式和ognl表达式

转自:http://blog.csdn.net/hzc543806053/article/details/7538723 文件上传链接: 1)Servlet 文件上传 ----  点击打开链接 2)Struts2 文件上传 ---- 点击打开链接 文件下载是一个很常见的功能,用struts2实现文件下载的步骤: 一)定义一个Action类,FileDownload.java [java] view plaincopy package com.struts2.filedownload; impor

el表达式跟ognl表达式的区别(转)

EL表达式: >>单纯在jsp页面中出现,是在四个作用域中取值,page,request,session,application.>>如果在struts环境中,它除了有在上面的四个作用域的取值功能外,还能从值栈(valuestack)中取值.>>特点1:${name},name在值栈中的查找顺序是:先从对象栈中取,取到终止,否则,向map中取.>>特点2:在对象栈的查找顺序是,先从model中找是否有name这个属性,找到终止,否则,找action中是否有n

el表达式跟ognl表达式的区别

:  EL表达式 单纯在jsp页面中出现,是在四个作用域中取值,page,request,session,application. 如果在struts环境中,它除了有在上面的四个作用域的取值功能外,还能从值栈(valuestack)中取值 特点: ${name},name在值栈中的查找顺序是:先从对象栈中取,取到终止,否则,向map中取. 在对象栈的查找顺序是,先从model中找是否有name这个属性,找到终止,否则,找action中是否有name这个全局变量 :${#name},里面的是不带#

EL表达式和OGNL表达式 区别小结

1:  EL表达式 单纯在jsp页面中出现,是在四个作用域中取值,page,request,session,application. 如果在struts环境中,它除了有在上面的四个作用域的取值功能外,还能从值栈(valuestack)中取值 特点: ${name},name在值栈中的查找顺序是:先从对象栈中取,取到终止,否则,向map中取. 在对象栈的查找顺序是,先从model中找是否有name这个属性,找到终止,否则,找action中是否有name这个全局变量 :${#name},里面的是不带

struts标签、OGNL表达式、JSTL标签、EL表达式

Struts标签.Ognl表达式.el表达式.jstl标签库这四者之间的关系和各自作用 我之前虽然会用,但是一直分不清彼此之间有什么区别,所以查找资料,将它们进行整合区分,加深了解, 一 介绍 1.Struts2的作用    Struts2标签库提供了主题.模板支持,极大地简化了视图页面的编写,而且,struts2的主题.模板都提供了很好的扩展性.实现了更好的代码复用.Struts2允许在页面中使用自定义组件,这完全能满足项目中页面显示复杂,多变的需求. Struts2的标签库有一个巨大的改进之

Struts标签、Ognl表达式、el表达式、jstl标签库这四者之间的关系和各自作用

<转载> 我之前虽然会用,但是一直分不清彼此之间有什么区别,所以查找资料,将它们进行整合区分,加深了解, 一 介绍 1.Struts2的作用   Struts2标签库提供了主题.模板支持,极大地简化了视图页面的编写,而且,struts2的主题.模板都提供了很好的扩展性.实现了更好的代码复用.Struts2允许在页面中使用自定义组件,这完全能满足项目中页面显示复杂,多变的需求.Struts2的标签库有一个巨大的改进之处,struts2标签库的标签不依赖于任何表现层技术,也就是说strtus2提供

OGNL表达式与EL表达式

一.OGNL表达式 a)什么是OGNL? OGNL是Object-Graph Navigation Language的缩写,它是一种功能强大的表达式语言, 通过它简单一致的表达式语法.主要功能: Ø  可以存取对象的任意属性: Ø  调用对象的方法: Ø  遍历整个对象的结构图: Ø  实现字段类型转化等功能. 它使用相同的表达式去存取对象的属性.这样可以更好的取得数据. b)OGNL与Struts2 OGNL是独立的开源组件 Struts2对其进行了改造和封装,OGNL内部自己会维护一个OGN

EL和OGNL表达式的区分

OGNL是通常要结合Struts 2的标志一起使用,如<s:property value="#xx" /> struts页面中不能单独使用,el可以单独使用 ${sessionScope.username} 页面取值区别: 名称 servlet ognl                                                                           el parameters request.getParameter(&q

EL,OGNL表达式 $ % #

1.OGNL表达式依赖于struts2标签,必须结合struts2标签使用, %”符号的用途是在标志的属性为字符串类型时,计算OGNL表达式的值. <s:a href="getThemeMsg.action?tea_id= %{#session.loginUser.teacher.tea_id}" cssClass="icoZwsc">作文上传</s:a> 访问session 包含loginUser的属性 <s:property val