Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Acao acao = (Acao) classe.newInstance(); Erro 500 nesta linha. Mim ajude a sanar este erro

insira se
@WebServlet("/entrada")
public class UnicaEntradaServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        String paramAcao = request.getParameter("acao");

        String nomeDaClasse = "br.com.alura.gerenciador.acao." + paramAcao;

        String nome;
        try {
            Class classe = Class.forName(nomeDaClasse);//carrega a classe com o nome
            Acao acao = (Acao)  classe.newInstance();
             nome = acao.executa(request, response);
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | ServletException
                | IOException e) {
             throw new ServletException(e);
        }

        String[]tipoEEndereco = nome.split(":");
        if(tipoEEndereco[0].equals("forward")) {
           RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/view/" +tipoEEndereco[1]);

             rd.forward(request, response);
        }else {
             response.sendRedirect(tipoEEndereco[1]);

        }u código aqui

at br.com.gerenciador.servelet.UnicaEntradaServlet.service(UnicaEntradaServlet.java:34)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
2 respostas
solução!

Oi Adilson

Vi que você postou um prequeno trecho do erro, poderia mandar a stack completa do erro, por favor?

Type Exception Report

Message java.lang.ClassNotFoundException: br.com.alura.gerenciador.acao.ListaEmpresas

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

javax.servlet.ServletException: java.lang.ClassNotFoundException: br.com.alura.gerenciador.acao.ListaEmpresas br.com.gerenciador.servelet.UnicaEntradaServlet.service(UnicaEntradaServlet.java:32) javax.servlet.http.HttpServlet.service(HttpServlet.java:733) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) Root Cause

java.lang.ClassNotFoundException: br.com.alura.gerenciador.acao.ListaEmpresas org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365) org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188) java.base/java.lang.Class.forName0(Native Method) java.base/java.lang.Class.forName(Class.java:291) br.com.gerenciador.servelet.UnicaEntradaServlet.service(UnicaEntradaServlet.java:27) javax.servlet.http.HttpServlet.service(HttpServlet.java:733) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) Note A pilha de erros completa da causa principal está disponível nos logs do servidor.

Erro no console INFORMAÇÕES: Server startup in [16842] milliseconds jul 24, 2020 7:32:14 PM org.apache.catalina.core.StandardWrapperValve invoke GRAVE: Servlet.service() for servlet [br.com.gerenciador.servelet.UnicaEntradaServlet] in context with path [/gerenciador] threw exception [java.lang.ClassNotFoundException: br.com.alura.gerenciador.acao.ListaEmpresas] with root cause java.lang.ClassNotFoundException: br.com.alura.gerenciador.acao.ListaEmpresas at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188) at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Class.java:291) at br.com.gerenciador.servelet.UnicaEntradaServlet.service(UnicaEntradaServlet.java:27) at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) 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:541) 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:690) 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:373) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1589) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.base/java.lang.Thread.run(Thread.java:844)