Bom dia amigos do forum, estou estudando pela apostila fj21 e estou tendo problemas que nao consigo resolver no codigo abaixo:
Codigo JSP:
<%--
Document : lista_contatos_jstl
Created on : 29/03/2012, 16:50:48
Author : Sidney
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<jsp:useBean id="dao" class="br.com.caelum.dao.ContatoDAO" />
<c:out value="Primeiro exemplo JSTL" />//Esta saida e exibida
<table>
<c:forEach var="contato" items="${dao.lista}" varStatus="id">
<c:out value="Primeiro exemplo JSTL Dentro do for each" />
<tr bgcolor="${id.count % 2 == 0 ? 'aaee88' : 'ffffff'}">
<td>${id.count}</td><td>${contato.nome}</td>
<td>${contato.email}</td>
<td>${contato.endereco}</td>
<td>${contato.dataNascimento.time}</td>
</tr>
</c:forEach>
</table>
</body>
</html>
O metodo getLista da classe ContatoDAO:
public List <Contatos> getLista() {
try{
List<Contatos> contatos = new ArrayList<Contatos>();
//na linha abaixo se eu remover a conversão retorna esse erro: incompatible types required: com.mysql.jdbc.PreparedStatement found: java.sql.PreparedStatement
PreparedStatement pst = (PreparedStatement) this.connection.prepareStatement("select * from contatos where nome like 'R%' ");
ResultSet rs = pst.executeQuery();
while(rs.next()){
//cria o objeto Contato
Contatos contato = new Contatos();
contato.setNome(rs.getString("nome"));
contato.setEmail(rs.getString("email"));
contato.setEndereco(rs.getString("endereco"));
Calendar cal = Calendar.getInstance();
cal.setTime(rs.getDate("dataNascimento"));
contato.setDataNascimento(cal);
contatos.add(contato);
}
rs.close();
pst.close();
return contatos;
}catch(Exception e){
throw new RuntimeException(e);
}
}
Pelos testes que fiz a variavel contato, do for each, nao consegue encontrar os campos email, endereco, nome e dataNascimento, mas o codigo esta escrito da mesma forma que na apostila, com excecao da conversao que estou sendo obrigado a fazer no metodo getLista(), sera essa a causa do erro? Estou fazendo no NetBeans e no Eclipse e cada um me da um erro diferente. no NetBeans o codigo executa mas so exibe a mensagem de Primeiro Exemplo JSTL na pagina e no eclipse lanca a excecao abaixo:
04/04/2012 11:06:40 org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_26\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jdk1.6.0_26/bin/../jre/bin/client;C:/Program Files/Java/jdk1.6.0_26/bin/../jre/bin;C:/Program Files/Java/jdk1.6.0_26/bin/../jre/lib/i386;;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Program Files\Java\jdk1.6.0_26\bin;.C:\Program Files\Java\jre6\bin;C:\Program Files\eclipse 32 bits;;.
04/04/2012 11:06:40 org.apache.tomcat.util.digester.SetPropertiesRule begin
AVISO: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:fj21_Agenda' did not find a matching property.
04/04/2012 11:06:40 org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
04/04/2012 11:06:40 org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
04/04/2012 11:06:40 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1161 ms
04/04/2012 11:06:40 org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
04/04/2012 11:06:40 org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.20
04/04/2012 11:06:42 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
04/04/2012 11:06:42 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
04/04/2012 11:06:42 org.apache.catalina.startup.Catalina start
INFO: Server startup in 1517 ms
Conectando ao banco!
04/04/2012 11:07:08 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [jsp] in context with path [/fj21_Agenda] threw exception [org.apache.jasper.el.JspPropertyNotFoundException: /lista_contatos_jstl.jsp(15,12) '${dao.listacontato}' Property 'listacontato' not found on type br.com.caelum.DAO.ContatoDAO] with root cause
org.apache.jasper.el.JspPropertyNotFoundException: /lista_contatos_jstl.jsp(15,12) '${dao.listacontato}' Property 'listacontato' not found on type br.com.caelum.DAO.ContatoDAO
at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:109)
at org.apache.jsp.lista_005fcontatos_005fjstl_jsp._jspx_meth_c_005fforEach_005f0(lista_005fcontatos_005fjstl_jsp.java:145)
at org.apache.jsp.lista_005fcontatos_005fjstl_jsp._jspService(lista_005fcontatos_005fjstl_jsp.java:96)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:279)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Que pelo que entendi nao esta conseguindo encontrar a propriedade listacontato, que e o nome do metodo, estou usando o Tomcat 7, ja pesquisei aqui no forum e encontrei o topico do link abaixo:
Mas o mesmo nao resolveu para mim, se alguem puder me ajudar fico muito grato. Abraco.