ActionContext act = ActionContext.getContext();
//伪访问Servlet API,使用Map来模拟一个HttpSession,设置session的值
Map<String,Object> session = act.getSession();
session.put("username", info.getUsername());
//真访问Servlet API,借助于ServletActionContext
HttpServletResponse response = ServletActionContext.getResponse();
Cookie cookie = new Cookie("password", info.getPassword());
cookie.setMaxAge(30000);
//System.out.println(cookie.getName());
response.addCookie(cookie);
struts2中,action访问servlet api的两种方式
最新推荐文章于 2020-04-04 21:34:23 发布