开发者

Session problem in Struts based application

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:otherwise> 
    <logic:redirect forward="welcome"/>
  </c:otherwise>
</c:choose>

My problem is that if the user clicks on a href link in the applicati开发者_运维百科on 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?


First of all, session is stored on server and has nothing to do with client cache.

Previous user is not loaded from cache (as you say), the page is loaded from cache since links go to the server on a GET. The browser is free to cache the result of a GET if the URL didn't change since the last time it was requested.

To fix this, you need to invalidate the client cache. You can do that by adding HTTP cache header directives or by adding meta tags in the page.

I would suggest to go with HTTP headers since proxies usually don't read the content of the page and you may end up with a cache on a proxy server even if the client does not store the page in the client cache.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜