1. 程式人生 > >javax.el.PropertyNotFoundException: Property 'XXX' not found on type bean.XXXXX

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)

但是我的類中已經定義了geter和seter方法,如下:

而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"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>首頁</title>
</head>
<body>
	<center>
		<form action="queryServlet">
			<table style="border-collapse: collapse; margin-top: 60px;"
				cellpadding="5px;" bordercolor="blue;" border="1px;" width="600px;">
				<tr height="35px;" align="center">
					<td colspan="6">員工姓名:<input type="text"
						style="padding: 5px; border-color: blue;" name="query" /><input
						type="submit" value="搜尋" style="margin-left: -10px; padding: 5px;" /></td>
					<td colspan="2"><a href="#"><font>新增</font> </a></td>
				</tr>
				<tr height="35px;" valign="middle" align="center">
					<td>序號</td>
					<td>姓名</td>
					<td>性別</td>
					<td>手機號</td>
					<td>職位</td>
					<td>生日</td>
					<td>備註</td>
					<td>操作</td>
				</tr>
				<%
					int count = 0;
				%>
				<f:forEach items="${list }" var="c">
					<tr height="35px;" valign="middle">
						<td><%=count++%></td>
						<td>${c.name }</td>
						<td>${c.sex }</td>
						<td>${c.mobile }</td>
						<td>${c.jobTitle }</td>
						<td>${c.birth }</td>
						<td>${c.note }</td>
						<td><a href="#"><font>刪除</font></a></td>
					</tr>
				</f:forEach>
			</table>
		</form>
	</center>
</body>
</html>

解決方案:(標紅字型根據實際情況運用)

1.可能你遇到的錯誤是“Property 'xxx' not found on type java.lang.String”異常

它的意思是String類中沒有xxx這個屬性,而修改的方法就是:
<c:forEach items="list" var="c" >  
修改成:
<c:forEach items="
${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).首先確保迴圈<c:forEach items="${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

遇到的問題: 在使用Eclipse開發Java Web時,呼叫DAO和Java Bean出現瞭如下錯誤: 嚴重: Servlet.service() for servlet [com.servlet.queryServlet] in context with path [

【java學習筆記】踩坑記錄,異常:javax.el.PropertyNotFoundException: Property [XXX] not found on type [XXX.XXX.XXX.XXX]

練習JavaWeb專案時,報錯javax.el.PropertyNotFoundException,原因是EL表示式裡面的屬性和pojo裡面的屬性名字沒有對上,範了個低階錯誤。 jsp中: <li>歡迎您,${loginUser.username}!</li> pojo

對與幾種javax.el.PropertyNotFoundException: Property 'XXX' not found on type java.lang.String問題原因

我最近在做一個專案時,點選連結tomcat報錯 “javax.el.PropertyNotFoundException: Property 'XXX' not found on type java.lang.String” 這樣的錯誤,然後我百度上去搜了一下,發現原因五花八

javax.el.PropertyNotFoundException: Property 'phone' not found on type xxx.xxx.domain

報錯資訊如上! 原因:我的Student類裡面定義的變數與JSP中EL裡面的屬性名稱不一致。 詳情:我把Student類中定義的變數改成與JSP中的屬性一致了,但還是會報這個錯誤。排除一切可能的錯誤後還是報錯。沒辦法,這時候就要看編譯器是不是出問題了,然後重啟了Ecl

javax.el.PropertyNotFoundException: Property 'name' not found on type java.lang.String 錯誤解決辦法

 javax.el.PropertyNotFoundException: Property 'name' not found on type java.lang.String javax.el.BeanELResolver$BeanProperties.get(Bean

使用jstl標籤遍歷資料時,報javax.el.PropertyNotFoundException: Property [id] not found on type [java.lang.String

後臺報錯資訊: javax.el.PropertyNotFoundException: Property [id] not found on type [java.lang.String]     at javax.el.BeanELResolver$Bean

javax.el.PropertyNotFoundException: Property 'XXX' not readable

使用spring框架,自己組裝了一個資訊搭載類扔到JSP中渲染,大致是這樣: UserBasicInfo userInfo = new UserBasicInfo(user); 以及 <img id="user_avatar" src="${

JSTL表示式錯誤PropertyNotFoundException: Property 'title' not found on type java.lang.String

低階錯誤!!! 異常: PropertyNotFoundException: Property 'title' not found on type java.lang.String 解釋:屬性找不到異常:屬性title找不到 查詢資料庫正常,出現錯誤原因是jstl表示式書

Property 'date' not found on type java.lang.String] with root cause解決方案

今晚的開發極其不順利,一個小小的bebug都找了一個多小時. 如果你也報這個錯,先看下el表達示是不是一個物件,如果是字串,這樣才會後面用EL取值的時候not found on type java.lang.String了 如果是一個物件那麼請再看下面的 二月 26, 2

EL表示式:Property 'id' not readable on type int

錯誤資訊:Property ‘id’ not readable on type int,如下圖: 前面為了偷懶,User實體類直接寫在了Controller裡, 所以User沒有Publi

異常:Property 'name' not found on type java.lang.String,attribute items does not accept any

最近在練習jstl與el綜合實訓時遇到兩個問題,雖然沒有什麼技術性但是很有必要給大家提個醒,在開發過程可能會因為某個非技術性問題讓我們百思不得其解,其實問題很簡單,看你細不細心了,否則死都不知怎麼死得啊。 第一問題百度了很久才發現原來指令標籤寫錯了 org.apache.

javax.el.PropertyNotFoundException: Property 'id' not found on type java.lang.Integer

nim osi ren worker lan servlet encoding site filter javax.el.PropertyNotFoundException: Property ‘id‘ not found on type java.lang.Integer

HTTP Status 500 - javax.el.PropertyNotFoundException: Property 'lkmId' not found on type cn.itcast.entity.LinkMan

報錯 type Exception report message javax.el.PropertyNotFoundException: Property 'lkmId' not found on type cn.itcast.entity.LinkMan description

關於EL表示式的原理以及提示Property 'xx' not found on 原因

EL表示式獲取物件屬性的原理是這樣的:以表示式${user.name}為例EL表示式會根據name去User類裡尋找這個name的get方法,此時會自動把name首字母大寫並加上get字首,一旦找到與之匹配的方法,El表示式就會認為這就是要訪問的屬性,並返回屬性的值。

spring,property not found on type

urn jsp logs ret tint oid pro blog nbsp 剛開始學spring mvc ,遇到這個報錯。 jsp頁面 user 實體類 public class User { private String name; private

Property 'id' not found on type java.lang.String

idt not height string .com com found body lan 改為 忘寫了$符,取不出來,因此報錯! Property 'id' not found on type java.lang.String

[IDE - Eclipse] JSP報錯:The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path

引入 ips eclips size eclipse -i let details javax 是因為Eclipse的Web項目不自動引入相關jar包. Right Click on the Project ? Properties ? Project Facets. Yo

The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

①.     1.右鍵點選專案->build path->configure build path->add library->server runtime->apache tomcat 無果,無法新增。 ②.   1.開啟Eclipse

專案出現 The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path 解決方法

The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path ①專案右擊–>build path -->新增libraries–>s

JSP頁面提示 The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

解決步驟: 1:開啟專案屬性頁面 2:點選Java BuildPath 3:點開 Libraries選項卡 4:點選Add Library 5:選中 Server Runtime 6:選擇