Forums Register Login

Auto logout after 15 seconds?

+Pie Number of slices to send: Send
Hi Guys,

I found a working Login/Logout using session.
How can I make it auto logout after 15 seconds without activity happen in the page?

Here's the code:

Validate.java


Welcome.jsp


logout.java


login.html


Thanks guys,
+Pie Number of slices to send: Send
There are 2 ways to set timeout, in web.xml (in minutes) or in programming (in seconds).

How are you setting the session-timeout in web.xml?
+Pie Number of slices to send: Send
 

K. Tsang wrote:There are 2 ways to set timeout, in web.xml (in minutes) or in programming (in seconds).

How are you setting the session-timeout in web.xml?



Here's my web.xml



how to add here?
1
+Pie Number of slices to send: Send
<session-config>
<session-timeout>30</session-timeout> <!-- in minutes -->
</session-config>

In the HttpSession class, there is a setMaxInactiveInterval(int) method that takes in "seconds". You may want to use this in your programming to "force" the timeout in 15 seconds.

But why you want to timeout in 15 seconds??
+Pie Number of slices to send: Send
 

K. Tsang wrote:<session-config>
<session-timeout>30</session-timeout> <!-- in minutes -->
</session-config>

In the HttpSession class, there is a setMaxInactiveInterval(int) method that takes in "seconds". You may want to use this in your programming to "force" the timeout in 15 seconds.

But why you want to timeout in 15 seconds??




I want this timeout for security reason.

How to redirect to login page after timeout?

Thanks,
1
+Pie Number of slices to send: Send
What security is afforded by timing out after 15 seconds?
+Pie Number of slices to send: Send
 

Bear Bibeault wrote:What security is afforded by timing out after 15 seconds?


Nobody can use the app so it is secure?

Seriously though, why 15 seconds vs 60 or 120 or 300 seconds?
+Pie Number of slices to send: Send
At client side use jquery code which will track a cookie.
This cookie shall have expire time of 15 sec.
So as and when you access any server side page the cookie gets updated with its time and when user stops interacting with server for more than 15sec the cookie will expire.
This cookie timeout shall be fired as an event in jquery and in the function of that event try to redirect to login page of your project.



I want this timeout for security reason.

How to redirect to login page after timeout?

Thanks,

 
+Pie Number of slices to send: Send
The usual way to handle this is as follows:

(1) When the user logs in, put their user ID (or some similar token) into the session.

(2) When the user logs out, remove that token from the session and invalidate the session.

(3) Use a servlet filter which checks that there is an active session and that it contains a user ID token. If not, then redirect to the login page.

Note that this is independent of the number of seconds it takes for an inactive session to become invalid. Note also that nothing happens when the session becomes invalid; the is-the-user-logged-in decision only takes place when the user sends a request.
+Pie Number of slices to send: Send
you can use the html meta tag....and redirect to a JSP page which invalidates the session....

however i dont feel its the right way to achieve it....
If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 16328 times.
Similar Threads
passing multiple values from one page to another
exchanging values from right to left on button click
Date format problem when using URLConnection to a JSP (JSTL 1.1)
INCLUDES.DBconnection error
problem with jsp for reset() method
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:01:24.