package daben;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.naming.*;
import daben.*;

public class AddCustServlet extends HttpServlet 
{
  private static final String CONTENT_TYPE = "text/html;charset=gb2312";
  private CustFacadeAppHome custFacadeAppHome;          //无状态会话Bean--CustFacadeApp的Home接口
  private CustFacadeApp custFacadeApp = null;           //无状态会话Bean--CustFacadeApp的Remote接口
  
  public void init(ServletConfig config) throws ServletException
  {
    super.init(config);
  
  }


  


  public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
  {
    Long id;
    String khmc = "";
    String khlxr = "";
    String khdz = "";
    String dzyj = "";
    String dh = "";
    String yhzh = "";
    String jsfs= "";
    String jshb = "";
try
  {
      id = Long.valueOf(request.getParameter("khid"));
      khmc = request.getParameter("khmc");
      khlxr = request.getParameter("khlxr");
      khdz = request.getParameter("khdz");
      dzyj = request.getParameter("dzyj");
      dh = request.getParameter("dh");
      yhzh = request.getParameter("yhzh");
      jsfs = request.getParameter("jsfs");
      jshb = request.getParameter("jshb");
     //使用取得的参数初始化上下文变量，并通过JNDI查找无状态会话Bean--MysessionFacadeEJB的Home接口
      InitialContext ctx = new InitialContext();
      Object result = ctx.lookup("CustFacadeApp");
     CustFacadeAppHome custFacadeAppHome = (CustFacadeAppHome)javax.rmi.PortableRemoteObject.narrow(result, MySessionFacadeEJBHome.class);

   custFacadeApp = custFacadeAppHome.create();
       custFacadeApp.addCustomer(id,khmc,khlxr,khdz,dh,dzyj,yhzh,jsfs,jshb);
    }
    catch(Exception e){
      throw new ServletException(e.toString());
    }

    response.setContentType(CONTENT_TYPE);
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head><title>数据录入</title></head>");
    out.println("<body>");
    out.println("<p>数据录入成功!<a href=CustInfo.jsp>返回</a></p>");
    out.println("</body></html>");
    out.close();
    //response.sendRedirect("custoinfo.jsp");
  }
}