• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Auto logout after 15 seconds?

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Android Mac OS X Firefox Browser Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What security is afforded by timing out after 15 seconds?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 8
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 33
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic