This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Servlets and the fly likes session attributes type Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "session attributes type" Watch "session attributes type" New topic
Author

session attributes type

Richard Sorhands
Greenhorn

Joined: Dec 23, 2005
Posts: 11
Hi.
Can I set as a servlet session attribute an object that have not a simple type like int or String?
I want to use the method putValue with a Class "Phone" and i want to get it with a cast of method getValue. Is this possible? If it's not possible can you give me some suggestions?

Thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14672
    
  11

You can put any kind of types into the session (but not primitives, use wrappers). And call setAttribute, not putValue which is deprecated.


[My Blog]
All roads lead to JavaRanch
Richard Sorhands
Greenhorn

Joined: Dec 23, 2005
Posts: 11
what is a wrapper? why I have to use it?
[ May 29, 2006: Message edited by: Richard Sorhands ]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14672
    
  11

You cannot put primitives (int, char...) directly into a session attribute.
But you can use wrappers (Integer, Character...) instead.
Richard Sorhands
Greenhorn

Joined: Dec 23, 2005
Posts: 11
OK, thanks!
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8876

Originally posted by Satou kurinosuke:
You cannot put primitives (int, char...) directly into a session attribute.
But you can use wrappers (Integer, Character...) instead.


With Java 5 you dont need to create wrapper objects. Auto boxing will ensure that appropriate wrapper objects are created.


Groovy
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: session attributes type
 
Similar Threads
regarding invalidating sessions
overloading ejbCreate() methods
session listener
Session Information
problem in session