HTTP Status 500没有属性'id'

时间:2019-06-10 11:50:53

标签: java

当显示客户ID时,我收到错误消息。我也尝试更改属性“ id”的名称,但是使用新名称来出现相同的错误。

HTTP状态500-内部服务器错误

类型例外报告 消息内部服务器错误 说明:服务器遇到内部错误,无法满足该请求。

例外 org.apache.jasper.JasperException:javax.el.PropertyNotFoundException:类'de.java2enterprise.onlineshop.model.Customer'没有属性'id'。

根本原因 javax.el.PropertyNotFoundException:类'de.java2enterprise.onlineshop.model.Customer'没有属性'id'。

注释,该异常的完整堆栈跟踪及其根本原因可在GlassFish Server Open Source Edition 5.1.0日志中找到。

HTML:

<%@ include file="header.jspf" %>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>Onlineshop</title>
	</head>
	<body>
		

<c:forEach var="customer" items="${customers}">
<article>
	<p>${customer.id}</p>
	<p>${customer.email}</p>
	<p>test</p>
</article>
</c:forEach>

<%@ include file="footer.jspf" %>

Java类

软件包de.java2enterprise.onlineshop.model;

导入java.io.Serializable;

客户公开类实现了可序列化{     私有静态最终长serialVersionUID = 1L;

private Long id;
private String email;
private String password;

public Customer() {}

public Customer(String email, String password) {
    this.email = email;
    this.password = password;
}

public Long getID() {
    return id;
}

public void setID(Long id) {
    this.id = id;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public String toString() {
    return 
        "[" +
        getID() + ", " +
        getEmail() + ", " +
        getPassword() + 
        "]";
}

}

控制器

@WebServlet("/userShow")

公共类UserServlet扩展了HttpServlet {     私有静态最终长serialVersionUID = 1L;

@Resource
private DataSource ds;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request, response);
}
public void doPost( HttpServletRequest request,  HttpServletResponse response) throws ServletException, IOException {

    try {
        List<Customer> customers = find();
        if (customers != null) {
            HttpSession session = request.getSession();
            session.setAttribute("customers", customers);
        }
    } catch (Exception e) {
        throw new ServletException(e.getMessage());
    }
    RequestDispatcher dispatcher = request.getRequestDispatcher("search.jsp");
    dispatcher.forward(request, response);
}

public List<Customer> find() throws Exception {

    List<Customer> customers = new ArrayList<Customer>();
    try (final Connection con = ds.getConnection();
            final PreparedStatement stmt = con
                    .prepareStatement(
                            "SELECT " +
                                    "id, " +
                                    "email, " +
                                    "password " +
                                    "FROM onlineshop.customer ")) {
        ResultSet rs = stmt.executeQuery();
        while (rs.next()) {

Customer customer = new Customer();

            Long id = Long.valueOf(rs.getLong("id"));
            customer.setID(id);

            String email = rs.getString("email");
            customer.setEmail(email);

            String password = rs.getString("password");
            customer.setPassword(password);
            customers.add(customer);

        }
    }
    return customers;
}

}

1 个答案:

答案 0 :(得分:0)

您的Customer类需要遵循Java Bean的命名约定:

它是getId/setId而不是getID/setID