package com.skic.servlet;

import java.io.IOException;
import java.io.PrintWriter;

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

import com.skic.DTO.UserDTO;
import com.skic.service.CheckNameService;

public class CheckNameServlet extends HttpServlet {

	private static final long serialVersionUID = -4871016110718914020L;
	private CheckNameService cns = new CheckNameService();
	public CheckNameServlet() {
		super();
	}

	public void destroy() {
		super.destroy();
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		request.setCharacterEncoding("utf-8");
		//System.out.println("checkNameServlet开始执行");
		PrintWriter out = response.getWriter();
		String userName = request.getParameter("name");
		UserDTO user = new UserDTO();
		user.setUserName(userName.trim());
		boolean rsName = cns.CheckName(user);
	    if (userName.trim().equals("")) {
	        out.print(1);
	    } else if (rsName) {
	        out.print(2);
	    } else {
	        out.print(3);
	    }
	}

	public void init() throws ServletException {
		
	}

}
