标签:java cti get use user 访问 request ext 出栈
1.取出request,session,applicaiton中的值
a.往里面加入request,session,application中加入值
public String testServlet(){
ServletActionContext.getRequest().setAttribute("request_username", "username");
ActionContext.getContext().getSession().put("session_username", "username");
ServletActionContext.getServletContext().setAttribute("application_username","username");
return "servlet";
}
取值:
输出request,session,application域中的值,由于访问的是map,所以要加个#号<br> request的值:<s:property value="#request.request_username" /><br> session的值:<s:property value="#session.session_username" /><br> application的值:<s:property value="#application.application_username" /><br>
2.用valuestack中的对象栈的set方法存放的数据,把对象封装成一个hashmap,放入栈顶
a.放值
public String testValueStack_Set(){
ValueStack valueStack = ActionContext.getContext().getValueStack();
valueStack.set("msg", "message");
return "value_stack_set";
}
b.取值
输出valuestack的set方法存放的数据,实际输出的是栈顶的数据<br> <s:property value="msg"/><br>
3. 在person,student和ognlAction中同时有commit,测试页面会输出栈中第一个commit,也就是OgnlAction中的commit
a.放值,用add方法放
public String testValueStack_Deep(){
Person person=new Person();
person.setAge(new Integer(1));
person.setName("person");
person.setCommit("person");
Student student=new Student();
student.setAge(2);
student.setName("student");
student.setCommit("student");
ValueStack valueStack = ActionContext.getContext().getValueStack();
CompoundRoot root = valueStack.getRoot();
root.add(person);
root.add(student);
return "valueStack_deep";
}
取值:
在person,student和ognlAction中同时有commit,测试页面会输出栈中第一个commit,也就是OgnlAction中的commit <s:property value="commit"/>
Strut2 ognl取出存放在request,session,application和对象栈的中的值
标签:java cti get use user 访问 request ext 出栈
原文地址:http://www.cnblogs.com/callyblog/p/7533065.html