This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sending parameters????

 
Chaitanya Reddy
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm calling a servlet from another :
pw.println("<tr><td><a target=\"new\" href='/servlet/threedstr?pid='fromdata'&spos='spos'&epos='epos'&cmd=5'> 3D Structure</a></td></tr>");
where the parameters pid,spos and epos are to be sent dynamically with the values in the corresponding variables.
But it is giving a runtime error: Number Format Exception.
Can someone tell me if this is the right way to pass values in variables as parameters?
Thanks.
 
Devesh H Rao
Ranch Hand
Posts: 687
Hibernate jQuery Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chaitanya,
try this if it works..
pw.println("<tr><td><a target=\"new\" href='/servlet/threedstr?pid="+fromdata+"&spos="+spos+"&epos="+epos+"&cmd=5> 3D Structure</a></td></tr>");
 
Andrey Orekhov
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As it seems from the exception, in the called servlet you try to read parameter value into numeric variable, but all parameter values are Strings in fact. So you need to take extra step and parse parameter string to extract number. Something like int paramA = Integer.parseInt(paramAValue);
 
Devesh H Rao
Ranch Hand
Posts: 687
Hibernate jQuery Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andrey Orekhov:
As it seems from the exception, in the called servlet you try to read parameter value into numeric variable, but all parameter values are Strings in fact. So you need to take extra step and parse parameter string to extract number. Something like int paramA = Integer.parseInt(paramAValue);

The exception will occur at the exact point where chaitanya would attempt something of this sort
"int paramA = Integer.parseInt(paramAValue);"
as in the query string that he is passing
(" pid='fromdata'&spos='spos'&epos='epos' ")
the values of pid,spos,and epos that will be passed will be "fromdata","spos" and "epos" respectively and not their numeric values as it is intended to be.
the single quote usage would not pick the numeric values for the pid,spos,and epos and hence need to be replaced with the URl using ".
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic