Ocorre o erro: java.lang.IllegalStateException: Cannot forward after response has been committed br.com.alura.gerenciador.web.FazTudo.service(FazTudo.java:30) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) br.com.alura.gerenciador.web.FiltroDeAuditoria.doFilter(FiltroDeAuditoria.java:43)
O código está assim:
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { super.service(req, resp); String tarefa = req.getParameter("tarefa"); if(tarefa == null) throw new IllegalArgumentException("Voce esqueceu de passar a tarefa"); try { String nomeDaClasse = "br.com.alura.gerenciador.web." + tarefa; Class tipo = Class.forName(nomeDaClasse); Tarefa instancia = (Tarefa) tipo.newInstance(); String pagina = instancia.executa(req,resp); RequestDispatcher dispatcher = req.getRequestDispatcher(pagina); dispatcher.forward(req, resp); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new ServletException(e); } }