jsp - How do I fix a java.lang.NumberFormatException: for String " " in my servlet? -
After I parse a string parameter in an integer I pulled from a corresponding jsp and after trying to create them, in the same error The display continues and a float in my web application I have Java class, the one on which I am trying to parse is an integer and a float, but I can not find a way to parse and work my servlet By the way i am I'm so proud. Here the code I used in my servlet is: Get the parameter from Does anyone give me some insights into doing something wrong?
// newStudentPage.jsp string id = request.getParameter ("stuId"), string fName = request.getParameter (" FName "); String lName = request.getParameter ("lName"); String road = request.getParameter ("street"); String city = request.getParameter ("city"); String position = request.getParameter ("state"); String zip = request.getParameter ("zip"); String email = request.getParameter ("email"); String gpa = request.getParameter ("GPA"); Int zip = integer.valof (zip); Float GPA = Float. PRS Flat (GPA); // request a request dispatcher to forward the request of jsp to the despter rd = request.getRequestDispatcher ("newStudentLoginPage.jsp"); Request Dispatcher rd2 = request.getRequestDispatcher ("newStudentSectionAddDrop.jsp"); // Create Student Object and fill with Paramater Data Student S2 = New Student (); S2.setstuId (id); S2.setfName (fName); S2.setlName (lName); S2.setstreet (road); S2.setcity (city); S2.setstate (state); S2.setzip (zip); S2.setemail (email); S2.setgpa (GPA); // Keep student object in session Http session ses2 = request.getSession (); Ses2.setAttribute ("s2", s2); If (id.equals ("") || fName.equals ("") || lName.equals ("") || street.equals ("") || city.equals ("") || state.equals ("") || zip.eimals ("") || email. Angle ("") || GPAiagles ("")) {rd.forward (request, response); } And (rd2.forward (request, response);}
One or all of the rows can create exceptions:
int zip = integer.wooof (zip); float GPA = Float. PRSFLOT (GPA);
You have to see whether the string zip or GPA can always be converted to a number or not, what if the user Nothing enters into the code like "7777", ""
, ""
or non-number
? Due to those conditions a < Code> NumberFormatException will
Comments
Post a Comment