• 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

an Integer in session

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I want to pass an integer from a servlet to JSP. If I put it in session I'm not able to retrieve it as I'm not able to cast it from object type to int type, I'm also not able to pass it with the URL as I'm not able to cast string to int, I'm not allowed to use cookies. How can I do it ? your suggestions please. When I use the following command I don't know why but when I retrieve the value of indSelect I get the value 'pageSelected' rather then value 12 which I'm assigning it in the servlet
int pageSelected = 12;
getServletConfig().getServletContext().getRequestDispatcher("/jsp/showResults.jsp?indSelect=pageSelected").forward(request, response);
Thanks
Neha
 
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What James posted is ofcourse the optimum solution in this case but i wanted to follow up on your error with values.
You should go about it this way :

That is concatenate the pageSelected variable not include it in the string ofcourse it will be passed as a String value.
Generally just use the way James mentioned is much better.
------------------
KaReEm
 
Neha Sharma
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks James & Kareem,
Your input helped me a lot to get away with the problem I was facing. Can you guys or anybody else tell me how can I convert string to int. Because I'm passing int values as string from my HTML to my servlet. How do I get those values back as int.
Thanks
Neha
 
Kareem Gad
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
simple as :
int intValue = Integer.parseInt(stringValue);

its a static method so you can call it this way .
------------------
KaReEm
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic