<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
</html>
<-- cria a lista -->
<jsp:useBean id="dao" class="br.com.mgf.oracle.OracleDao"/>
<-- faz o forEach -->
<c:forEach var="contato" items="${dao.lista}">
<li>
nome: ${contato.nome},
endereco ${contato.endereco},
email ${contato.email}
</li>
</c:forEach>
package br.com.mgf.oracle;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import br.com.mgf.modelo.Contato;
public class OracleDao {
private Connection conexao;
public OracleDao() throws SQLException {
this.conexao = OracleFactury.getConnection();
}
public void adciona(Contato con) throws SQLException {
PreparedStatement smtm = this.conexao.prepareStatement("insert into contatos(nome, endereco, email, id) values(?,?,?,?)");
smtm.setString(1,con.getNome());
smtm.setString(2, con.getEndereco());
smtm.setString(3, con.getEmail());
smtm.setInt(4, con.getId());
smtm.execute();
smtm.close();
}
public void consulta() throws SQLException {
PreparedStatement smtm = this.conexao.prepareStatement("select * from contatos");
ResultSet rs = smtm.executeQuery();
while(rs.next()) {
System.out.println("O Nome é : " + rs.getString("nome"));
System.out.println("O Endereco é : " + rs.getString("endereco"));
System.out.println("O Email é : " + rs.getString("email"));
System.out.println("O Id é : " + rs.getInt("id"));
}
rs.close();
smtm.close();
}
public void excluir(Contato contato) throws SQLException {
PreparedStatement smtm = this.conexao.prepareStatement("delete from contatos where id = " + contato.getId());
smtm.execute();
smtm.close();
}
public List<Contato> getList() throws SQLException {
PreparedStatement smtm = this.conexao.prepareStatement("select * from contatos");
ResultSet rs = smtm.executeQuery();
List<Contato> contatos = new ArrayList<Contato>();
while(rs.next()) {
Contato conta = new Contato();
conta.setEmail(rs.getString("email"));
conta.setEndereco(rs.getString("endereco"));
conta.setId(rs.getInt("id"));
conta.setNome(rs.getString("nome"));
contatos.add(conta);
}
rs.close();
smtm.close();
return contatos;
}
}
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Unable to find a value for "lista" in object of class "br.com.mgf.oracle.OracleDao" using operator "."
Como eu resolvo isso...Obrigado...