public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); printHtmlHeader(out); // process request String action = request.getParameter("action"); if (action == null) { // do nothing if no action requested } else if (action.equals("CreateEmp")) { Employee emp = empService.createEmployee( request.getParameter("empName"), parseLong(request.getParameter("salary"))); out.println("Created " + emp); } else if (action.equals("CreateDept")) { Department dept = deptService.createDepartment(request.getParameter("deptName")); out.println("Created " + dept); } else if (action.equals("SetEmployeeDept")) { Employee emp = empService.setEmployeeDepartment( parseInt(request.getParameter("empId")), parseInt(request.getParameter("deptId"))); out.println("Updated " + emp + "</br>"); out.println(emp.getDepartment() + " with Employees:</br>"); out.println(emp.getDepartment().getEmployees()); } else if (action.equals("FindAll")) { Collection<Employee> emps = empService.findAllEmployees(); if (emps.isEmpty()) { out.println("No Employees found "); } else { out.println("Found Employees: </br>"); for (Employee emp : emps) { out.println(emp + "<br/>"); } } out.println("</br>"); Collection<Department> depts = deptService.findAllDepartments(); if (depts.isEmpty()) { out.println("No Departments found "); } else { out.println("Found Departments: </br>"); for (Department dept : depts) { out.println( dept + " with " + dept.getEmployees().size() + " employees " + dept.getEmployees() + "<br/>"); } } } printHtmlFooter(out); }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); printHtmlHeader(out); // process request String action = request.getParameter("action"); if (action == null) { // do nothing if no action requested } else if (action.equals("CreateEmp")) { Employee emp = empService.createEmployee( request.getParameter("empName"), parseLong(request.getParameter("salary"))); out.println("Created " + emp); } else if (action.equals("CreatePhone")) { Phone phone = phoneService.createPhone( request.getParameter("phoneNum"), request.getParameter("phoneType")); out.println("Created " + phone); } else if (action.equals("addEmpPhone")) { Employee emp = empService.addEmployeePhone( parseInt(request.getParameter("empId")), parseInt(request.getParameter("phoneId"))); out.println("Updated " + emp + "</br>"); } else if (action.equals("FindAll")) { Collection<Employee> emps = empService.findAllEmployees(); if (emps.isEmpty()) { out.println("No Employees found "); } else { out.println("Found Employees: </br>"); for (Employee emp : emps) { out.println(emp + "<br/>"); } } out.println("</br>"); Collection<Phone> phones = phoneService.findAllPhones(); if (phones.isEmpty()) { out.println("No Phones found "); } else { out.println("Found Phones: </br>"); for (Phone phone : phones) { out.println(phone + "<br/>"); } } } printHtmlFooter(out); }