• 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

Wrapper Class Problem with the httpSession

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I want to have a Variable in a Session. In a Scenario i am fetching a variable from the session will replace back after incrementing it. But in the .SetAttribute we are allowed to have only the Objects. So i created an abject for int fromt the Wrapper Class ie Integer(0). Now i am able to set it in a Session.

Is it possible to convert this Integer(0) 's Object to its primitive type ie int. or is it possible to directly increment the object of the Wrapper Class with ++ Operater.


The code is as follows
-------------------------------------------------------------------------
HttpSession hSess= request.getSession(false);
hSess.setAttribute("counter",new Integer(0));
// new Integer Object is set in session

------------------------------------------------------------------------
Code to fetch and increment in a .jsp page (code in enclosed in a scriplets)
=----------------------------------------------------------------------
Integer YO= new Integer(0);

// fetching the Objct from the Session
YO=session.getAttribute("counter");
YO++// this fires error..

-----------------------------------------------------------------------

So please let me know if my code is fine else what be done to solve this problem.

Thank you
Regards
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a general question about java.lang.Integer -- you cannot increment it. Integer objects are immutable.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question really has little to do with sessions, and more to do with primitive wrapper calsess, so I've moved this to the Java in General (beginner) forum.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change Y++; to Y= new Integer(Y.intValue()+1);
 
Ranganath .S.Junpal
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a Lot!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic