我試圖在同一個表中顯示所有員工列表,並將其刪除。但是這個錯誤一直困擾着我。其原因是什麼?在類型bean上找不到屬性'EmployeeID'。員工
May 28, 2017 9:25:27 PM
org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
javax.el.PropertyNotFoundException: Property 'EmployeeID' not found on type bean.Employee
May 28, 2017 9:25:27 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [DisplayAllEmp] in context with path [/ELMS] threw exception [An exception occurred processing JSP page /elms/elms_skms/DeleteEmployeeAcc.jsp at line 55
52: <tbody>
53: <c:forEach items="${employee}" var="emp">
54: <tr>
55: <td><c:out value="${emp.EmployeeID}" /></td>
56: <td><c:out value="${emp.EmployeeIC}" /></td>
57: <td><c:out value="${emp.EmployeeName}" /></td>
58: <td><c:out value="${emp.EmployeePosition}" /></td>
Stacktrace:] with root cause
javax.el.PropertyNotFoundException: Property 'EmployeeID' not found on type bean.Employee
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:266)
at javax.el.BeanELResolver$BeanProperties.access$300(BeanELResolver.java:243)
這是我的jsp頁面:
<div class="module-body table">
<form name = delete" method="POST" action="DeleteEmployeeServlet">
<table cellpadding="0" cellspacing="0" border="0" class="datatable-1 table
table-bordered table-striped display" width="50%">
<thead>
<tr>
<th>Employee ID</th>
<th>Employee IC</th>
<th>Employee Name</th>
<th>Employee Position</th>
<th>Employee Session</th>
<th>Employee Grade</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<c:forEach items="${employee}" var="emp">
<tr>
<td><c:out value="${emp.EmployeeID}" /></td>
<td><c:out value="${emp.EmployeeIC}" /></td>
<td><c:out value="${emp.EmployeeName}" /></td>
<td><c:out value="${emp.EmployeePosition}" /></td>
<td><c:out value="${emp.EmployeeSession}" /></td>
<td><c:out value="${emp.EmployeeGrade}" /></td>
<td><a href="DeleteEmployeeServlet?table=employee&employeeid=<c:out
value="${emp.EmployeeID}" />"onclick="return confirm('Are you
sure?');"><i class="icon-trash"></i></a> <br></td>
</c:forEach>
</tbody>
這是我的servlet頁面:
package servlet;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Date;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import model.EmployeeDAO;
import bean.Employee;
public class DeleteEmployeeServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private EmployeeDAO dao;
public DeleteEmployeeServlet() {
super();
dao = new EmployeeDAO();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String forward = "";
String table = request.getParameter("table");
if(table.equalsIgnoreCase("employee")){
int id = Integer.parseInt(request.getParameter("EmployeeID"));
dao.DeleteEmployeeDetails(id);
forward = "DisplayAllEmp?table=employee";
}
RequestDispatcher view = request.getRequestDispatcher(forward);
view.forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}
}
這裏是我的模型/ DAO(viewEmployee):
public List<Employee> viewEmployee() {
List<Employee> employee = new ArrayList<Employee>();
try {
currentCon = ConnectionManager.getConnection();
stmt = currentCon.createStatement();
ResultSet rs = stmt.executeQuery("select * from employee");
while (rs.next()) {
Employee e = new Employee();
e.setEmployeeID(rs.getInt("EmployeeID"));
e.setEmployeePassword(rs.getString("EmployeePassword"));
e.setEmployeeName(rs.getString("EmployeeName"));
e.setEmployeeIC(rs.getString("EmployeeIC"));
e.setEmployeeGender(rs.getString("EmployeeGender"));
e.setEmployeeEmail(rs.getString("EmployeeEmail"));
e.setEmployeePhoneNo(rs.getString("EmployeePhoneNo"));
e.setEmployeeStreet1(rs.getString("EmployeeStreet1"));
e.setEmployeeStreet2(rs.getString("EmployeeStreet2"));
e.setEmployeePCode(rs.getInt("EmployeePCode"));
e.setEmployeeCity(rs.getString("EmployeeCity"));
e.setEmployeeState(rs.getString("EmployeeState"));
e.setEmployeeQualification(rs.getString("EmployeeQualification"));
e.setEmployeePosition(rs.getString("EmployeePosition"));
e.setEmployeeSession(rs.getString("EmployeeSession"));
e.setEmployeeGrade(rs.getInt("EmployeeGrade"));
e.setEmploymentDate(rs.getDate("EmploymentDate"));
employee.add(e);
System.out.println("Employee id: " + e.getEmployeeID());
}
System.out.println("All rows from table view Employee retrieved!");
} catch (SQLException e) {
System.out.println("Failed: An SQL Exception occured : " + e);
e.printStackTrace();
}
return employee;
}
這是我的DisplayAllEmp的DAO:
public void DeleteEmployeeDetails(int id) {
try {
currentCon = ConnectionManager.getConnection();
ps = currentCon.prepareStatement("delete from employee where employeeID=?");
// Parameters start with 1
ps.setInt(1, id);
ps.executeUpdate();
System.out.println("1 row of table Employee has been deleted. employeeID:" + id);
} catch (SQLException e) {
e.printStackTrace();
}
}
這裏是我的豆(員工):
package bean;
import java.util.Date;
public class Employee {
private int EmployeeID;
private String EmployeePassword;
private String EmployeeName;
private String EmployeeIC;
private String EmployeeGender;
private String EmployeeEmail;
private String EmployeePhoneNo;
private String EmployeeStreet1;
private String EmployeeStreet2;
private int EmployeePCode;
private String EmployeeCity;
private String EmployeeState;
private String EmployeeQualification;
private String EmployeePosition;
private String EmployeeSession;
private int EmployeeGrade;
private Date EmploymentDate;
private boolean valid;
public Employee() {
EmployeeID = 0;
EmployeePassword = null;
EmployeeName=null;
EmployeeIC=null;
EmployeeGender=null;
EmployeeEmail=null;
EmployeePhoneNo=null;
EmployeeStreet1=null;
EmployeeStreet2=null;
EmployeePCode=0;
EmployeeCity=null;
EmployeeState=null;
EmployeeQualification=null;
EmployeePosition=null;
EmployeeSession=null;
EmployeeGrade=0;
EmploymentDate=null;
}
public Employee(int employeeID, String employeePassword, String employeeName, String employeeIC, String employeeGender, String employeeEmail, String employeePhone, String employeeStreet1, String employeeStreet2, int employeePCode, String employeeCity, String employeeState, String employeeQuaification, String employeePosition, String employeeSession, int employeeGrade, Date employmentDate) {
EmployeeID = employeeID;
EmployeePassword = employeePassword;
EmployeeName=employeeName;
EmployeeIC=employeeIC;
EmployeeGender=employeeGender;
EmployeeEmail=employeeEmail;
EmployeePhoneNo=employeePhone;
EmployeeStreet1=employeeStreet1;
EmployeeStreet2=employeeStreet2;
EmployeePCode=employeePCode;
EmployeeCity=employeeCity;
EmployeeState=employeeState;
EmployeeQualification=employeeQuaification;
EmployeePosition=employeePosition;
EmployeeSession=employeeSession;
EmployeeGrade=employeeGrade;
EmploymentDate=employmentDate;
}
public int getEmployeeID() {return EmployeeID;}
public void setEmployeeID(int employeeID) {EmployeeID = employeeID;}
public String getEmployeePassword() {return EmployeePassword;}
public void setEmployeePassword(String employeePassword) {EmployeePassword = employeePassword;}
public String getEmployeeName() {return EmployeeName;}
public void setEmployeeName(String employeeName) {EmployeeName = employeeName;}
public String getEmployeeIC() {return EmployeeIC;}
public void setEmployeeIC(String employeeIC) {EmployeeIC = employeeIC;}
public String getEmployeeGender() {return EmployeeGender;}
public void setEmployeeGender(String employeeGender) {EmployeeGender = employeeGender;}
public String getEmployeeEmail() {return EmployeeEmail;}
public void setEmployeeEmail(String employeeEmail) {EmployeeEmail = employeeEmail;}
public String getEmployeePhoneNo() {return EmployeePhoneNo;}
public void setEmployeePhoneNo(String employeePhoneNo) {EmployeePhoneNo = employeePhoneNo;}
public String getEmployeeStreet1() {return EmployeeStreet1;}
public void setEmployeeStreet1(String employeeStreet1) {EmployeeStreet1 = employeeStreet1;}
public String getEmployeeStreet2() {return EmployeeStreet2;}
public void setEmployeeStreet2(String employeeStreet2) {EmployeeStreet2 = employeeStreet2;}
public int getEmployeePCode() {return EmployeePCode;}
public void setEmployeePCode(int employeePCode) {EmployeePCode = employeePCode;}
public String getEmployeeCity() {return EmployeeCity;}
public void setEmployeeCity(String employeeCity) {EmployeeCity = employeeCity;}
public String getEmployeeState() {return EmployeeState;}
public void setEmployeeState(String employeeState) {EmployeeState = employeeState;}
public String getEmployeeQualification() {return EmployeeQualification;}
public void setEmployeeQualification(String employeeQualification) {EmployeeQualification = employeeQualification;}
public String getEmployeePosition() {return EmployeePosition;}
public void setEmployeePosition(String employeePosition) {EmployeePosition = employeePosition;}
public String getEmployeeSession() {return EmployeeSession;}
public void setEmployeeSession(String employeeSession) {EmployeeSession = employeeSession;}
public int getEmployeeGrade() {return EmployeeGrade;}
public void setEmployeeGrade(int employeeGrade) {EmployeeGrade = employeeGrade;}
public Date getEmploymentDate() {return EmploymentDate;}
public void setEmploymentDate(Date employmentDate) {EmploymentDate = employmentDate;}
public boolean isValid() {return valid;}
public void setValid(boolean valid) {this.valid = valid;}
}
歡迎來到SO,您可能需要參加[tour](https://stackoverflow.com/tour)。還請提供一個[最小,完整和可驗證的示例](http://stackoverflow.com/help/mcve),以提高回答問題的可能性,而不是太多的代碼行。 – Nuageux