[java] javax.el.PropertyNotFoundException: Property 'id' not found on type bean.Student
問題提出:
在使用MyEclipse開發Java Web時,呼叫DAO和Java Bean出現瞭如下錯誤:
嚴重: Servlet.service() for servlet [jsp] in context with path [/JDBCbyDao] threw exception [An exception occurred processing JSP page /student.jsp at line 37
34:
35: <c:forEach items="${ studentList }" var="student">
36: <tr bgcolor="#FFFFFF">
37: <td><input type="checkbox" name="id" value="${ student.id }" /></td>
38: <td>${ student.id }</td>
39: <td>${ student.name }</td>
40: <td>${ student.password }</td>
Stacktrace:] with root cause
javax.el.PropertyNotFoundException: Property 'id' not found on type bean.Student
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:290)
at javax.el.BeanELResolver$BeanProperties.access$300(BeanELResolver.java:243)
其中我的類中已經定義了屬性和get/set方法,如下:
解決方案:
1.可能你遇到的錯誤是“Property 'id' not found on type java.lang.String”異常
它的意思是String類中沒有id這個屬性,而修改的方法就是:
<c:forEach items="videos" var="video" >
修改成:
<c:forEach items="${videos}" var="video" >
但是你需要注意它的錯誤是: java.lang.String對比type bean.Student,其中對應src/bean.Student.java檔案。而且我在JSP中已經是${studentList}這種變數了,所以該方法不是該錯誤的解決方案。
2.有人說是bean的屬性名稱錯誤,或者沒有get,set方法,但是我的bean如下方法。又參考錯誤“javax.el.PropertyNotFoundException: Property 'pNum' 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 [jsp] in context with path
javax.el.PropertyNotFoundException: Property 'id' not found on type bean.Student
你需要做到的是:
//刪除操作
public static int delete(Integer id) throws Exception {
String sql = "DELETE FROM student WHEREstuid = ? ";
return JDBCConnect.executeUpdate(sql, id);
}
//查詢操作
student.setId(rs.getInt("stuid"));
student.setName(rs.getString("username"));
(5).如果上面的資料庫、Java類變數型別都是一致的,使用方法都正確仍然存在該錯誤,那可能就是下面的錯誤:
當我定義函式public Integer getID() { return id; }時就會報錯
另一種猜測:在jstl的el表示式引用錯誤應該使用${info.type.id } 而不是${info.id }(未驗證)
參考資料:
1.JSP not finding property in bean - stackoverflow 丟失set方法
2.javax.el.PropertyNotFoundException: Property 'answer' not - stackoverflow
3.異常:javax.el.PropertyNotFoundException: Property 'id' not found on - CSDN
4.javax.el.PropertyNotFoundException: Property 'Owner' not found on - 百度知道
5.JSP沒有使<c:forEach items="${specialty}" var="spe"> - CSDN論壇
該錯誤報告和線上筆記希望對你有所幫助~
(By:Eastmount 2015-5-19 凌晨4點 http://blog.csdn.net/eastmount/)
在使用MyEclipse開發Java Web時,呼叫DAO和Java Bean出現瞭如下錯誤:
嚴重: Servlet.service() for servlet [jsp] in context with path [/JDBCbyDao] threw exception [An exception occurred processing JSP page /student.jsp at line 37
34:
35: <c:forEach items="${ studentList }" var="student">
36: <tr bgcolor="#FFFFFF">
37: <td><input type="checkbox" name="id" value="${ student.id }" /></td>
38: <td>${ student.id }</td>
39: <td>${ student.name }</td>
40: <td>${ student.password }</td>
Stacktrace:] with root cause
javax.el.PropertyNotFoundException: Property 'id' not found on type bean.Student
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:290)
at javax.el.BeanELResolver$BeanProperties.access$300(BeanELResolver.java:243)
其中我的類中已經定義了屬性和get/set方法,如下:
package bean;
public class Student {
private Integer id; //學號
private String name; //姓名
private String password; //密碼
public Integer getID() { return id; }
public String getName() { return name; }
public String getPassword() { return password; }
public void setID(Integer id) { this.id = id; }
public void setName(String name) { this.name = name; }
public void setPassword(String pwd) { this.password = pwd; }
}
而Jsp中的呼叫程式碼是通過EL實現,也匯入了相應的包。如下:<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<jsp:directive.page import="DAO.StudentDAO"/>
<jsp:directive.page import="java.util.List"/>
<%
List studentList = StudentDAO.listStudents();
request.setAttribute("studentList", studentList);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'student.jsp' starting page</title>
</head>
<body>
<form action="operateStudent.jsp" method=get>
<table bgcolor="#CCCCCC" cellspacing=1 cellpadding=5 width=100%>
<tr bgcolor=#DDDDDD>
<th>選擇</th>
<th>學號</th>
<th>姓名</th>
<th>密碼</th>
<th>操作</th>
</tr>
<c:forEach items="${studentList}" var="stu">
<tr bgcolor="#FFFFFF">
<td><input type="checkbox" name="id" value="${stu.id}" /></td>
<td>${stu.id}</td>
<td>${stu.name}</td>
<td>${stu.password}</td>
<td>
<a href="addEmployee.jsp?action=edit&id=${stu.id}">修改</a>
<a href="addEmployee.jsp?action=del&id=${stu.id}"
onclick="return confirm('確定刪除?')">刪除</a>
</td>
</tr>
</c:forEach>
</table>
</form>
</body>
</html>
解決方案:
1.可能你遇到的錯誤是“Property 'id' not found on type java.lang.String”異常
它的意思是String類中沒有id這個屬性,而修改的方法就是:
<c:forEach items="videos" var="video" >
修改成:
<c:forEach items="${videos}" var="video" >
但是你需要注意它的錯誤是: java.lang.String對比type bean.Student,其中對應src/bean.Student.java檔案。而且我在JSP中已經是${studentList}這種變數了,所以該方法不是該錯誤的解決方案。
2.有人說是bean的屬性名稱錯誤,或者沒有get,set方法,但是我的bean如下方法。又參考錯誤“javax.el.PropertyNotFoundException: Property 'pNum' 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 [jsp] in context with path
javax.el.PropertyNotFoundException: Property 'id' not found on type bean.Student
你需要做到的是:
(1).首先確保迴圈<c:forEach items="${studentList}" var="stu">,然後呼叫是${stu.id}、${stu.name};
(2).然後屬性命名最好是小寫的,當然首字母一定要小寫,如empNo;
(3).在資料庫中create table student( stuid int,username varchar(20)
)對應的Student類變數private Integer id; private String name;其中型別需要一致,同時設定get和set方法:
private Integer id; //學號
private String name; //姓名
public Integer getID() { return id; }
public String getName() { return name; }
public void setId(Integer id) { this.id = id; }
public void setName(String name) { this.name = name; }
(4).在DAO中資料庫增刪改查操作中型別要一致,並且對應資料庫中的學號stuid和姓名username://刪除操作
public static int delete(Integer id) throws Exception {
String sql = "DELETE FROM student WHEREstuid = ? ";
return JDBCConnect.executeUpdate(sql, id);
}
//查詢操作
student.setId(rs.getInt("stuid"));
student.setName(rs.getString("username"));
(5).如果上面的資料庫、Java類變數型別都是一致的,使用方法都正確仍然存在該錯誤,那可能就是下面的錯誤:
當我定義函式public Integer getID() { return id; }時就會報錯
HTTP Status 500 - javax.el.PropertyNotFoundException: Property 'id' not readable on type bean.Student
而當我修改為public IntegergetId() { return id; }後執行結果如下圖所示:
另一種猜測:在jstl的el表示式引用錯誤應該使用${info.type.id } 而不是${info.id }(未驗證)
參考資料:
1.JSP not finding property in bean - stackoverflow 丟失set方法
2.javax.el.PropertyNotFoundException: Property 'answer' not - stackoverflow
3.異常:javax.el.PropertyNotFoundException: Property 'id' not found on - CSDN
4.javax.el.PropertyNotFoundException: Property 'Owner' not found on - 百度知道
5.JSP沒有使<c:forEach items="${specialty}" var="spe"> - CSDN論壇
該錯誤報告和線上筆記希望對你有所幫助~
(By:Eastmount 2015-5-19 凌晨4點 http://blog.csdn.net/eastmount/)
相關文章
- javax.el.PropertyNotFoundException:Property 'statisDate' not found on type java.lang.StringJavaException
- PropertyReferenceException: No property courseId found for type CoursePic! Did you mean ‘courseid‘?Exception
- 問題No property 屬性名 found for type 類名
- Spring boot ElasticSearch,出現ElasticsearchRepository.refresh()! No property refresh found for type錯誤...Spring BootElasticsearch
- Cannot set property ‘type‘ of null(vue)NullVue
- Java之建立物件>3.Enforce the singleton property with a private constructor or an enum typeJava物件Struct
- Property 'context' does not exist on type 'NodeRequire'.ts(2339)ContextUI
- MyBatisSystemException There is no getter for property named 'id' in 'class java.lang.String'MyBatisExceptionJava
- There is no getter for property named 'userIds' in 'class java.lang.String'Java
- HttpServlet was not found on the JavaHTTPServletJava
- springboot專案解決 No beans of 'UserDao' type found 問題Spring BootBean
- 15個小type:教你高效使用Eclipse Java IDEEclipseJavaIDE
- [Vue warn]: Error in render: "TypeError: Cannot read property 'matched' of undefined" found in <App> at src/App.vueVueErrorUndefinedAPP
- Spring Boot建立DataSource時遇到的錯誤:No supported DataSource type foundSpring Boot
- android動畫——屬性動畫(Property Animation)Android動畫
- Android 屬性動畫Property Animation(中)Android動畫
- Android 屬性動畫Property Animation(下)Android動畫
- golang expected declaration, found 'IDENT'GolangIDE
- Android Animation 系列——屬性動畫(Property Animation)Android動畫
- Android property屬性許可權新增Android
- 異常解決java.io.IOException: invalid constant type: 15JavaException
- MySQL server PID file could not be found!MySqlServer
- Plugin with id 'com.android.application' not found.PluginAndroidAPP
- Android樣式的開發:Property Animation篇Android
- org.springframework.beans.NotWritablePropertyException: Invalid property '' of bSpringFrameworkBeanException
- Java泛型裡的Intersection TypeJava泛型
- Android:Unexpected lock protocol found in lock file. Expected 3, found 0.AndroidProtocol
- Android layer type與WebView白屏AndroidWebView
- Overriding the Default Tablespace Type (79)
- mybatis3:Invalid bound statement (not found)MyBatisS3
- MyBatis 錯誤:Invalid bound statement (not found)MyBatis
- mybatis 報錯: Invalid bound statement (not found)MyBatis
- Android動畫效果之初識Property Animation(屬性動畫)Android動畫
- Could not autowire. No beans of 'OrderService' type found. less... (Ctrl+F1) Inspection info:ChecksBean
- Java中的Type型別詳解Java型別
- vector android:fillType gradient android:endX attribute not foundAndroid
- React報錯之Element type is invalidReact
- All About JAVA An invalid XML character (Unicode: 0xdd65) was found in the comment 錯誤JavaXMLUnicode