Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can We Store Something Other Than An Object In A Session?

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have seen how to store an object in a session and the syntax is

and we usually put String(s) in that object; for example, we have a customer object and we do the following:

Is it possible to store a String in a session? What if I only want to store a String "origin" in a session so that this String can be passed to all subsequent requests?
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JiaPei -
Guess what?
A String is an Object !! . So yes, you can put a String object in the session.
Just remember that when you use session.getAttribute("yourParameter"), it'll always return an Object, so you'll have to typecast it to a String.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic