gpt4 book ai didi

javax.el.PropertyNotFoundException : The class 'PureJavaClasses.employeeClass' does not have the property 'Id'

转载 作者:行者123 更新时间:2023-11-30 06:48:59 24 4
gpt4 key购买 nike

我一直在尝试在Servlet的帮助下通过ArrayList在JSP中打印ResultSet。JDBC部分似乎没问题。ArrayList可以在JSP内部获取并可以打印。但是当我想迭代时该列表通过 <c:forEach> 传递到 JSP标签,它说我的 bean 类“PureJavaClasses.employeeClass”没有属性“Id”。我已经尝试了在 SO 上发布的一堆不同的解决方案,但都是徒劳。我不知道该怎么做。我是 JavaEE 的初学者。

这是我的 Bean 类:

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>

关于javax.el.PropertyNotFoundException : The class 'PureJavaClasses.employeeClass' does not have the property 'Id' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43173928/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com