java - javax.el.PropertyNotFoundException: -
this question has answer here:
i´m learning jsp, servlets , so. got exception cant find out error. kinda know el cant find field of error javabean seens fine.the list passed jsp page seens ok. changed jsp , servlet alot , exception keeps going.
hope some1 can give me hand.
heres code , stacktrace:
stacktrace:
severe: servlet.service() servlet jsp threw exception javax.el.propertynotfoundexception: property 'nome' not found on type java.lang.string @ javax.el.beanelresolver$beanproperties.get(beanelresolver.java:268) @ javax.el.beanelresolver$beanproperties.access$300(beanelresolver.java:221) @ javax.el.beanelresolver.property(beanelresolver.java:355) @ javax.el.beanelresolver.getvalue(beanelresolver.java:95) @ org.apache.jasper.el.jasperelresolver.getvalue(jasperelresolver.java:110) @ org.apache.el.parser.astvalue.getvalue(astvalue.java:169) @ org.apache.el.valueexpressionimpl.getvalue(valueexpressionimpl.java:184) @ org.apache.jasper.runtime.pagecontextimpl.proprietaryevaluate(pagecontextimpl.java:943) @ org.apache.jsp.admin.buscar_jsp._jspx_meth_c_005fforeach_005f0(buscar_jsp.java:253) @ org.apache.jsp.admin.buscar_jsp._jspx_meth_c_005fif_005f0(buscar_jsp.java:215) @ org.apache.jsp.admin.buscar_jsp._jspservice(buscar_jsp.java:162) @ org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70) @ javax.servlet.http.httpservlet.service(httpservlet.java:729) @ org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:438) @ org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:396) @ org.apache.jasper.servlet.jspservlet.service(jspservlet.java:340) @ javax.servlet.http.httpservlet.service(httpservlet.java:729) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:291) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.applicationdispatcher.invoke(applicationdispatcher.java:719) @ org.apache.catalina.core.applicationdispatcher.processrequest(applicationdispatcher.java:465) @ org.apache.catalina.core.applicationdispatcher.doforward(applicationdispatcher.java:390) @ org.apache.catalina.core.applicationdispatcher.forward(applicationdispatcher.java:317) @ control.controleproduto.buscar(controleproduto.java:140) @ control.controleproduto.execute(controleproduto.java:65) @ control.controleproduto.dopost(controleproduto.java:46) @ javax.servlet.http.httpservlet.service(httpservlet.java:648) @ javax.servlet.http.httpservlet.service(httpservlet.java:729) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:291) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:212) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:106) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:502) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:141) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:79) @ org.apache.catalina.valves.abstractaccesslogvalve.invoke(abstractaccesslogvalve.java:616) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:88) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:521) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1096) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:674) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun(nioendpoint.java:1500) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.run(nioendpoint.java:1456) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(thread.java:745) excessa no buscar exception occurred processing jsp page /admin/buscar.jsp @ line 33 30: </tr> 31: <c:foreach items="lista" var="prod"> 32: <tr> 33: <td>${prod.nome }</td> 34: <td>${prod.estoque }</td> 35: <td><fmt:formatnumber value="${prod.preco}" type="currency"/> </td> 36: <td> <fmt:formatdate value="${prod.validade}" pattern="dd/mm/yyyy" /> </td> stacktrace: org.apache.jasper.jasperexception: exception occurred processing jsp page /admin/buscar.jsp @ line 33 30: </tr> 31: <c:foreach items="lista" var="prod"> 32: <tr> 33: <td>${prod.nome }</td> 34: <td>${prod.estoque }</td> 35: <td><fmt:formatnumber value="${prod.preco}" type="currency"/> </td> 36: <td> <fmt:formatdate value="${prod.validade}" pattern="dd/mm/yyyy" /> </td> stacktrace: @ org.apache.jasper.servlet.jspservletwrapper.handlejspexception(jspservletwrapper.java:574) @ org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:476) @ org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:396) @ org.apache.jasper.servlet.jspservlet.service(jspservlet.java:340) @ javax.servlet.http.httpservlet.service(httpservlet.java:729) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:291) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.applicationdispatcher.invoke(applicationdispatcher.java:719) @ org.apache.catalina.core.applicationdispatcher.processrequest(applicationdispatcher.java:465) @ org.apache.catalina.core.applicationdispatcher.doforward(applicationdispatcher.java:390) @ org.apache.catalina.core.applicationdispatcher.forward(applicationdispatcher.java:317) @ control.controleproduto.buscar(controleproduto.java:140) @ control.controleproduto.execute(controleproduto.java:65) @ control.controleproduto.dopost(controleproduto.java:46) @ javax.servlet.http.httpservlet.service(httpservlet.java:648) @ javax.servlet.http.httpservlet.service(httpservlet.java:729) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:291) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:212) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:106) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:502) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:141) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:79) @ org.apache.catalina.valves.abstractaccesslogvalve.invoke(abstractaccesslogvalve.java:616) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:88) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:521) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1096) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:674) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun(nioendpoint.java:1500) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.run(nioendpoint.java:1456) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(thread.java:745) caused by: javax.el.propertynotfoundexception: property 'nome' not found on type java.lang.string @ javax.el.beanelresolver$beanproperties.get(beanelresolver.java:268) @ javax.el.beanelresolver$beanproperties.access$300(beanelresolver.java:221) @ javax.el.beanelresolver.property(beanelresolver.java:355) @ javax.el.beanelresolver.getvalue(beanelresolver.java:95) @ org.apache.jasper.el.jasperelresolver.getvalue(jasperelresolver.java:110) @ org.apache.el.parser.astvalue.getvalue(astvalue.java:169) @ org.apache.el.valueexpressionimpl.getvalue(valueexpressionimpl.java:184) @ org.apache.jasper.runtime.pagecontextimpl.proprietaryevaluate(pagecontextimpl.java:943) @ org.apache.jsp.admin.buscar_jsp._jspx_meth_c_005fforeach_005f0(buscar_jsp.java:253) @ org.apache.jsp.admin.buscar_jsp._jspx_meth_c_005fif_005f0(buscar_jsp.java:215) @ org.apache.jsp.admin.buscar_jsp._jspservice(buscar_jsp.java:162) @ org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70) @ javax.servlet.http.httpservlet.service(httpservlet.java:729) @ org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:438) ... 38 more
heres bean:
package entity; import java.util.date; import java.util.gregoriancalendar; public class produto { private integer idproduto; private string nome; private integer estoque; private double preco; private date validade; /* * produto tem uma categoria */ private categoria categoria; public produto(integer idproduto, string nome, integer estoque, double preco, date validade) { super(); this.idproduto = idproduto; this.nome = nome; this.estoque = estoque; this.preco = preco; this.validade = validade; } public produto() { super(); } public categoria getcategoria() { return categoria; } public void setcategoria(categoria categoria) { this.categoria = categoria; } public integer getidproduto() { return idproduto; } public void setidproduto(integer idproduto) { this.idproduto = idproduto; } public string getnome() { return nome; } public void setnome(string nome) { this.nome = nome; } public integer getestoque() { return estoque; } public void setestoque(integer estoque) { this.estoque = estoque; } public double getpreco() { return preco; } public void setpreco(double preco) { this.preco = preco; } public date getvalidade() { return validade; } public void setvalidade(date validade) { this.validade = validade; } public static date converterdata(string data){ string[] novadata = data.split("/"); gregoriancalendar cal = new gregoriancalendar( new integer(novadata[2]), new integer(novadata[1]) - 1, new integer(novadata[0])); return cal.gettime(); } @override public string tostring() { return "produto [idproduto=" + idproduto + ", nome=" + nome + ", estoque=" + estoque + ", preco=" + preco + ", validade=" + validade + "]"; } }
jsp pages:
topo.jsp
<%@ page language="java" contenttype="text/html; charset=iso-8859-1" pageencoding="iso-8859-1"%> <!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>sistema de controle de produtos</title> <!-- css styles --> <link rel="stylesheet" type="text/css" href="${pagecontext.request.contextpath}/bootstrap/css/bootstrap.min.css"> <!-- tabela com cores diferentes --> <link rel="stylesheet" type="text/css" href="${pagecontext.request.contextpath}/css/tabelacomcores.css"> </head> <body> <!-- como criar submenus? --> <div class="container" > <div class="col-xs-12"> <ul class="nav nav-pills"> <li><a href="index.jsp">cadastrar</a></li> <li><a href="buscar.jsp">consultar</a></li> <li><a href="#">sair</a> </ul> </div> <!-- menu -->
rodape.jsp
</div> </div> <!-- container --> </body> </html>
buscar.jsp
<jsp:include page="topo.jsp"></jsp:include> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> <!-- format library --> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <h3 class="page-header">buscar produtos</h3> <form method="post" action="buscar.html"> <div class="form-group"> nome : <input type="text" name="nome" value="${nome}" class="form-control"> </div> <input type="submit" value="buscar" class="btn btn-primary"> </form> ${msg } <c:if test="${fn:length(lista)>0}"> <table class="table table-bordered"> <tr> <th>nome</th> <th>estoque</th> <th>preco</th> <th>validade</th> <th>categoria</th> <th></th> </tr> <c:foreach items="lista" var="prod"> <tr> <td>${prod.nome }</td> <td>${prod.estoque }</td> <td><fmt:formatnumber value="${prod.preco}" type="currency"/> </td> <td> <fmt:formatdate value="${prod.validade}" pattern="dd/mm/yyyy" /> </td> <td>${prod.categoria.nomecategoria }</td> <td> <a href="editar.html?id=${prod.idproduto}" class="btn btn-warning">editar</a> <a href="excluir.html?id=${prod.idproduto}" class="btn btn-danger" onclick="return confirm('deseja excluir realmente o produto?')">excluir</a> </td> </tr> </c:foreach> </table> </c:if> <jsp:include page="rodape.jsp"></jsp:include>
dao.java
package persistence; import java.sql.connection; import java.sql.drivermanager; import java.sql.preparedstatement; import java.sql.resultset; public class dao { connection con; preparedstatement stmt; resultset rs; private final string url = "jdbc:mysql://localhost:3306/aula"; private final string user = "root"; private final string pass = "something"; protected void open()throws exception{ class.forname("com.mysql.jdbc.driver"); con = drivermanager.getconnection(url, user, pass); } protected void close()throws exception{ if(rs != null) rs.close(); if(stmt != null) stmt.close(); if(con != null) con.close(); } }
produtodao.java
package persistence; import java.text.simpledateformat; import java.util.arraylist; import java.util.list; import entity.categoria; import entity.produto; public class produtodao extends dao { public void cadastrar(produto prod)throws exception{ open(); stmt = con.preparestatement("insert produto (nome,estoque,preco,validade,idcategoria)" + " values(?,?,?,?,?)"); stmt.setstring(1, prod.getnome()); stmt.setint(2, prod.getestoque()); stmt.setdouble(3, prod.getpreco()); simpledateformat sdf = new simpledateformat("yyyy-mm-dd"); stmt.setstring(4, sdf.format(prod.getvalidade())); stmt.setint(5, prod.getcategoria().getidcategoria()); stmt.execute(); close(); } public list<produto> buscar(string nome)throws exception{ open(); stmt = con.preparestatement("select * produto inner join categoria " + " on produto.idcategoria = categoria.idcategoria nome ?"); stmt.setstring(1, nome + "%"); rs = stmt.executequery(); list<produto> lista = new arraylist<produto>(); while(rs.next()){ produto prod = new produto(rs.getint("idproduto"), rs.getstring("nome"), rs.getint("estoque"), rs.getdouble("preco"), rs.getdate("validade")); categoria cat = new categoria(rs.getint("idcategoria"), rs.getstring("nomecategoria")); prod.setcategoria(cat); lista.add(prod); } close(); return lista; } /** * busca pela id produto * @param id * @return * @throws exception */ public produto buscar(int id) throws exception{ open(); stmt = con.preparestatement("select * produto inner join categoria " + " on idcategoria = idcategoria idproduto = ?"); stmt.setint(1, id); produto prod = null; rs = stmt.executequery(); if(rs.next()){ prod = new produto(rs.getint("idproduto"), rs.getstring("nome"), rs.getint("estoque"), rs.getdouble("preco"), rs.getdate("validade")); categoria cat = new categoria(rs.getint("idcategoria"), rs.getstring("nomecategoria")); prod.setcategoria(cat); } close(); return prod; } public void excluir(int id)throws exception{ open(); stmt = con.preparestatement("delete produto idproduto = ?"); stmt.setint(1, id); stmt.execute(); close(); } public void editar(produto prod)throws exception{ open(); stmt = con.preparestatement("update produto set nome = ?, estoque = ?, preco = ?, " + " validade = ?, categoria_idcategoria = ? idproduto = ?"); stmt.setstring(1, prod.getnome()); stmt.setint(2, prod.getestoque()); stmt.setdouble(3, prod.getpreco()); simpledateformat sdf = new simpledateformat("yyyy-mm-dd"); stmt.setstring(4, sdf.format(prod.getvalidade())); stmt.setint(5, prod.getcategoria().getidcategoria()); stmt.setint(6, prod.getidproduto()); stmt.execute(); close(); } }
sorry, find out.
the c:foreach items= must parameter "${lista}" , not "lista".
solved. anyway.
Comments
Post a Comment