javax.el.PropertyNotFoundException: class 'PureJavaClasses.employeeClass' 没有 属性 'Id'
javax.el.PropertyNotFoundException: The class 'PureJavaClasses.employeeClass' does not have the property 'Id'
我一直在尝试在 Servlet 的帮助下通过 ArrayList.The JDBC 部分在 JSP 中打印结果集,似乎所有 right.The ArrayList 都可以获得在 JSP 内并且可以是 printed.But 当我想用 <c:forEach>
标签迭代传递到 JSP 的列表时,它说我的 bean class 'PureJavaClasses.employeeClass' 没有属性 'Id'。我在 SO 上尝试了很多不同的解决方案,但在 vain.I 中,我完全不知道要做什么 do.I 我是 JavaEE 的初学者。
这是我的 Bean class:
public class employeeClass implements java.io.Serializable {
private int id;
private String name;
private String job;
private int subjectId;
private int salary;
public employeeClass() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public int getSubjectid() {
return subjectId;
}
public void setSubjectid(int subjectId) {
this.subjectId = subjectId;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
@Override
public String toString() {
return "id=" + id +
", name=" + name +
", job=" + job +
", subjectId=" + subjectId +
", salary=" + salary;
}
}
这是 servlet:
private void show_table(HttpServletRequest request,HttpServletResponse response){
Connection connection = ServletLogin.connection;
String query = "SELECT * FROM `dog`.`employee`";
ArrayList<employeeClass> list = new ArrayList<>();
try {
PreparedStatement pst = connection.prepareStatement(query);
ResultSet rs = pst.executeQuery();
while(rs.next()){
employeeClass obj2 = new employeeClass();
obj2.setId(rs.getInt("ID"));
obj2.setName(rs.getString("Name"));
obj2.setJob(rs.getString("Job_Designation"));
obj2.setSubjectid(rs.getInt("Subject ID"));
obj2.setSalary(rs.getInt("Salary"));
list.add(obj2);
}
} catch (SQLException e) {
e.printStackTrace();
}
request.setAttribute("listEmp",list);
try {
request.getRequestDispatcher("/Pages/EmployeeTable.jsp").forward(request,response);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
这是我的 EmployeeTable.jsp :
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="java.util.ArrayList"%>
<html>
<head>
<title>Employee List</title>
</head>
<body>
<% ArrayList list1 =(ArrayList) request.getAttribute("listEmp"); %>
<%=list1%>
<table>
<th>ID</th>
<th>Name</th>
<th>Job Designation</th>
<th>Subject ID</th>
<th>Salary</th>
<c:forEach items="${listEmp}" var="list">
<tr>
<td><c:out value="${list.Id}"/></td>
<td><c:out value="${list.name}"/></td>
<td><c:out value="${list.job}"/></td>
<td><c:out value="${list.subjectId}"/></td>
<td><c:out value="${list.salary}"/></td>
</tr>
</c:forEach>
</table>
</body>
</html>
这是我的 web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>ServletLogin</servlet-name>
<servlet-class>ServletLogin</servlet-class>
</servlet>
<servlet>
<servlet-name>ServletEmployee</servlet-name>
<servlet-class>ServletEmployee</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletLogin</servlet-name>
<url-pattern>/ServletLogin</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ServletEmployee</servlet-name>
<url-pattern>/ServletEmployee</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
我认为您需要通过提供正确的名称来解决。比如用id代替id等应该可以解决
<td><c:out value="${list.id}"/></td>
我一直在尝试在 Servlet 的帮助下通过 ArrayList.The JDBC 部分在 JSP 中打印结果集,似乎所有 right.The ArrayList 都可以获得在 JSP 内并且可以是 printed.But 当我想用 <c:forEach>
标签迭代传递到 JSP 的列表时,它说我的 bean class 'PureJavaClasses.employeeClass' 没有属性 'Id'。我在 SO 上尝试了很多不同的解决方案,但在 vain.I 中,我完全不知道要做什么 do.I 我是 JavaEE 的初学者。
这是我的 Bean class:
public class employeeClass implements java.io.Serializable {
private int id;
private String name;
private String job;
private int subjectId;
private int salary;
public employeeClass() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public int getSubjectid() {
return subjectId;
}
public void setSubjectid(int subjectId) {
this.subjectId = subjectId;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
@Override
public String toString() {
return "id=" + id +
", name=" + name +
", job=" + job +
", subjectId=" + subjectId +
", salary=" + salary;
}
}
这是 servlet:
private void show_table(HttpServletRequest request,HttpServletResponse response){
Connection connection = ServletLogin.connection;
String query = "SELECT * FROM `dog`.`employee`";
ArrayList<employeeClass> list = new ArrayList<>();
try {
PreparedStatement pst = connection.prepareStatement(query);
ResultSet rs = pst.executeQuery();
while(rs.next()){
employeeClass obj2 = new employeeClass();
obj2.setId(rs.getInt("ID"));
obj2.setName(rs.getString("Name"));
obj2.setJob(rs.getString("Job_Designation"));
obj2.setSubjectid(rs.getInt("Subject ID"));
obj2.setSalary(rs.getInt("Salary"));
list.add(obj2);
}
} catch (SQLException e) {
e.printStackTrace();
}
request.setAttribute("listEmp",list);
try {
request.getRequestDispatcher("/Pages/EmployeeTable.jsp").forward(request,response);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
这是我的 EmployeeTable.jsp :
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="java.util.ArrayList"%>
<html>
<head>
<title>Employee List</title>
</head>
<body>
<% ArrayList list1 =(ArrayList) request.getAttribute("listEmp"); %>
<%=list1%>
<table>
<th>ID</th>
<th>Name</th>
<th>Job Designation</th>
<th>Subject ID</th>
<th>Salary</th>
<c:forEach items="${listEmp}" var="list">
<tr>
<td><c:out value="${list.Id}"/></td>
<td><c:out value="${list.name}"/></td>
<td><c:out value="${list.job}"/></td>
<td><c:out value="${list.subjectId}"/></td>
<td><c:out value="${list.salary}"/></td>
</tr>
</c:forEach>
</table>
</body>
</html>
这是我的 web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>ServletLogin</servlet-name>
<servlet-class>ServletLogin</servlet-class>
</servlet>
<servlet>
<servlet-name>ServletEmployee</servlet-name>
<servlet-class>ServletEmployee</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletLogin</servlet-name>
<url-pattern>/ServletLogin</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ServletEmployee</servlet-name>
<url-pattern>/ServletEmployee</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
我认为您需要通过提供正确的名称来解决。比如用id代替id等应该可以解决
<td><c:out value="${list.id}"/></td>