繁体   English   中英

HTTP状态500没有属性“id”

[英]HTTP Status 500 does not have the property 'id'

当我显示客户的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'。

note备注 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类

package de.java2enterprise.onlineshop.model;

import java.io.Serializable;

public class Customer实现Serializable {private static final long 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")

public class UserServlet扩展HttpServlet {private static final long 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()) {

客户客户=新客户();

            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;
}

}

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

它是getId/setId而不是getID/setID

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM