File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes session.removeAttribute and session.invalidate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "session.removeAttribute and session.invalidate" Watch "session.removeAttribute and session.invalidate" New topic
Author

session.removeAttribute and session.invalidate

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
I pass a scoped object from one JSP #1 to JSP #2 in a session.

In JSP #1, I did:


In JSP #2, I did:


Immediately after I output the value, I want to remove the object from the session. I have two questions:
1. which one of the following should I do:

or

or

2. Do I have to invalidate the session; i.e. session.invalidate(); after all the objects in the session are removed?

[ July 06, 2004: Message edited by: JiaPei Jen ]
[ July 06, 2004: Message edited by: JiaPei Jen ]
Atul Prabhu
Ranch Hand

Joined: Dec 17, 2002
Posts: 60
Hi,

You would have to use session.removeAttribute( "cr" ), session.removeAttribute( "author" ) cannot be used because "author" is available in page scope.
session.removeAttribute( "reciever" ) cannot be used because "reciver" would be in the request scope after the form is submitted.

Why would u have to use session.invalidate()

Hope this solves ur problem.

Regards
Atul
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
2. Do I have to invalidate the session; i.e. session.invalidate(); after all the objects in the session are removed?

A single call to session.invalidate() will automatically remove all attached references. Of course you won't be able to use that session at all after that call - you will get an IllegalStateException.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session.removeAttribute and session.invalidate