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

Invalidating session on browser refresh

 
Ravi Kiran Savirigana
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
I wanted to invalidate session on browser refresh...or on opening the same url on other tab of the browser

Whit i thought is to declare a static int in action class, and increment it every time the action class gets hit.
So if I refresh the browser, that static variable gets initialized to 0, so that if i keep a check on the variable for its value to be 0, i can actually invalidate the session.

something like this

static int ref = 0;

in processRequest of action class,
ref++;
if(ref == 1)
processRefresh(request);



public void processRefresh(HttpServletRequest request) {
HttpSession session = request.getSession(false);
if(session!=null) {
System.out.println(session);
System.out.println("session existing....and being invalidated in processor....");
session.invalidate();
}


But i'm getting some exceptions



If there is any other way, can someone help me out??

Thanks
Ravi
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But i'm getting some exceptions

And they're secret, so you couldn't tell us what they are?

In any case, different browsers handle new tabs/windows differently: it's going to be tough to do this in any meaningful way without a fairly robust framework for handling session conversations (for example, like Seam does).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic