package com.neuedu.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.neuedu.pojo.User;
import com.neuedu.service.IUserService;
import com.neuedu.service.ipml.UserServiceImpl;
/**
* Servlet implementation class regservlet
*/
@WebServlet("/regservlet")
public class regservlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public regservlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String name = request.getParameter("name");
String password = request.getParameter("password");
String repeatpwd = request.getParameter("repeatpwd");
String email = request.getParameter("email");
String idcard = request.getParameter("idcard");
IUserService userservice = new UserServiceImpl();
User j = userservice.checkuser(name);
if (j == null) {
User user = new User();
user.setName(name);
user.setPassword(password);
user.setRepeatpwd(repeatpwd);
user.setEmail(email);
user.setIdcard(idcard);
int i = userservice.adduser(user);
String result;
if (i > 0) {
response.getWriter().print("成功登录");
} else {
request.setAttribute("result", "注册失败");
}
} else {
response.getWriter().print("用户名已存在注册");
}
}
}