jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<c:url value="/entrada" var="linkEntradaServlet"/>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="${linkEntradaServlet }" method="post">
Nome: <input type="text" name="nome" value="${empresa.nome }" />
Data Abertura: <input type="text" name="data" value="<fmt:formatDate value="${empresa.dataAbertura }" pattern="dd/MM/yyyy"/>" />
<input type="hidden" name="id" value="${empresa.id }">
<input type="hidden" name="acao" value="AlteraEmpresa">
<input type="submit" />
</form>
</body>
</html>
CLASSE
package br.com.alura.gerenciador.acao;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import br.com.alura.gerenciador.modelo.Banco;
import br.com.alura.gerenciador.modelo.Empresa;
public class AlteraEmpresa {
public void executaAlteracao(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String nomeEmpresa = request.getParameter("nome");
String paramDataEmpresa = request.getParameter("data");
Integer id = Integer.valueOf(request.getParameter("id"));
System.out.println("Alterando empresa" + id);
Date dataAbertura = null;
try {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
dataAbertura = sdf.parse(paramDataEmpresa);
} catch (ParseException e) {
throw new ServletException(e);
}
Banco banco = new Banco();
Empresa empresa = new Empresa();
empresa.setNome(nomeEmpresa);
empresa.setDataAbertura(dataAbertura);
response.sendRedirect("entrada?acao=ListaEmpresas");
}
}