开发者

Problem with HttpSession in Struts2

I am doing a multi user login application where I use session to store the user object.

HttpSession session = request.getSession(true);
  session.setAttribute("user",user);

In every page I am checking using JSTL whether the user object is present in the session.

<c:choose>
   <c:when test="${not empty sessionScope.user}"> 
    //jsp code
    </c:when>
 开发者_如何学C  <c:otherwise> 
    <logic:redirect forward="welcome"/>
  </c:otherwise>
</c:choose>

My problem is that if the user clicks on a href link in the application the user changes to Previous user in the session. i.e. the it is loading the user from cache. If I refresh the page it will load the correct user.

How could I fix it?


If you are using Struts2 it might make more sense to have that check in an Interceptor instead of repeating the code in every JSP.

http://struts.apache.org/2.0.11/docs/interceptors.html


Nate is right, this is best handled in an Interceptor. This answer may be of use to you.

Edit

It sounds like this might be a page caching issue, then. Try setting a breakpoint in your Java code so that you can inspect what the user object in the session is. Assuming that the user object is always correct and it is just the page showing incorrect information, then try setting no-cache headers as detailed here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜