I have a form in JSP
that performs a registration that has a date.
<form method="Post" action="InserirCompromisso">
titulo : <input type="text" name="titulo" required="true">
local : <input type="text" name="local" required="true">
data : <input type="text" name="data">
<input type="submit" value="Cadastrar">
</form>
And here's the problem. How do I convert this String
of Input
using request.getParameter
as I did with other Strings
? The way I did it on my Servlet
is not running. Could anyone help me.
Follow my Servlet
below.
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String Titulo = request.getParameter("titulo");
String Local = request.getParameter("local");
String dataEmTexto = request.getParameter("data");
Calendar data = null;
try {
Date date = new SimpleDateFormat("dd/MM/yyyy").parse(dataEmTexto);
data = Calendar.getInstance();
data.setTime(date);
} catch (ParseException e) {
out.println("Erro de conversão da data");
return; //para a execução do método
}
Compromisso compromisso = new Compromisso();
compromisso.setTitulo(Titulo);
compromisso.setLocal(Local);
compromisso.setData(data);
CompromissoDAO dao = new CompromissoDAO();
String retorno = dao.inserir(compromisso);
if(retorno.equals("sucesso")){
response.sendRedirect("index.jsp");
}else{
PrintWriter out = response.getWriter();
out.print("<html>");
out.print("<h2>Não foi possivel inserir</h2>");
out.print("<br>");
out.print("</html>");
}
}