E ai pessoal tudo certo?
Seguinte, começando a pegar JSTL e EL, ai fiz uma aplicação bem básica de inserir e listar dados no banco. Inserir insere, mas na hora de listar, o tomcat me da esse erro aqui:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Exception in JSP: /Lista.jsp:14
11: <body>
12: <jsp:useBean id="dao" class="br.com.web.ComandoDAO" />
13: <table>
14: <c:forEach var="usuario" items="${dao.usuarios}">
15: <tr>
16: <td>${usuario.nome}</td>
17: <td>${usuario.email}</td>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
javax.servlet.ServletException: Unable to find a value for "usuarios" in object of class "br.com.web.ComandoDAO" using operator "."
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp.Lista_jsp._jspService(Lista_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
javax.servlet.jsp.el.ELException: Unable to find a value for "usuarios" in object of class "br.com.web.ComandoDAO" using operator "."
org.apache.commons.el.Logger.logError(Logger.java:481)
org.apache.commons.el.Logger.logError(Logger.java:498)
org.apache.commons.el.Logger.logError(Logger.java:611)
org.apache.commons.el.ArraySuffix.evaluate(ArraySuffix.java:340)
org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:263)
org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:190)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:924)
org.apache.jsp.Lista_jsp._jspx_meth_c_005fforEach_005f0(Lista_jsp.java:99)
org.apache.jsp.Lista_jsp._jspService(Lista_jsp.java:73)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.25 logs.
E o meu código é esse:
[code]
<%@ page isELIgnored=“false”%>
<%@ taglib uri=“http://java.sun.com/jsp/jstl/core” prefix=“c”%>
<%@ page language=“java” import=“br.com.web.*”
contentType=“text/html; charset=ISO-8859-1” pageEncoding=“ISO-8859-1”%>
${usuario.nome} | ${usuario.email} | ${usuario.idade} | ${usuario.endereco} |
E aqui a classe ComandoDAO:
package br.com.web;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class ComandoDAO {
private Connection con;
public ComandoDAO(){
con = new Conexao().getConnectionFactory();
}
public void insereDados(Usuarios user){
String sql = "INSERT INTO usuario (nome, email, idade, endereco) VALUES (?,?,?,?)";
try{
PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, user.getNome());
pst.setString(2,user.getEmail());
pst.setInt(3, user.getIdade());
pst.setString(4, user.getEndereco());
pst.execute();
}
catch(SQLException e){
}
}
public List<Usuarios> listaUsuarios(){
String sql = "SELECT * FROM usuario";
try{
PreparedStatement pstm = con.prepareStatement(sql);
ResultSet rs = pstm.executeQuery();
List<Usuarios> usuarios = new ArrayList<Usuarios>();
while(rs.next()){
Usuarios user = new Usuarios();
user.setNome(rs.getString("nome"));
user.setEmail(rs.getString("email"));
user.setIdade(rs.getInt("idade"));
user.setEndereco(rs.getString("endereco"));
usuarios.add(user);
}
rs.close();
pstm.close();
return usuarios;
}
catch(SQLException e){
throw new RuntimeException(e);
}
}
}
Alguma luz?