aspose file tools*
The moose likes Servlets and the fly likes How to end the user's session on closing the browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to end the user Watch "How to end the user New topic
Author

How to end the user's session on closing the browser

bhaskar selvaraj
Greenhorn

Joined: Nov 05, 2012
Posts: 9
Hi,

Can any of you provide a code snippet to end the user's session on closing the browser using the servlets. actually i don't want any logout buttons in the application,so I need to end the user's session when they closes their browser.



Thanks,
Bhaskar
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 537

bhaskar selvaraj wrote:Hi,
actually i don't want any logout buttons in the application,so I need to end the user's session when they closes their browser.

Why you don't need any logout button?
There is no reliable way to find out the close of browser, you need to rely upon the session timeout...
bhaskar selvaraj
Greenhorn

Joined: Nov 05, 2012
Posts: 9
Hi Prasad,

I saw one application basically built using servlets and JSP without logout functionality, but when you close the browser the user's session ends and if you hit again that URL by re-opening the browser it displays a login screen.


Regarding the clarification you gave,

Do you mean the <session-timeout> tag in the web.xml. If not could you explain me in detail.

Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 537

Yes i meant session-time-out. You can set it to a very minimum value, say 5 mins, but the disadvantage of this is, even if the user is idle for 5 mins, without closing the browser, the session gets expired.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to end the user's session on closing the browser