struts2 中OGNL

1、访问OGNL上下文和Action 上下文,#相当于 ActionContext.getContext();

名称 作用 例子
parameters 包含当前HTTP请求参数的Map #parameters.id[0]作用相当于request.getParameter(“id”)

(这个是因为在请求中可能包含多个同一名字的参数,所以这里是数组,所以切记要用数组下标[0]来取元素)
request 包含当前HttpServletRequest的属性(attribute)的Map #request.userName相当于request.getAttribute(“userName”)
session 包含当前HttpSession的属性(attribute)的Map #session.userName相当于session.getAttribute(“userName”)
application 包含当前应用的ServletContext的属性(attribute)的Map #application.userName相当于application.getAttribute(“userName”)
attr 用于按request > session > application顺序访问其属性(attribute) #attr.userName相当于按顺序在以上三个范围(scope)内读取userName属性,直到找到为止

2、用于过滤和投影(projecting)集合,如 books.{?#this.price<100} ;

3、构造 Map,如#{'foo1':'bar1', 'foo2':'bar2'} 。 
‹   “%”符号的用途是在标志的属性为字符串类型时,计算 OGNL 表达式的值。例如在 Ognl.jsp 中加入以下代码: 
< hr /> 
    < h3 > %的用途 </ h3 > 
    < p >< s:url value ="#foobar['foo1']" /></ p > 
    < p >< s:url value ="%{#foobar['foo1']}" /></ p > 
‹   “$”有两个主要的用途 
用于在国际化资源文件中,引用 OGNL 表达式(请参见相应章节);
在 Struts 2 配置文件中,引用 OGNL 表达式,如 
< action name ="AddPhoto" class ="addPhoto" > 
            < interceptor-ref name ="fileUploadStack" />            
            < result type ="redirect" > ListPhotos.action?albumId=${albumId} </ result > 
        </ action >

你可能感兴趣的:(struts2 中OGNL)