• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session.removeAttribute and session.invalidate

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic