• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

can't i put int value in Session?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am playing around with the JDBC..however i have to put user id in session for some interactivity in my next servlet. But HttpSession don't accept int value....is there a way to put int value in it?

------------------
regards,
Asif Kilwani
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can only store Objects, not primitives.
Use the int-wrapper: java.lang.Integer
session.setAttribute("int", new Integer(primitive));
Dave.
[This message has been edited by David O'Meara (edited December 05, 2001).]
 
asif kilwani
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
whats the diff btw new Integer(primitive) and Integer.parsetInt(primitive).
I tried Integer.parseInt(primitive) in session attributes but gave me error
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
new Integer(primitive) is wrapping an Integer object around your primitive in so that it can be put in the session since sessions only accept object.
Integer.parsetInt(primitive) is just trying to parse the primitive int to verify if it's actually a numeric integer avriable.
Bottom line...they are two diferent things. Check the API for more info.
------------------
Bosun
SCJP for the Java� 2 Platform
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any valid object can be put in session...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic