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>