1.方法一:直接获取 Map类型
Map request = (Map)ActionContext.getContext().get("request");
Map session = (Map)ActionContext.getContext().getSession();
Map application =(Map) ActionContext.getContext().getApplication();
设置值后 :request.put("name",name);
可以在Jsp页面获取
2。方法二:实现接口 依赖struts2注入 Map 类型
public class LoginAction extends ActionSupport implements RequestAware,SessionAware,ApplicationAware{
private Map
private Map
private Map
@override
public void setRequest(Map
this.request=request;
}
@override
public void setSession(Map
this.session=session;
}
@override
public void setApplication(Map
this.application=application;
}
}
3.方法三:获取httpServlet类型的 (不常用)
private HttpServletRequest request = ServletActionContext.getRequest();
private HttpSession session = request.getSession();
private ServletContext application = session.getServletContext();
使用request :request.setAttribute("name",name);
4.方法四:获取httpServlet类型的 实现ServletRequestAware 接口 (不常用)
public class LoginAction extends ActionSupport implements ServletRequestAware{
private HttpServletRequest request ;
private HttpSession session ;
private ServletContext application ;
public void setServletRequest(HttpServletRequest ruequst){
this.request = request;
this.session = request.getSession();
this.application = session.getServletContext();
}
}
文章转自:http://hi.baidu.com/snbrskt/item/6b2865e7ef61fba1c10d7505