jsp - how do i solve the double method while string in java with servlet -
package com.dev.web.controller; import java.io.ioexception; import java.text.parseexception; import java.text.simpledateformat; import java.util.date; import javax.servlet.requestdispatcher; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import com.dev.web.dao.userdao; import com.dev.web.model.user; public class usercontroll extends httpservlet { private static final long serialversionuid = 1l; private static string insert_or_edit = "/user.jsp"; private static string list_user = "/listemp.jsp"; private userdao dao; public usercontroll() { super(); userdao dao = new userdao(); } protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { string forward=""; string action = request.getparameter("action"); if (action.equalsignorecase("delete")){ int employee_id= integer.parseint(request.getparameter("employee_id")); dao.deleteuser(employee_id); forward = list_user; request.setattribute("users", dao.getallusers()); } else if (action.equalsignorecase("edit")){ forward = insert_or_edit; int employee_id = integer.parseint(request.getparameter("empid")); user user = dao.getuserbyid(employee_id); request.setattribute("user", user); } else if (action.equalsignorecase("listuser")){ forward = list_user; request.setattribute("employee", dao.getallusers()); } else { forward = insert_or_edit; } requestdispatcher view = request.getrequestdispatcher(forward); view.forward(request, response); } protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { user user = new user(); user.setemployee_name(request.getparameter("empname")); user.setsalary(request.getparameter("empsalary"));// here error..i declared salary double try { date dob = new simpledateformat("mm/dd/yyyy").parse(request.getparameter("empdob")); user.setdob(dob); } catch (parseexception e) { e.printstacktrace(); } user.setactive(request.getparameter("empactive"));// here error.. declared active boolean string empid = request.getparameter("empid"); if(empid == null || empid.isempty()) { dao.adduser(user); } else { user.setemployee_id(integer.par`enter code here`seint(empid)); dao.updateuser(user); } requestdispatcher view = request.getrequestdispatcher(list_user); request.setattribute("users", dao.getallusers()); view.forward(request, response); } }
the getparameter()
method of httpservletrequest
inherited servletrequest
. api docs can see method returns string
. need parse boolean or double string, example
double.parsedouble(request.getparameter("empsalary"));
Comments
Post a Comment