ValueStack值栈主要包含另个部分:
1.map栈(非根元素) context:主要存储域对象。
2.list栈(根元素) root:主要存储
(1)通过值栈的push()方法存放的对象
(2)Map对象(通过值栈的set()方法存放的数据)
(3)Action对象
(4)其他代理对象.
测试类OgnlDemo2
<span style="font-size:14px;"><span style="font-family:Courier New;">package cn.itcast.ognl; import java.util.Map; import cn.itcast.domain.Admin; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.util.ValueStack; import com.sun.accessibility.internal.resources.accessibility; public class OgnlDemo2 extends ActionSupport{ public Admin admin=new Admin("liweikang","123"); public Admin getAdmin() { return admin; } public void setAdmin(Admin admin) { this.admin = admin; } public String execute() throws Exception { ActionContext ac = ActionContext.getContext(); ac.getContextMap().put("request_data", "request_data"); ac.getSession().put("session_data", "session_data"); ac.getApplication().put("application_data", "application_data"); ValueStack stack = ac.getValueStack(); //放到栈顶 stack.push(admin); stack.set("admin1", new Admin("程崇树", "123") ); System.out.println(stack);<strong><span style="color:#cc33cc;">//我们在这行打了一个断点进行调试</span></strong> return SUCCESS; } }</span> </span>
struts.xml配置文件:
<span style="font-family:Courier New;font-size:14px;"><package name="ognl" extends="struts-default"> <action name="ognl1" class="cn.itcast.ognl.OgnlDemo2" method="execute"> <result name="success">/ognl.jsp</result> </action> </package></span>
浏览器访问OgnlDemo2进行断点调试:
可以发现值栈的两个对象分别为map栈和list栈
点开context 找到values:
打开values观察:
找到list栈即root
在ognl1.jsp中取出数据:
<span style="font-family:Courier New;"><body> <s:property value="#request.request_data"/> <s:property value="#session.sesson_data"/> <s:property value="#application.application_data"/> <s:property value="admin.username"/> </body></span>
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-12-23 21:23:40