[Java] javax.el.PropertyNotFoundException:Property ' id ' not found on type bean. Student

Source: Internet
Author: User

questions raised:

When developing the Java Web using MyEclipse, call theDAO and Java BeansThe following error occurred:

Critical: Servlet.service () for Servlets [JSP] in context with path [/jdbcbydao] threw exception [an exception occurred proce Ssing JSP page/student.jsp at line Notoginseng
:
:<c:foreach items= "${studentlist}" var= "Student" >
£ º<tr bgcolor= "#FFFFFF" >
Panax Notoginseng:<td><input type= "checkbox" Name= "id" value= "${student.id}"/></td>
:<td>${student.id}</td>
:<td>${student.name}</td>
Max :<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)




The properties and Get/set methods are already defined in my class, as follows:
Package Bean;public class Student {private Integer ID;       Study number private String name;      Name private String password;  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;}}
The calling code in the JSP is implemented by El, and the corresponding package is imported. as follows:
<%@ 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" >

Solution:

1. The error you may have encountered is "Property ' id ' is found on type java.lang.String"Exception
It means that there is no id attribute in the String class, and the method of modification is:
<c:foreach items= "Videos" var= "video" >
Modified to:
<c:foreach items= "${videos}" var= "video" >
But you need to be aware that its errors are:java.lang.String vs . Type Bean. Student, which corresponds to Src/bean. Student.java file. And I am already a variable of ${studentlist} in JSP, so this method is not the wrong solution.

2. It is said that the Bean property name is wrong, or there is no Get,set method, but my bean is the following method. Also refer to the error "Javax.el.PropertyNotFoundException:Property ' Pnum ' not found on type Com.manager.Paper", at this time the solution is:
private int pnum;
private int pSize;
It is recommended that you replace the names of these two properties
private int pnum;
private int psize;
It is said that the naming convention should be Stu at the same time. EmpNo estimates that the case is wrong, replaced by ${stu.empno} can be successful, because El is the getter method to read the property, generally according to the property first letter lowercase to handle. But my name is ID, so this method is not working.

3. If the above two methods you still error, the following is my own summary of the method:
Servlet.service () for Servlets [JSP] in context with path
Javax.el.PropertyNotFoundException:Property ' id ' not found on type bean. Student
What you need to do is:

(1). First make sure the loop <c:foreach items= "${ Studentlist} "var=" Stu ", then call is ${stu.id}, ${stu.name};
(2). Then the property name is preferably lowercase, of course, the first letter must be lowercase, such as empno;
(3). CREATE table student in the database (stuid int, user name varchar (20)) The corresponding student class variable private Integer ID; Private String name, where the type needs to be consistent while setting the Get and set methods:

<span style= "White-space:pre" ></span>private Integer ID;       Study number private String name;      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). In the DAO database additions and deletions in the operation type to be consistent, and the corresponding database number Stuid and name username:
Delete operation
public static int Delete (Integer ID) throws Exception {
String sql = "DELETE from student WHEREStuid= ? ";
return jdbcconnect.executeupdate (SQL, id);
}
Query operations
Student.setid (Rs.getInt ("Stuid"));
Student.setname (Rs.getString ("username"));
(5). If the above database, Java class variable type is consistent, the use of the correct method is still the error, it may be the following error:
When I define the function public IntegerGetID (){return ID;} When you get an error.

HTTP Status 500-javax.el.propertynotfoundexception:property ' id ' not readable on type bean. Student

And when I change to public IntegergetId () {return ID;} After running the result as shown:


The same SetID () method is also modified, and the SetID () and GetID () methods in DAO are also modified to "D=>d". So I still suspect the use of El when the naming convention is in mischief. And I can succeed with code validation to lowercase d. And the first one is wrongServlet.service () for Servletyou need to look at the exception thrown after it, which is the second error.
Another guess: the El expression reference error in Jstl should use ${info.type.id} instead of ${info.id} (not verified)
Resources:
1.JSP finding property in Bean-stackoverflow missing set method
2.javax.el.propertynotfoundexception:property ' Answer ' Not-stackoverflow
3. Exception: Javax.el.PropertyNotFoundException:Property ' id ' not found ON-CSDN
4.javax.el.propertynotfoundexception:property ' Owner ' not found on-Baidu knows
5.JSP did not make <c:foreach items= "${specialty}" var= "SPE" >-CSDN Forum
this error report and online note hope to help you ~
(By:eastmount 2015-5-19 4 o'clock in the morninghttp://blog.csdn.net/eastmount/)
        

[Java] javax.el.PropertyNotFoundException:Property ' id ' not found on type bean. Student

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.