码迷,mamicode.com
首页 > 移动开发 > 详细

struct2访问或添加request/session/application

时间:2014-10-29 16:49:59      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:http   io   ar   sp   on   cti   as   res   tt   

访问或添加request/session/application
1 通过ActionContext
//这样放置
public String execute()
{
ActionContext ctx = ActionContext.getContext();
ctx.getApplication().put("app","lll");
ctx.getSession().put("ses","session范围");
ctx.put("req", "request范围");
return "success";
}
//这样取出

${applicationScope.app}

${sessionScope.ses}

${requestScope.req}




2 获取相应对象

2.1 通过ServletActionContext类直接获取:
public String rsa() throws Exception{
HttpServletRequest request = SerletActionContext.getRequest();
request.setAttribute("req","请求范围属性");
request.getSession().setAttribute("res","会话属性");
}

2.2实现指定接口,由struct2框架运行时注入
public class HelloWorldAction implements ServletRequestAware,ServletResponseAware,ServletContextAware
{
private HttpServletRequest request;
public void setServletRequest(HttpServletRequest req){
this.request = res;
}
}

struct2访问或添加request/session/application

标签:http   io   ar   sp   on   cti   as   res   tt   

原文地址:http://www.cnblogs.com/csy8fs/p/4059600.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!