0
I have a form in JSP that makes a register 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 there’s the problem. How do I convert this String of Input using the request.getParameter like I did with the others Strings? The way I did in mine Servlet is not spinning. Someone could help me.
Follows my Servlet down 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>");
    }
}
Tiago, welcome to [en.so]! You need to tell us what the mistake is. The code looks right.
– utluiz
Ola utluiz. Thank you for answering. You are making an error on this line: compromise.setData(data); The error is this: incompatible types : Calendar cannot be converted to Date.
– Tiago Frioli