首页 > 代码库 > Struts2重学习之作用域的获取

Struts2重学习之作用域的获取

第一种:获取requestMap,sessionMap,applicationMap, HttpServletRequest,HttpServletResponse对象的获取,在Struts2中

 1 public String getMap(){ 2         //获取被处理过的request,session,application三大常用作用域的map形式,可以往里边存放数据,在jsp中就可以用el,ognl表达式取值 3         //ac容器在struts2中任何地方都可以获取,可以当做一个作用域来传递值 4         ActionContext ac=ActionContext.getContext(); 5         //requestMap 6         Map<String, Object> requestMap=(Map<String, Object>) ac.get("request"); 7         //sessionMap 8         Map<String, Object> sessionMap=ac.getSession(); 9         //applicationMap10         Map<String, Object> applicationMap=ac.getApplication();11         12         13         //获取真正的request,session,application,response对象14         15         //httpServletRequest 常用于一次请求传递数据16         HttpServletRequest request=ServletActionContext.getRequest();17         //httpServletResponse,常用于ajax请求响应18         HttpServletResponse response=ServletActionContext.getResponse();19         //ac容器20         ActionContext ac1=ServletActionContext.getContext();21         return null;22     }
View Code