在struts2中怎么样访问容器的session对象

来源:百度知道 编辑:UC知道 时间:2024/05/31 22:17:44
在struts2中怎么样访问容器的session对象,好像有这么几个类:ActionContext,ServletActionContext,到目前为止我只知道这么多的类,怎样做才能像在servlet中那样使用HttpSession对象,麻烦说的详细一些,

两种办法,直接的和间接的:
直接的就是通过实际的Request得到真实的Session对象:
比如:
HttpSession session=ServletActionContext.getRequest().getSession();

间接的就是通过Struts2封装的MAP来间接实现使用Session,但这个Session不是真实的Session:
比如:
ActionContext ctx = ActionContext.getContext();
Map session = ctx.getSession();

HttpSession session = request.getSession();这样创建个session就可以了,还可以在配置文件里配一下。