File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session id destroy when browser or tab is closed

 
sudarshan jadhav
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone , I have a problem related to session handling in my code how to write a session invalidate method in browser tab closed or browser "X" closed event in servlet
and how to handling session timeout when session is timeout how session expire page is display in jsp when session is expire
Thank you in advance.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTTP is not a continuous-conversation protocol where the client connects to the server and they trade information asynchronously until the client disconnects.

Instead, each HTTP client request acts like it logs in, does one thing, then logs out. This request/response cycle repeats until the client stops sending requests.

At NO time is the server allowed to send a response to the client unless it's in response to a specific actual request and only one response is permitted per request.

So you cannot have a server post a "you timed out" page to the client. The closest you can get is to respond with a "you were timed out" response page if/when the client makes a request.

The other common thing people want to do is to notify the server that the client has closed a browser, window, or tab. There is no protocol defined for the World Wide Web to deal with that. If the user closes a server window/tab, the server is not notified by the client. Since there is no ongoing session to be dropped (remember, the connection only lasts long enough for the server to accept a request and return a response), there's no way the server will know that the client went away.
 
sudarshan jadhav
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thank you "Tim" for reply,
please give me solution for following point:
1) Window close or tab close event in jsp & servlet.
2) When the session timeout tag is set in web.xml then display session expire page in jsp.
 
Paul Clapham
Sheriff
Pie
Posts: 20168
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sudarshan jadhav wrote: please give me solution for following point:
1) Window close or tab close event in jsp & servlet.
2) When the session timeout tag is set in web.xml then display session expire page in jsp.


Let me summarize Tim's answer for you:

You can't do either of those things. In other words, there is no solution.
 
sudarshan jadhav
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thank you "paul" for reply,
But what is any other idea about the solution when the browser tab is closed or window is closed any java script is write for closing tab or browser???
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You simply need to rely upon the session timeout. The timeout could happen at any time and you cannot even know if the user is even looking at one of your pages when it occurs. It's likely they're off looking at videos of kittens at the time.
 
sudarshan jadhav
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all of you for reply,
My problem is that when user is login user related key is stored in hashmap entry of servlet context listener but when user side browser is closed then user related key is present in hashmap entry table how to remove this key from hashmap
please give me solution for this
Thank you in advance.............
 
J. Kevin Robbins
Bartender
Pie
Posts: 1605
15
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the api for SessionListener. I've never used one, but it may be what you are looking for.
 
G krishna kumar
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the sample code how to use invalidate().

public void service(HttpServletRequest request,HttpServletResponse response) {


HttpSession session = request.getSession(false);

if(session != null) {

try {
session.invalidate();
PrintWriter out = response.getWriter();
out.println("<a href=\"/ls\">redirection to login screen </a>");

}catch(java.io.IOException e){

e.printStackTrace();
}

}


}
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic