Null Pointer after try catch

2

Servlet:

@WebServlet("/AdicionaContato")
public class AdicionaContatoServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //busca o writter
        PrintWriter out = response.getWriter();

        //busca parametros
        String nome = request.getParameter("nome");
        String endereco = request.getParameter("endereco");
        String email = request.getParameter("email");
        String dataEmTexto = request.getParameter("DataNascimento");

        //Converter data
        Calendar dataNascimento = null;
        try {
            Date date = new SimpleDateFormat("dd/MM/yyyy").parse(dataEmTexto);
            dataNascimento = Calendar.getInstance();
            dataNascimento.setTime(date);
        } catch (ParseException e){
            out.println("Erro na conversão da data");
            return;
        }
    }
}

After using SimpleDataFormat and set date with getInstance / setTime was not it to be populated?

My HTML page that makes subbmit

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Adicionar contatos</title>
</head>
<body>
      <form action="AdicionaContato">
       Nome : <input type="text" name="nome" /> <br/>
       E-mail: <input type="text" name="email" /> <br/>
       Endereço: <input type="text" name="endereco" /> <br/>
       Data Nascimento: <input type="text" name="dataNascimento" /><br/>
       <input type="submit" value="Gravar">
</form>
</body>
</html>
    
asked by anonymous 06.03.2018 / 11:58

1 answer

6

The% of the input of the date of birth is different from the name used in name .

One looks like this: getParameter(String) , and the other is like this: dataNascimento DataNascimento is Case Sensitive .

Make sure this is not the cause of the problem.

    
06.03.2018 / 12:03