java.text.ParseException: Unparseable date: "" 代码和老师一样,但是日期格式一直报错?

来源:1-11 Servlet获取表单数据

慕娘5532926

2018-08-16 09:27

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

}

}


写回答 关注

3回答

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

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

    慕仔1073...

    我去,我这个问题找了半天 我就说怎么回事得不到value

    2020-05-08 23:12:42

    共 1 条回复 >

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

    我也是呀 什么情况

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

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

JAVA遇见HTML——Servlet篇

本门课程在JSP课程的基础上,深入介绍Servlet的基础知识

160613 学习 · 1029 问题

查看课程

相似问题