• 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

Servlet Request (Integer)

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a question regarding how to bring in integer values from a HTML page. I am having no problems pulling in Strings into my servlet.
Here is where I am confused.
String roleid = req.getParameter("txtroleid");
String name = req.getParameter("txtname");
String loginid = req.getParameter("txtloginId");
String funcid = req.getParameter("txtfuncId");
String progid = req.getParameter("txtprogId");
String type = req.getParameter("txttyp");
String cocode = req.getParameter("txtcocode");
String costctr = req.getParameter("txtcostctr");
int persnbr = req.getParameter("txtpersnbr");
String perstype = req.getParameter("txtperstype");
int rolelevel = req.getParameter("txtrolelevel");

any ideas?
Thanks
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Brown:
I have a question regarding how to bring in integer values from a HTML page. I am having no problems pulling in Strings into my servlet.
Here is where I am confused.
String roleid = req.getParameter("txtroleid");
String name = req.getParameter("txtname");
String loginid = req.getParameter("txtloginId");
String funcid = req.getParameter("txtfuncId");
String progid = req.getParameter("txtprogId");
String type = req.getParameter("txttyp");
String cocode = req.getParameter("txtcocode");
String costctr = req.getParameter("txtcostctr");
int persnbr = req.getParameter("txtpersnbr");
String perstype = req.getParameter("txtperstype");
int rolelevel = req.getParameter("txtrolelevel");

any ideas?
Thanks


Try to use int rolelevel =Integer.parseInt(req.getParameter("txtrolelevel"));
Bye
 
Ben Brown
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nicola Romeo:
Try to use int rolelevel =Integer.parseInt(req.getParameter("txtrolelevel"));

[B]Nicola,
Thanks, everything works now!
-Ben

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
although int persnbr = Integer.parseInt(req.getParameter("txtpersnbr")); works but it is quite on the safer side if you first check the values coming from the html page for the null values otherwise it will give you NumberFormatException. On the safer side try:
int persnbr=0;
String temp=req.getParameter("txtpersnbr");
if((temp!=null)&&(temp.equals("null")))
{
persnbr=Integer.parseInt(temp);
}
and do this in a try catch block so that any exception can be caught and tackled immediately like you can give error message to the user.

Originally posted by Ben Brown:
I have a question regarding how to bring in integer values from a HTML page. I am having no problems pulling in Strings into my servlet.
Here is where I am confused.
String roleid = req.getParameter("txtroleid");
String name = req.getParameter("txtname");
String loginid = req.getParameter("txtloginId");
String funcid = req.getParameter("txtfuncId");
String progid = req.getParameter("txtprogId");
String type = req.getParameter("txttyp");
String cocode = req.getParameter("txtcocode");
String costctr = req.getParameter("txtcostctr");
int persnbr = req.getParameter("txtpersnbr");
String perstype = req.getParameter("txtperstype");
int rolelevel = req.getParameter("txtrolelevel");

any ideas?
Thanks



------------------
Vikas Aggarwal
Technology Associate
Shakun Global Networks
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic