package com.control;

import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import com.beans.EmployeeBean;

//public class EmployeeServlet extends HttpServlet{
//   /**
//	 * 
//	 */
//	private static final long serialVersionUID = 1L;
//
//public void doPost(HttpServletRequest request, 
//HttpServletResponse response) 
//                     throws ServletException,IOException{
//  
//      String eno = request.getParameter("eno");
//      String ename = request.getParameter("ename");
//      String ecompany = request.getParameter("ecompany");
//      EmployeeBean employee = new EmployeeBean();
//      employee.setEno(eno);
//      employee.setEname(ename);
//      employee.setEcompany(ecompany);
//      
//      request.setAttribute("employee", employee);
//      RequestDispatcher view =
//           request.getRequestDispatcher("/displayEmployee.jsp");
//      view.forward(request, response);
//  }
//}

@WebServlet("/employee")
public class EmployeeServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 获取表单参数
        String eno = request.getParameter("eno");
        String ename = request.getParameter("ename");
        String ecompany = request.getParameter("ecompany");

        // 封装为 EmployeeBean 对象
        EmployeeBean employee = new EmployeeBean();
        employee.setEno(eno);
        employee.setEname(ename);
        employee.setEcompany(ecompany);

        // 将 EmployeeBean 对象设置为请求属性
        request.setAttribute("employee", employee);

        // 转发到 displayEmployee.jsp
        RequestDispatcher view = request.getRequestDispatcher("/displayEmployee.jsp");
        view.forward(request, response);
    }
}
