java.text.ParseException: Unparseable date: "" 代码和老师一样,但是日期格式一直报错?
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
Users users = new Users();
String username,mypassword,gender,email,introduce,isAccept;
Date birthday;
String[] favorites;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
username = request.getParameter("username");
mypassword = request.getParameter("mypassword");
gender = request.getParameter("gender");
email = request.getParameter("email");
introduce = request.getParameter("introduce");
birthday = sdf.parse(request.getParameter("birthday"));
if(request.getParameterValues("isAccept") != null){
isAccept = request.getParameter("isAccept");
}else{
isAccept = "false";
}
favorites = request.getParameterValues("favorite");
users.setUsername(username);
users.setMypassword(mypassword);
users.setGender(gender);;
users.setEmail(email);;
users.setFavorites(favorites);
users.setIntroduce(introduce);
users.setBirthday(birthday);
if(isAccept.equals("true")){
users.setFlag(true);
}else{
users.setFlag(false);
}
//把注册成功的用户对象保存到session中
request.getSession().setAttribute("regUser", users);
request.getRequestDispatcher("../userinfo.jsp").forward(request, response);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}