Note that there are some explanatory texts on larger screens.

plurals
  1. POCheck Database value,when there is no interaction of user with session
    primarykey
    data
    text
    <p>I have written a test.jsp,web.xml and Session listener.For session timeout i am using <code>HttpSessionListener</code> feature.My session is getting invalidated after 1 minute,when there is no user interaction with the session. Technology used : JSP,Servlet JSP</p> <pre><code>&lt;%@ page import="java.util.List"%&gt; &lt;%@ page import="java.util.ArrayList"%&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Servlet Session Listener example&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h2&gt;Add User Screen&lt;/h2&gt; &lt;span style="float: right"&gt; &lt;a href="DestroySession.jsp"&gt;Destroy this session&lt;/a&gt; &lt;/span&gt; &lt;form method="post" action="AddUser.jsp"&gt; &lt;h3&gt;Enter Username to Add in List&lt;/h3&gt; &lt;input type="text" name="user"/&gt; &lt;input type="submit" value="Add User"/&gt; &lt;/form&gt; &lt;% List&lt;String&gt; users = (List&lt;String&gt;)session.getAttribute("users"); for(int i=0; null!=users &amp;&amp; i &lt; users.size(); i++) { out.println("&lt;br/&gt;" + users.get(i)); } %&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Java code</p> <pre><code>import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener; public class SessionListener implements HttpSessionListener { private int sessionCount = 0; public void sessionCreated(HttpSessionEvent event) { synchronized (this) { sessionCount++; } System.out.println("Session Created: " + event.getSession().getId()); System.out.println("Total Sessions: " + sessionCount); } public void sessionDestroyed(HttpSessionEvent event) { synchronized (this) { sessionCount--; } System.out.println("Session Destroyed: " + event.getSession().getId()); System.out.println("Total Sessions: " + sessionCount); } } </code></pre> <p>web.xml</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app&gt; &lt;display-name&gt;SessionListener&lt;/display-name&gt; &lt;distributable/&gt; &lt;listener&gt; &lt;listener-class&gt;SessionListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;session-config&gt; &lt;session-timeout&gt;1&lt;/session-timeout&gt; &lt;/session-config&gt; &lt;/web-app&gt; </code></pre> <p>My requirement is : When there is no interaction of user with the session for 1 minute, i want to invalidate session depending on some database value. If database value is false then session should not be invalidated. If database value is true then session should be invalidated. But after 1 minuter(when there is no interaction of user with the session), sessionDestroyed function of SessionListener class is automatically called and i am not able to check database value. How can i do this?</p>
    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.
 

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