JSP:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page import="java.util.list,br.com.alura.gerenciador.servlet.Empresa"%>
Classe das listas:
package br.com.alura.gerenciador.servlet;
/**
Servlet implementation class ListaEmpresasServlet */ @WebServlet("/listaEmpresas") public class ListaEmpresasServlet extends HttpServlet { private static final long serialVersionUID = 1L;
protected void doGet(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);
}
}
E o erro que dá:
Type Exception Report
Message Unable to compile class for JSP:
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
An error occurred at line: [13] in the jsp file: [/listaEmpresas.jsp] List cannot be resolved to a type 10:
11:- 12: <% 13: List lista = (List)request.getAttribute("empresas"); 14: for (Empresa empresa : lista) { 15: %> 16:
- <%=empresa.getNome()%>
Stacktrace: org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:213) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:541) org.apache.jasper.compiler.Compiler.compile(Compiler.java:392) org.apache.jasper.compiler.Compiler.compile(Compiler.java:362) org.apache.jasper.compiler.Compiler.compile(Compiler.java:346) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:605) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:400) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) br.com.alura.gerenciador.servlet.ListaEmpresasServlet.doGet(ListaEmpresasServlet.java:28) javax.servlet.http.HttpServlet.service(HttpServlet.java:634) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) Note The full stack trace of the root cause is available in the server logs.