• Post Reply Bookmark Topic Watch Topic
  • New Topic

Auto logout after 15 seconds?  RSS feed

 
Lester Carmelotes
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Lester Carmelotes
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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??
 
Lester Carmelotes
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What security is afforded by timing out after 15 seconds?
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37250
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rajesh Vassey
Greenhorn
Posts: 8
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Paul Clapham
Sheriff
Posts: 22505
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sourabh Bawage
Ranch Hand
Posts: 33
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!