• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet Request (Integer)  RSS feed

 
Ben Brown
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
 
Nicola Romeo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
  • 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

 
Vikas Aggarwal
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!