javaweb学生管理系统------注册功能的实现

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);
		}
	}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zzbkong

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值