AD

To determine whether a session expired

How to determine whether the session expired.

1, to achieve HttpSessionListener interface, and then sessionDestroyed () method to perform some operations, said the session is about to expire, and because this method is session.invalidate () method is called before the listener. The judge's approach is clearly unsatisfactory.

2, request.getSeesion (boolean) method. This method parameter boolean, the value if it is true, then if the current request of the session is not available, then create a new session, if it exists on the return to the current session. If the argument is false, then the request of the current session does not exist when returns null.
This so-called request for the current session and the session expired the existence of the link, you can "approximate" that the session does not exist is the session expires, then we can easily determine whether the session expired. As follows:
if (request.getSession (false) == null)
System.out.println ( "Session has been invalidated!");
else
System.out.println ( "Session is active!");

I wonder if special circumstances exist.
This special case is the first request has not yet created a session time, then use this method returns is still null.

3, in a special session to save the field to determine whether the session expired

Transfer from: **blog.csdn**/liu251/archive/2009/01/21/3848958.aspx
标签: listener, interface, aspx, existence, special circumstances, method parameter, session time, special session
分类: Java
时间: 2010-03-25

相关文章

  1. Ajax applications on the session expired problem several solutions

    Now web development, ajax application more. On this side of the frame either. Encounter in the application ses ...
  2. Flex (Alternative session expired) to achieve the user for a long time to re-login does not deal with operational requirements

    flex (alternative session expired) operation requires the user to log a long time without treatment Post Categ ...
  3. Session expired, close the parent window, go to the login page

    D: \ GTRS_workspace \ TRS_1_TimeReportingFEWeb \ WebContent \ sessionTimeoutTarget.jsp add for the window.open ...
  4. HBase RegionServer exit (ZooKeeper session expired)

    RegionServer withdrew because ZooKeeper session expired, a headache for a long time, summed up the possible re ...
  5. flex (alternative session expired) the user time to re-login does not deal with operational requirements

    In some ways the Internet can see, but the effect was not good. Recent http://inflagrantedelicto.memoryspiral. ...
  6. Frameset in the login screen in the session expired page display problems.

    Sometimes the background page do some systems use a framework page. In general is a login screen, then jump to ...
  7. session expired out of the frame

    <script language="text/javascript"> top.location="a.jsp" </script> Can be achi ...
  8. session expired, the page jump to login page

    Add the login page <script type="text/javascript"> if (window != top) { top.location.href = lo ...
  9. (Transfer) php session expiration time set in

    Many people are given the answers online: modify php configuration file session.gc_maxlifetime. If you want to ...
  10. Some of the session and cookie understanding of

    See today a cookie on the session, and articles written in a very good feeling! On the reproduced, the origina ...
  11. cookie mechanism and the session mechanism

    A, cookie mechanism and the mechanism of the difference between session ************************************** ...
  12. cookie mechanism and the mechanism of the difference between session

    A, cookie mechanism and specifically the difference between session mechanism uses a cookie mechanism to maint ...
  13. cookie mechanism and the mechanism of the difference between session (reproduced)

    A, cookie mechanism and the mechanism of the difference between session ************************************** ...
  14. cookie mechanism and the mechanism of the difference between session (switched from 8366)

    A, cookie mechanism and specifically the difference between session mechanism uses a cookie mechanism to maint ...
  15. Logout time capture solution ----- java in the session of the correct understanding of collections

    Logout time capture solution ----- java collection in the session some time ago to do a correct understanding ...
  16. Ext Solutions asynchronous request session expiration

    Recently in the development of administrative system, using the Ext framework front, in the development proces ...
  17. Chapter VII of the Servlet Session Programming

    Chapter VII of the Servlet Session Programming 7.1 What is a session 7.3 Session underlying implementations fi ...
  18. A session cookie and persistent cookie mechanism to achieve the session (reproduced)

    A session cookie and persistent cookie mechanism to achieve the session When you first visit a site when the w ...
  19. Based on the servlet session tracking (1)

    Web projects Why should I use a session? Because stateless HTTP protocol, we can not distinguish between diffe ...