Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When your session expires the session object will return null from the request object.</p> <pre><code>if(request.getSession(false)==null){ //Session expired or never existed } else{ //session is still good. } </code></pre> <p>It is better practice to leave such testing up to a filter that can check each request but you could do it inside a JSP or inside a servlet. Putting redirection code inside a JSP tends to make it more complicated and takes your focus away from the UI. I would recommend using a filter, if not then in the servlet that routes requests to your JSP ( Your controller). If your not using a controller... </p> <p><strong>JSP Version</strong> (Not Recommended) - Inside your JSP use the following</p> <pre><code>&lt;% if(request.getSession(false)==null){ //session has expired response.sendRedirect("/ExpiredPage"); } else{ //Do what you normally would } %&gt; </code></pre> <p><strong>Servlet Version</strong> (Better) - Inside the servlet that calls your JSP use the following</p> <pre><code>public void doGet(HttpServletRequest request,HttpServletResponse){ if(request.getSession(false)==null){ //session has expired response.sendRedirect("/ExpiredPage"); } else{ //Do what you normally would } } </code></pre> <p><strong>Filter Version</strong> (Best Choice) - Inside your filter that calls your servlet that calls your JSP use the following</p> <pre><code>public void doFilter(ServletRequest request,ServletResponse, FilterChain chain){ if((HttpServletRequest)request.getSession(false)==null){ //session has expired ((HttpServletResponse)response).sendRedirect("/ExpiredPage"); } else{ //Do what you normally would chain.doFilter(request,response); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload