I keep running into the same error after trying to parse a String parameter I pulled from a corresponding jsp and make them into an integer and a float. In my web application I have java classes where the values I'm trying to parse are an integer and a float, but I can't seem to find a way to parse them and have my servlet work the way I'd like it to. Here's the code I used in my servlet:
//get Parameter from newStudentPage.jsp
String id = request.getParameter("stuId");
String fName = request.getParameter("fName");
String lName = request.getParameter("lName");
String street = request.getParameter("street");
String city = request.getParameter("city");
String state = request.getParameter("state");
String zip = request.getParameter("zip");
String email = request.getParameter("email");
String gpa = request.getParameter("gpa");
int Zip = Integer.valueOf(zip);
float GPA = Float.parseFloat(gpa);
//Use RequestDispatcher to forward to jsp's
RequestDispatcher rd = request.getRequestDispatcher("newStudentLoginPage.jsp");
RequestDispatcher 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(street);
s2.setcity(city);
s2.setstate(state);
s2.setzip(Zip);
s2.setemail(email);
s2.setgpa(GPA);
//Put Student object into Session
HttpSession ses2 = request.getSession();
ses2.setAttribute("s2", s2);
if(id.equals("")||fName.equals("")||lName.equals("")||street.equals("")||city.equals("")||state.equals("")||zip.equals("")||email.equals("")||gpa.equals("")){
rd.forward(request, response);
}else{
rd2.forward(request, response);
}
Can anyone please offer my some insight to what I'm doing wrong?
ziporgpais blank or a space (since we don't have a stack trace, just a portion of the stack trace as your question title). As a result, parsing""or" "will be a problem. Either you need to do an empty check or make sure that any pages leading to this one require a zip and gpa.