Error on clicking the edit or delete button on ui
SEVERE: Servlet.service() for servlet [com.ntt.web.EmployeeServlet] in context with path [/CaseStudy] threw exception
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:592)
at java.lang.Integer.parseInt(Integer.java:615)
at com.ntt.web.EmployeeServlet.showEditForm(EmployeeServlet.java:130)
at com.ntt.web.EmployeeServlet.doGet(EmployeeServlet.java:75)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:615)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1627)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
EmployeeServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String action=request.getServletPath();
switch(action) {
case "/new":
showNewForm(request,response);
break;
case "/insert":
try {
insertUser(request,response);
} catch (ServletException | IOException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case "/delete":
try {
deleteUser(request,response);
} catch (ServletException | IOException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case "/edit":
try {
showEditForm(request,response);
} catch (ServletException | IOException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case "/update":
try {
updateUser(request,response);
} catch (ServletException | IOException | SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
break;
default:
try {
listEmployee(request,response);
} catch (ServletException | IOException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
}
private void listEmployee(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException, SQLException{
List<Employee> listEmployee=employeeDAO.selectAllEmployees();
request.setAttribute("listEmployee",listEmployee);
RequestDispatcher dispatcher=request.getRequestDispatcher("employee-list.jsp");
dispatcher.forward(request,response);
}
private void deleteUser(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException, SQLException{
int id=Integer.parseInt(request.getParameter("id"));
employeeDAO.deleteEmployee(id);
response.sendRedirect("list");
}
private void updateUser(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException, SQLException{
int id=Integer.parseInt(request.getParameter("id")); **errorline on which it shows error**
String employeename=request.getParameter("employeename");
String address=request.getParameter("address");
String dateofjoining=request.getParameter("dateofjoining");
String experience=request.getParameter("experience");
String dateofbirth=request.getParameter("dateofbirth");
Employee employee=new Employee(id,employeename,address,dateofjoining,experience,dateofbirth);
employeeDAO.updateEmployee(employee);
response.sendRedirect("list");
}
private void showEditForm(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException, SQLException{
int id=Integer.parseInt(request.getParameter("id"));
Employee existingEmployee=employeeDAO.selectEmployee(id);
RequestDispatcher dispatcher=request.getRequestDispatcher("employee-form.jsp");
request.setAttribute("employee",existingEmployee);
dispatcher.forward(request, response);
}
And also when i am inserting the data into the table it gets inserted there but i am not able to see the inserted data into my ui.And whem i try to click the edit or delete button on ui to edit or delete the data from table it shows error.