[color=green][size=medium]另:struts的Map session 不是同一个Session [/size][/color]
struts里的Session实际上是一个Map集合,
private Map<String, Object> session;
与servlet的HttpSession不同,struts2的session并不能在不同action里引用,放入session的值,只能在本action里取,以及传递到页面上。
struts2里获得HttpSession、httpServletRequest、HttpServletResponse的方法:
public class AdminAction extends ActionSupport implements SessionAware,ServletResponseAware{
HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);
HttpSession session = request.getSession();
//杀死session
session.invalidate();
}
struts里的Session实际上是一个Map集合,
private Map<String, Object> session;
与servlet的HttpSession不同,struts2的session并不能在不同action里引用,放入session的值,只能在本action里取,以及传递到页面上。
struts2里获得HttpSession、httpServletRequest、HttpServletResponse的方法:
public class AdminAction extends ActionSupport implements SessionAware,ServletResponseAware{
HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);
HttpSession session = request.getSession();
//杀死session
session.invalidate();
}