• Post Reply Bookmark Topic Watch Topic
  • New Topic

an Integer in session  RSS feed

 
Neha Sharma
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • 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
 
James Swan
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Kareem Gad
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
simple as :
int intValue = Integer.parseInt(stringValue);

its a static method so you can call it this way .
------------------
KaReEm
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!