[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();
}
本文探讨了Struts2框架中Session的实现机制,并指出它与servlet的HttpSession的区别。Struts2的Session实质为Map集合,在不同Action间无法直接共享数据。文章还提供了获取HttpSession的方法。
3430

被折叠的 条评论
为什么被折叠?



