public class RegServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//接收注册表的个人信息
String id = request.getParameter("id");
String name = request.getParameter("name");
String age = request.getParameter("age");
String sex = request.getParameter("sex");
String userName=request.getParameter("userName");
String password=request.getParameter("password");
String password2=request.getParameter("password2");
//创建session对象储存注册结果
HttpSession httpSession=request.getSession();
httpSession.setAttribute("errorMsg", " ");
//判断两次输入的密码是否一致
if(!password.equals(password2)||password==null||password2==null) {
httpSession.setAttribute("errorMsg", "密码为空或密码不一致!");
request.getRequestDispatcher("/Register.jsp").forward(request,response);
}
//创建学生对象保存学生信息
Student stu=new Student();
stu.setId(id);
stu.setName(name);
stu.setAge(Integer.parseInt(age));
stu.setSex(sex);
stu.setUserName(userName);
stu.setPassword(password);
StuDao stuDao=new StuDao();
String info=stuDao.addstudent(stu);
if(info.equals("success")) {
//用户注册成功
httpSession.setAttribute("errorMsg","");
request.getRequestDispatcher("/login.jsp").forward(request,response);
}else {
//用户注册失败
httpSession.setAttribute("errorMsg", "注册失败,请检查注册信息");
request.getRequestDispatcher("/Register.jsp").forward(request,response);
}
}
}
javaweb学生管理系统------注册功能的实现
最新推荐文章于 2023-01-01 17:35:58 发布