File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Invalidating session on browser refresh Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Invalidating session on browser refresh" Watch "Invalidating session on browser refresh" New topic

Invalidating session on browser refresh

Ravi Kiran Savirigana

Joined: Nov 24, 2008
Posts: 20
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,
if(ref == 1)

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

But i'm getting some exceptions

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


SCJP 5.0 | SCWCD 5.0
David Newton

Joined: Sep 29, 2008
Posts: 12617

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).
I agree. Here's the link:
subject: Invalidating session on browser refresh
It's not a secret anymore!