package com.neuedu.javaweb.chap02;
import java.io.IOException;
import java.io.PrintWriter;
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.servlet.IUserservlet;
import com.neuedu.servlet.impl.UserservletImpl;
/**
* Servlet implementation class Regnoservlet
*/
@WebServlet("/regnoservlet")
public class Regnoservlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Regnoservlet() {
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 {
// TODO Auto-generated method stub
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String name=request.getParameter("username");
System.out.println(name);
String pwd=request.getParameter("password");
System.out.println(pwd);
String repwd=request.getParameter("repassword");
System.out.println(repwd);
String email=request.getParameter("email");
System.out.println(email);
String idcard=request.getParameter("idcard");
System.out.println(idcard);
String[] Cookie=request.getParameterValues("CookieYN");
System.out.println(Cookie);
response.setContentType("text/html;charset=UTF-8");
User user=new User();
user.setUsername(name);
user.setPassword(pwd);
user.setRepassword(repwd);
user.setEmail(email);
user.setIdcard(idcard);
IUserservlet mm=new UserservletImpl();
int i=mm.addUser(user);
if(i>0){
System.out.println("成功");
response.sendRedirect(request.getContextPath()+"/login.html");
}else{
System.out.println("失败");
}
}
}
网友评论