Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convertion 2

Status
Not open for further replies.

yama

Programmer
Jun 28, 2001
69
SG
Hi everyone, does anyone how to convert a string that you get from a form to an integer type using jsp? thanks alot.
 
try---
String str = request.getParameter("variable");
int i = Integer.parseInt(str);
hope this helps you.
 
It is very important you check for null and empty strings especially if you are accepting input from an html INPUT box.

Code:
int i;
Integer j;
String formElement = request.getParameter("formElement");
if (formElement != null && !formElement.trim().equals("")) {
  
    /* to convert to a primative int */
    i = Integer.parseInt(formElement);

    /* to convert to an Integer object */
    j = new Integer(formElement);
}
Wushutwist
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top