protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String forward = ""; String action = request.getParameter("action"); if (action.equalsIgnoreCase("delete")) { int userId = Integer.parseInt(request.getParameter("userId")); String email = request.getParameter("email"); dao.deleteUser(userId, email); forward = LIST_USER; request.setAttribute("users", dao.getAllUsers()); } else if (action.equalsIgnoreCase("edit")) { forward = EDIT; int userId = Integer.parseInt(request.getParameter("userId")); Doctor user = dao.getUserById(userId); request.setAttribute("user", user); } else if (action.equalsIgnoreCase("listUser")) { forward = LIST_USER; request.setAttribute("users", dao.getAllUsers()); } else { forward = INSERT; } RequestDispatcher view = request.getRequestDispatcher(forward); view.forward(request, response); }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Doctor user = new Doctor(); user.setFirstName(request.getParameter("firstName")); user.setLastName(request.getParameter("lastName")); try { Date dob = new SimpleDateFormat("MM/dd/yyyy").parse(request.getParameter("dob")); user.setDob(dob); } catch (ParseException e) { e.printStackTrace(); } user.setEmail(request.getParameter("email")); user.setName(request.getParameter("email")); user.setPass(request.getParameter("pass")); user.setaddress(request.getParameter("uadd")); user.setphone(request.getParameter("uphone")); user.setqualification(request.getParameter("uqual")); user.setspecialization(request.getParameter("uspec")); System.out.println("Added"); String userid = request.getParameter("userid"); if (userid == null || userid.isEmpty()) { dao.addUser(user); } else { user.setUserid(Integer.parseInt(userid)); dao.updateUser(user); } RequestDispatcher view = request.getRequestDispatcher(LIST_USER); request.setAttribute("users", dao.getAllUsers()); view.forward(request, response); }