javax.el.PropertyNotFoundException: Property 'XXX' not found on type bean.XXXXX

遇到的问题:

在使用Eclipse开发Java Web时,调用DAO和Java Bean出现了如下错误:

严重: Servlet.service() for servlet [com.servlet.queryServlet] in context with path [/20180502] threw exception [javax.el.PropertyNotFoundException: Property 'Note' not found on type bean.employee] with root cause
javax.el.PropertyNotFoundException: Property 'Note' not found on type bean.employee
	at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:269)
	at javax.el.BeanELResolver$BeanProperties.access$300(BeanELResolver.java:221)
	at javax.el.BeanELResolver.property(BeanELResolver.java:356)
	at javax.el.BeanELResolver.getValue(BeanELResolver.java:95)
	at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110)
	at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
	at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
	at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:943)
	at org.apache.jsp.JSP.Index_jsp._jspService(Index_jsp.java:193)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:716)
	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466)
	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391)
	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
	at com.servlet.queryServlet.doGet(queryServlet.java:43)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

javax.el.PropertyNotFoundException: Property 'XXX' not found on type bean.XXXXX_第1张图片javax.el.PropertyNotFoundException: Property 'XXX' not found on type bean.XXXXX_第2张图片

但是我的类中已经定义了geter和seter方法,如下:

javax.el.PropertyNotFoundException: Property 'XXX' not found on type bean.XXXXX_第3张图片

而Jsp中的调用代码是通过EL实现,也导入了相应的包。如下:

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="f"%>




首页


	
<% int count = 0; %>
员工姓名: 添加
序号 姓名 性别 手机号 职位 生日 备注 操作
<%=count++%> ${c.name } ${c.sex } ${c.mobile } ${c.jobTitle } ${c.birth } ${c.note } 删除

解决方案:(标红字体根据实际情况运用)

1.可能你遇到的错误是“Property 'xxx' not found on type java.lang.String”异常

它的意思是String类中没有xxx这个属性,而修改的方法就是:
list" var="c" >  
修改成:
${list}
" var="c" >

但是你需要注意它的错误是: java.lang.String对比type bean.Employee,其中对应src/bean.Employee.java文件。而且我在JSP中已经是${list}这种变量了,所以该方法不是该错误的解决方案。

 

2.有人说是bean的属性名称错误,或者没有getter,setter方法,但是我的bean如下方法。

又参考错误“javax.el.PropertyNotFoundException: Property 'Note' not found on type com.manager.Paper”,此时的解决方案是:
 

private int pNum;
private int pSize;

建议你将这两个属性的名称改为小写:
 

private int pnum;
private int psize;

据说是因为命名规范,同时stu.EmpNo估计是大小写错了,换成 ${stu.empNo} 就能成功,因为EL是读取属性的getter方法的,一般按照属性首字母小写来处理。但是我的名字的字段是id,因此该方法对我的情况也是行不通的。


3.如果上面两个方法你仍然报错,下面是我自己总结的方法:

严重: Servlet.service() for servlet [com.servlet.queryServlet] in context with path [/20180502] threw exception [javax.el.PropertyNotFoundException: Property 'Note' not found on type bean.employee] with root cause

javax.el.PropertyNotFoundException: Property 'Note' not found on type bean.employee

你需要做到的是:

(1).首先确保循环${list}" var="c">,然后调用是${c.name }、${c.sex }、、、${c.Note }(这个是我之前写错的地方,对照上文代码)
(2).然后属性命名最好是小写的,当然首字母一定要小写,如note;(很重要
(3).在数据库中create table student( stuid int,username varchar(20) )对应的Student类变量private Int id; private String name;其中类型需要一致,同时设置getter和setter方法;

 

经过上面的调试,这个问题应该就已经搞定了。欢迎转载。

javax.el.PropertyNotFoundException: Property 'XXX' not found on type bean.XXXXX_第4张图片

你可能感兴趣的:(Web学习笔录,Exception笔记,报错,el,JavaWeb,Property,'XXX',not,found,on,ty,数据库)