问答详情
源自:1-11 Servlet获取表单数据

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

}

}


提问者:慕娘5532926 2018-08-16 09:27

个回答

  • 慕沐7199068
    2019-04-24 12:16:06

    https://img3.mukewang.com/5cbfe2f30001af2607640426.jpg老师这个Accept拼错了

  • Vince_Lin
    2018-12-02 23:56:36

    我也是呀 什么情况

  • 慕仰5314311
    2018-08-16 15:08:49

    你导入java.util.Date这个包了吗?