Content

Board ID 830
Writer 허진경
Write Date 2018-03-15 11:10:14
Subject EmpServlet
Content EmpServlet
package com.coderby.myapp;

import java.io.IOException;
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/Emp.do")
public class EmpServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	IEmpDAO dao = new EmpDAO();
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		EmpVO emp = new EmpVO();
		emp.setEmployeeId(Integer.parseInt(request.getParameter("employeeId")));
		emp.setFirstName(request.getParameter("firstName"));
		emp.setLastName(request.getParameter("lastName"));
		emp.setPhoneNumber(request.getParameter("phoneNumber"));
		
		SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd");
		String hireDateStr = request.getParameter("hireDate");
		java.sql.Date hireDate = new java.sql.Date(new java.util.Date().getTime());
		try {
			hireDate = new java.sql.Date(transFormat.parse(hireDateStr).getTime());
		} catch (ParseException e) {
			System.out.println("잘 못된 잘짜 형식");
		}
		emp.setHireDate(hireDate);

		dao.insertEmp(emp);
		response.getWriter().append("OK");
	}

}