wood burning stoves 2.0*
The moose likes Servlets and the fly likes Sending parameters???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Sending parameters????" Watch "Sending parameters????" New topic
Author

Sending parameters????

Chaitanya Reddy
Greenhorn

Joined: Jun 06, 2002
Posts: 18
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

Joined: Feb 09, 2002
Posts: 687

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

Joined: Nov 29, 2001
Posts: 14
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

Joined: Feb 09, 2002
Posts: 687

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 ".
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Sending parameters????
 
Similar Threads
display errors
Implementing HttpSession in the Spring MVC
Break Down Paragraph Text
JSTL help - forEach
servlets/jsp