简体   繁体   English

HTTP状态500没有属性“id”

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

I get Error Messsage when I display the ID of the customer. 当我显示客户的ID时,我收到错误消息。 I have too try to change the name of the property 'id' but the came the same error with new name. 我也尝试更改属性'id'的名称,但是新名称出现了同样的错误。

HTTP Status 500 - Internal Server Error HTTP状态500 - 内部服务器错误

type Exception report message Internal Server Error description The server encountered an internal error that prevented it from fulfilling this request. 类型异常报告消息内部服务器错误说明服务器遇到内部错误,导致无法完成此请求。

exception org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: The class 'de.java2enterprise.onlineshop.model.Customer' does not have the property 'id'. 异常 org.apache.jasper.JasperException:javax.el.PropertyNotFoundException:类'de.java2enterprise.onlineshop.model.Customer'没有属性'id'。

root cause javax.el.PropertyNotFoundException: The class 'de.java2enterprise.onlineshop.model.Customer' does not have the property 'id'. 根本原因 javax.el.PropertyNotFoundException:类'de.java2enterprise.onlineshop.model.Customer'没有属性'id'。

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 5.1.0 logs. note备注 GlassFish Server Open Source Edition 5.1.0日志中提供了异常的完整堆栈跟踪及其根本原因。

HTML: 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 Class Java类

package de.java2enterprise.onlineshop.model; package de.java2enterprise.onlineshop.model;

import java.io.Serializable; import java.io.Serializable;

public class Customer implements Serializable{ private static final long serialVersionUID = 1L; 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() + 
        "]";
}

} }

Controller 调节器

@WebServlet("/userShow")

public class UserServlet extends HttpServlet { private static final long serialVersionUID = 1L; 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()) {

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

} }

Your Customer class needs to follow the naming conventions for Java beans: 您的Customer类需要遵循Java bean的命名约定:

It's getId/setId instead of getID/setID . 它是getId/setId而不是getID/setID

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

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