Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Sending parameters????

 
Greenhorn
Posts: 18
  • 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.
 
Ranch Hand
Posts: 687
Hibernate jQuery Spring
  • 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>");
 
Greenhorn
Posts: 14
  • 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
  • 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 ".
 
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic