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