struct2访问或添加request/session/application

访问或添加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";
 }
//这样取出
 <body> 
   ${applicationScope.app}<br>
   ${sessionScope.ses}<br>
   ${requestScope.req}<br>
 </body>


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;
  }
}

posted @ 2014-01-15 14:39  sandea  阅读(182)  评论(0编辑  收藏  举报