Struts2 OGNL表达式详解

来源:互联网 发布:sap系统优缺点知乎 编辑:程序博客网 时间:2024/05/19 23:10
Struts2使用标准的Context进行OGNL表达式求值,
OGNL处理的顶级对象是OGNL ValueStack,可以通过如下方式即可:
#取得ValueStack中的bar属性
${bar}

OGNL上下文中有且仅有一个根对象(ValueStack)。Struts2为我们定义了许多命名对象,他们分别是:

"ValueStack","Parameters","Session","Request", "Appliction","Attr"

其中"ValueStack"被设置为上下文的根对象。访问非根对象必须加上"#"号,输出格式如下:

<s:property value="#request.student.age"/>

一般使用<s:debug>标签查看ValueStack和Stack Context的值

<%=request.getSession().getAttribute("user") %><br/>  ValueStack point:<s:property value="point" /><br/>  ValueStack student.name:<s:property value="student.name"/><br/>  Stack Context.request:<s:property value="#request.point"/><br/>Stack Context.session:<s:property value="#session.user"/><br/><s:property value="locale"/><br/><s:property value="[0]"/><br/><s:textfield value="%{#request.point}"/>    <s:debug></s:debug>


原文链接:http://www.cnblogs.com/beliefbetrayal/archive/2012/02/11/2347244.html



原创粉丝点击