Ao rodar o programa proposto pela aula obtive um problema.
Código do servlet
package br.com.alura.gerenciador.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import br.com.alura.gerenciador.acao.ListaEmpresas;
@WebServlet("/entrada")
public class UnicaEmpresaServlet2 extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String ParameterAcao = request.getParameter("acao");
if (ParameterAcao.equals("ListaEmpresas")) {
System.out.println("Lista Empresas");
ListaEmpresas listaEmpresas = new ListaEmpresas();
ERRO -> listaEmpresas.executa(request, response); <-ERRO
} else if (ParameterAcao.equals("MostraEmpresa")) {
System.out.println("Mostra Empresa");
} else if (ParameterAcao.equals("RemoveEmpresa")) {
System.out.println("Remove Empresa");
}
}
}
Código da classe
package br.com.alura.gerenciador.acao;
import java.io.IOException;
import java.util.List;
import javax.servlet.RequestDispatcher;
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 ListaEmpresas {
public void executa(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Banco banco = new Banco();
List<Empresa> lista = banco.getEmpresas();
request.setAttribute("empresas", lista);
RequestDispatcher rd = request.getRequestDispatcher("/listaEmpresas.jsp");
rd.forward(request, response);
}
}
StackTrace:
java.lang.Error: Unresolved compilation problem:
Syntax error on token(s), misplaced construct(s)
at br.com.alura.gerenciador.servlet.UnicaEmpresaServlet2.service(UnicaEmpresaServlet2.java:25)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1579)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Unknown Source)
Eu indiquei onde supostamente esta o erro, mas nao consigo resolver. Assim que eu acesso a página (url correto) ele me joga essa exceção.