1,使用解耦的方式访问Servlet API
ActionContext ac= ActionContext.getContext();
//获得HttpServletRequest对象对应的Map对象
Map request1=(Map) ac.get("request");
//获得HttpSession对象对应的Map对象
Map session1= ac.getSession();
//获得ServletContext对象对应的Map对象
Map application= ac.getApplication();
session1.put("name",name);
2,使用耦合的方式访问Servlet API
//获得ServletContext对象
ServletContext servletContext= ServletActionContext.getServletContext();
//获得HttpServletResponse对象
HttpServletResponse response=ServletActionContext.getResponse();
//获得HttpServletRequest对象
HttpServletRequest request= ServletActionContext.getRequest();
//获得HttpSession对象
HttpSession session=request.getSession();
|
|