Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

can't i put int value in Session?  RSS feed

 
asif kilwani
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • 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
 
sharad goswami
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any valid object can be put in session...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!