gpt4 book ai didi

javax.el.PropertyNotFoundException : Property 'role_id' not found on type model. 角色

转载 作者:行者123 更新时间:2023-12-01 11:35:43 25 4
gpt4 key购买 nike

我在 StackOverflow 上发现了其他类似/问题,我尝试按照他们的解决方案解决我的问题,但我无法弄清楚我做错了什么。我需要将列表从 servlet 传递到 JSP 页面。

这是 Servlet:

package controller;

import dao.DAOFactory;
import dao.interfaces.RoleDAO;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Role;

/**
*
* @author realnot
*/
@WebServlet("/Dashboard")
public class Dashboard extends HttpServlet {

private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

// Prepare messages.
Map<String, String> messages = new HashMap<String, String>();
req.setAttribute("messages", messages);

// Obtain DAOFactory.
DAOFactory crm = DAOFactory.getInstance("crm.jdbc");
if (crm == null) {
messages.put("dao", "DAOFactory not obtainerd: " + crm);
}

// Obtain RoleDAO.
RoleDAO roleDAO = crm.getRoleDAO();
if (roleDAO == null) {
messages.put("dao", "RoleDAO not obtained: " + roleDAO);
}

List<Role> roles = roleDAO.list();
req.setAttribute("roleList", roles);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/pages/Dashboard.jsp");
rd.forward(req, res);
}
}

这是 JSP 页面:

<!DOCTYPE html>
<html>
<head>
<title>CRM - Customer Relationship Management</title>
<link rel="stylesheet" type="text/css" href="../css/reset.css" />
<link rel="stylesheet" type="text/css" href="../css/style.css" />
<link rel="stylesheet" type="text/css" href="../css/menu.css" />
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
</head>
<body>
<div id="container">
<div id="header">Header</div>
<div id="page" class="grid_24">
<div id="nav" class="grid_6">
<%@include file="include/navigation.html" %>
</div>
<div id="next-meetings" class="grid_6 content">
<h3>Next Meetings</h3>
<c:forEach items="${roleList}" var="role">
<c:out value="${role.role_id}"></c:out>
<c:out value="${role.role_name}"></c:out>
</c:forEach>
</div>
<div id="business-proposals" class="grid_6 content">
<h3>Business Proposals</h3>
</div>
<div id="personal-notes" class="grid_6 content">
<h3>Personal Notes</h3>
</div>
</div>
<div id="footer">Footer</div>
</div>
</body>
</html>

模型:

package model;

import java.io.Serializable;

public class Role implements Serializable {

// Constants ------------------------------------------------------
private static final long serialVersionUID = 1L;

// Properties -----------------------------------------------------
private Integer role_id;
private String role_name;
private String role_desc;

// Getters/setters ------------------------------------------------
public Integer getRoleID() { return this.role_id; }
public String getRoleName() { return this.role_name; }
public String getRoleDesc() { return this.role_desc; }

public void setRoleID(Integer value) { this.role_id = value; }
public void setRoleName(String value) { this.role_name = value; }
public void setRoleDesc(String value) { this.role_desc = value; }
}

但我不断收到此错误:

HTTP Status 500 - An exception occurred processing JSP page /pages/Dashboard.jsp at line 20

type Exception report

message An exception occurred processing JSP page /pages/Dashboard.jsp at line 20

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /pages/Dashboard.jsp at line 20

17: 18:

Next Meetings

19:
20:
21:
22:
23:

Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(Unknown Source) org.apache.jasper.servlet.JspServletWrapper.service(Unknown Source) org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source) org.apache.jasper.servlet.JspServlet.service(Unknown Source) javax.servlet.http.HttpServlet.service(Unknown Source) controller.Dashboard.doGet(Dashboard.java:53) javax.servlet.http.HttpServlet.service(Unknown Source) javax.servlet.http.HttpServlet.service(Unknown Source)

root cause

javax.el.PropertyNotFoundException: Property 'role_id' not found on type model.Role javax.el.BeanELResolver$BeanProperties.get(Unknown Source) javax.el.BeanELResolver$BeanProperties.access$300(Unknown Source) javax.el.BeanELResolver.property(Unknown Source) javax.el.BeanELResolver.getValue(Unknown Source) org.apache.jasper.el.JasperELResolver.getValue(Unknown Source) org.apache.el.parser.AstValue.getValue(Unknown Source) org.apache.el.ValueExpressionImpl.getValue(Unknown Source) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(Unknown Source) org.apache.jsp.pages.Dashboard_jsp._jspx_meth_c_005fout_005f0(Dashboard_jsp.java:197) org.apache.jsp.pages.Dashboard_jsp._jspx_meth_c_005fforEach_005f0(Dashboard_jsp.java:161) org.apache.jsp.pages.Dashboard_jsp._jspService(Dashboard_jsp.java:108) org.apache.jasper.runtime.HttpJspBase.service(Unknown Source) javax.servlet.http.HttpServlet.service(Unknown Source) org.apache.jasper.servlet.JspServletWrapper.service(Unknown Source) org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source) org.apache.jasper.servlet.JspServlet.service(Unknown Source) javax.servlet.http.HttpServlet.service(Unknown Source) controller.Dashboard.doGet(Dashboard.java:53) javax.servlet.http.HttpServlet.service(Unknown Source) javax.servlet.http.HttpServlet.service(Unknown Source)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.56-gentoo logs. Apache Tomcat/7.0.56-gentoo

出了什么问题?

最佳答案

您已使用属性role_id

<c:out value="${role.role_id}"></c:out>

但你没有这样的属性(property)。要成为属性 role_id,您需要为名称 role_id 生成 getter 和 setter。

关于javax.el.PropertyNotFoundException : Property 'role_id' not found on type model. 角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30014285/

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