package com.wh.action;
import java.io.IOException;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.wh.entity.User;
import com.wh.servie.RegisterServie;
import com.wh.servie.RegisterServieIml;
import com.wh.utils.DateUtil;
@SuppressWarnings("serial")
public class RegisterServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
// TODO Auto-generated method stub
String function = request.getParameter("function");
if ("register".equals(function)) {
this.register(request, response);
}else if("reRegister".equals(function)) {
this.reRegister(request,response);
}
}
private void reRegister(HttpServletRequest request, HttpServletResponse response) throws IOException {
// TODO Auto-generated method stub
response.sendRedirect("/loginProject/register.jsp");
}
@SuppressWarnings("rawtypes")
private void register(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
String username = request.getParameter("username");
String password = request.getParameter("password");
String name = request.getParameter("name");
String gender = request.getParameter("gender");
int age = Integer.parseInt(request.getParameter("age"));
String address = request.getParameter("address");
Date regdate = DateUtil.dateParse(request.getParameter("regdate"), "yyyy-MM-dd ");
@SuppressWarnings("unused")
User user = new User(username, password, name, gender, age, address, regdate);
// 掉用service层
RegisterServie registerServie = new RegisterServieIml();
Enum registerStatu = registerServie.register(user);
request.setAttribute("rs", registerStatu);
request.getRequestDispatcher("/registerStatu.jsp").forward(request, response);
}
}
注册的action层
最新推荐文章于 2023-05-23 17:40:03 发布