request.getParameter()获取的页面数据从String类型转变为Date类型

String birthday = request.getParameter("birthday");

由于生日birthday在pojo类中的是date的类型,所以这里需要转换为date类型

        //因为生日在student中是日期类型,但是这里接收的时候是string类型,需要转型
       //sting--->date
		try {
			Date birth = new SimpleDateFormat("yyyy-MM-dd").parse(birthday);
            //将获取的信息进行封装
			Student student  = new Student(sname, sex, phone, hobby, birth, info);			
			//添加到数据库
			StuService serivice = new StuServiceImpl();
			serivice.insertStu(student);			
			//跳转列表页面
			request.getRequestDispatcher("StuListServlet").forward(request, response);
			} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

这个有异常,需要捕捉一下,然后在进行封装时,直接将birth存入即可。

发布了11 篇原创文章 · 获赞 4 · 访问量 184

猜你喜欢

转载自blog.csdn.net/liulianzi_147/article/details/104901723