Estou tendo um erro 500 quando o servlet FazTudo, quando o programa eecuta a linha Class<?> tipo = Class.forName(tarefa); ele me retornajavax.servlet.ServletException.
Servlet FazTudo:
package br.com.alura.gerenciador.web;
import java.io.IOException;
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;
/**
*
* @author T-800
*/
@WebServlet(name = "FazTudo", urlPatterns = {"/FazTudo"})
public class FazTudo extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String tarefa = req.getParameter("tarefa");
if(tarefa==null) {
throw new IllegalArgumentException("Não há tarefa a ser processada");
}
try {
System.out.println("inicio try");
tarefa = "br.com.alura.gerent.web." + tarefa;
System.out.println(tarefa);
System.out.println("pegando tipo da tarefa");
Class<?> tipo = Class.forName(tarefa);
System.out.println("instanciando tarefa");
Tarefa instancia = (Tarefa) tipo.newInstance();
System.out.println("pegando uri e salvando em string");
String pagina = instancia.executa(req, resp);
System.out.println("fazendo request dispatcher");
RequestDispatcher dispatcher = req.getRequestDispatcher(pagina);
System.out.println("dispatcher foward");
dispatcher.forward(req, resp);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | ServletException | IOException classNotFoundException) {
throw new ServletException();
}
}
}
classe BuscaEmpresa:
package br.com.alura.gerenciador.web;
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import br.com.alura.gerenciador.model.Empresa;
import br.com.alura.gerenciador.dao.EmpresaDAO;
public class BuscaEmpresa implements Tarefa{
public BuscaEmpresa(){
System.out.println("Construindo uma servlet do tipo Busca Empresa");
}
@Override
public String executa(HttpServletRequest req, HttpServletResponse resp) {
String filtro = req.getParameter("filtro");
Collection<Empresa> empresas = new EmpresaDAO().buscaPorSimilaridade(filtro);
req.setAttribute("empresas",empresas);
return "/WEB-INF/pagina/buscaEmpresa.jsp";
}
}
interface Tarefa:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package br.com.alura.gerenciador.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author T-800
*/
public interface Tarefa {
String executa(HttpServletRequest req, HttpServletResponse resp);
}
erro no navegador:
HTTP Status 500 - Internal Server Error
type Exception report
messageInternal Server Error
descriptionThe server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException
note The full stack traces of the exception and its root causes are available in the Payara Server 4.1.2.174 #badassfish logs.
Payara Server 4.1.2.174 #badassfish