日期:2014-05-20  浏览次数:20843 次

session的问题
SSH2 搭的网站。 在某个action里面 通过ServletActionContext.getRequest().getSession().setAttribute放入几个属性的值。

在接下去的很多action里面通过ServletActionContext.getRequest().getSession().getAttribute都可以提取到。 但是到了jsp页面里面通过同样的代码,却出现NullPointerException ,这是为什么会这样。不是同样的session吗? 怎么到了jsp页面,session里面没有我要的属性。 难道是spring的sessionfactory的缘故?

------解决方案--------------------
直接session,不要用ServletActionContext.getRequest()
------解决方案--------------------
和sessionfactory没有关系

页面上使用:

<s:property value="#session.你的session Key" />
------解决方案--------------------
request.getSession().getAttribute()试一下
------解决方案--------------------
如果你有用struts2标签的话,<s:property value="#session.你的session Key" />

如果说,你想直接用jsp的表达式,那么
<%=session.getAttribute("xm").toString()%>
这种方法也可以


------解决方案--------------------
直接表达式输出 <%=session.getAttribute("name").toString()%>