1

I recieved Data from a form via POST/GET method in a page. Now, by default, JSP takes that as string. I wanted to convert it to int and tried but it not worked.

My JSP Code for this is:

String editstr=request.getParameter("some_thing");
int edit;
edit=Integer.parseInt(editstr)

I also tried something like

int edit=Integer.parseInt(editstr)

Neither Works

cipher
  • 2,414
  • 4
  • 30
  • 54

2 Answers2

1

Do you get NumberFormatException or NullPointerException?

If not then look for an trouble in setting and getting the parameter some_thing.

kapandron
  • 3,546
  • 2
  • 25
  • 38
1

You must have to test the parameter whether it is null or not.

String editstr=request.getParameter("some_thing");
int edit=0;
if(editstr!=null){
   try{
     edit=Integer.parseInt(editstr);
   }catch(Exception ex) { 
     out.println(ex);
   }
}

PS: You should have to learn/use JSTL to avoid Java code in JSPs.

Community
  • 1
  • 1
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186