package br.com.alura.gerenciador.servlet;
import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date;
import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;
/**
Servlet implementation class NovaEmpresaServlet */ @WebServlet("/novaEmpresa") public class NovaEmpresaServlet extends HttpServlet { private static final long serialVersionUID = 1L;
/**
@throws IOException
@throws ServletException
@see HttpServlet#service(HttpServletRequest request, HttpServletResponse response) */ protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
System.out.println("Cadastrando nova empresa");
String nomeEmpresa = request.getParameter("nome"); String paramDataEmpresa = request.getParameter("data");
Date dataAbertura = null; try {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); dataAbertura = sdf.parse(paramDataEmpresa);
} catch (ParseException e) {
throw new ServletException(e);
}
Empresa empresa = new Empresa(); empresa.setNome(nomeEmpresa); empresa.setDataAbertura(dataAbertura);
Banco banco = new Banco(); banco.adiciona(empresa);
//chama o JSP RequestDispatcher rd = request.getRequestDispatcher("/listaEmpresas.jsp"); request.setAttribute("empresa", empresa.getNome()); rd.forward(request, response);
}
}
java.lang.NullPointerException java.text.SimpleDateFormat.parse(Unknown Source) java.text.DateFormat.parse(Unknown Source) br.com.alura.gerenciador.servlet.NovaEmpresaServlet.service(NovaEmpresaServlet.java:37) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Alguem pode me ajudar?