wood burning stoves 2.0*
The moose likes JSP and the fly likes How to destroy session attribute? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to destroy session attribute?" Watch "How to destroy session attribute?" New topic
Author

How to destroy session attribute?

raj malhotra
Ranch Hand

Joined: Feb 22, 2007
Posts: 285
Hi friends i have set an attribute in jsp and if i close the browser and
again open the browser and try to view the same jsp .That session attribute still persist.Can any one suggest me the way to destroy the attribute on closing window.

Thanks
Raj
[ February 15, 2008: Message edited by: Bear Bibeault ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

That doesn't sound like a session variable issue to me.
It sounds like you've got instance variables in your page.

Can you post the code?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
raj malhotra
Ranch Hand

Joined: Feb 22, 2007
Posts: 285
Hi Ben Thanks for reply .Here is the snippet:



i am automatically refreshing this page after 5 sec using meta tag given
below.It goes in <head> tag:


I am getting message Second Timer even i reopen the browser.It means time attribute is still there..

[ February 15, 2008: Message edited by: raj malhotra ]
[ February 15, 2008: Message edited by: raj malhotra ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Hmm.
I just tried your code and it's not doing that on my machine.
After closing the browser, I see "First Timer".
What browser are you using?

Are you sure that you're really closing it?
What I mean when I ask this, is, do you have any browser windows left open?
I know that, with Firefox, if I have a separate window (console debugger, LiveHeaders, download manager, etc..) open, if I close the main Firefox window but not the others, Firefox is still running and maintaining its sessions.
I just tried this and after re-opening Firefox, "Second Timer" came up.
When I shut ALL the Firefox windows and re-opened it, "First Timer" was the first message to come up.
[ February 15, 2008: Message edited by: Ben Souther ]
raj malhotra
Ranch Hand

Joined: Feb 22, 2007
Posts: 285
Hi Ben
Thanks for your analysis.Yes i am using Firefox and there were many other windows open.I think this was the problem.I got it.But let me tell you what i am trying to achieve,may be you have some better idea.
I want to develop one monitor jsp which will show the web crawling status.Jsp will contain one button 'crawl'. if i click that, a java class's crawl method will be called which will crawl website.This page will automatically refresh itself to get the status from crawl class.I don't want that crawl method to execute on every refresh.I will call method invocation in 'if' condition and monitor logic in 'else' part.Is there any other way than using session?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

There are several ways to store state other than sessions.
You can use cookies, hidden form variables, or you can store your state information in a file or a database.

When your page refreshes, you could simply add a querystring variable that lets the server know that the page is only checking the status and that crawl method should not be called again.
raj malhotra
Ranch Hand

Joined: Feb 22, 2007
Posts: 285
Thanks for suggestions
 
wood burning stoves
 
subject: How to destroy session attribute?
 
Similar Threads
Destroy session when close browser.
session management for logout
how to invalidate a session when browser is closed
How can I redirect from sessionDestroyed() of Session Listener
Session need to be destroyed when browser closes