This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Primitives in Session 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 » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Primitives in Session" Watch "Primitives in Session" New topic

Primitives in Session

Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1075

Can we store any primitive type variable (for eg - float,char,int ) in Session scope ?
Waiting for a reply

Oracle Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I
Patil Niteen
Ranch Hand

Joined: Dec 10, 2009
Posts: 48

Hi Abhay,

HttpSession interface has methods to store and retreive the objects from session scope.The methods are:
setAttribute(String name, Object value)
Object getAttribute(String name)

If you want to store the premitives in the session scope you have to wrap them into corresponding object types and retreive the values by casting the return values.
For example, int values can be wrapped into Integer object and stored .

Hope this helps.

Thanks and Regards,

I agree. Here's the link:
subject: Primitives in Session
Similar Threads
Alternative to Cookie?
Field set in action method coming null in JSP
Advice on persisting complex state across multiple server trips
Session problem in NetBeans