gpt4 book ai didi

java - 从数据库检索表 : javax. el.PropertyNotFoundException

转载 作者:行者123 更新时间:2023-11-29 08:17:48 25 4
gpt4 key购买 nike

我想从数据库中检索整个表并将其显示到我的 jsp 页面中,但出现错误

我的 StaffBean。 java是

package com.staff.bean;
import java.util.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;


public class StaffBean {

private String date;
private int workload;
private int hourId;
private int daysId;
private int staffId;
private String StaffName;
private String ActiveORInactive;
private String Stafftype;
private String subcode;
private boolean valid = false;

public String getdate() {
// DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
// Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); // your template here
java.util.Date dateStr = null;
try {
dateStr = formatter.parse(date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
java.sql.Date dateDB = new java.sql.Date(dateStr.getTime());
return formatter.format(dateDB);
}
public void setdate(String date){
this.date=date;
}
public int gethourId() {
return hourId;
}
public void sethourId(int hourId) {
this.hourId = hourId;
}
public int getdaysId() {
return daysId;
}
public void setdaysId(int daysId) {
this.daysId = daysId;
}
public int getworkload() {
return hourId;
}
public void setworkload(int workload) {
this.workload = workload;
}
public int getstaffId() {
return staffId;
}
public void setstaffId(int staffId) {
this.staffId = staffId;
}
public String getStaffName() {
return StaffName;
}
public void setStaffName(String StaffName) {
this.StaffName = StaffName;
}
public String ActiveORInactive() {
return ActiveORInactive;
}
public void setActiveORInactive(String ActiveORInactive) {
this.ActiveORInactive = ActiveORInactive;
}

public String getStafftype() {
return Stafftype;
}
public void setStafftype(String Stafftype) {
this.Stafftype = Stafftype;
}
public String getsubcode() {
return Stafftype;
}
public void setsubcode(String subcode) {
this.subcode = subcode;
}

public boolean isValid() {
return valid;
}
public void setValid(boolean valid) {
this.valid = valid;
}


}

我的 GetAllDetailDAO.java 是

 package com.staff.DAO;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.staff.bean.StaffBean;
import com.staff.DB.ConnectionProvider;
public class GetAllDetailDAO {

Connection con;
Statement stmt;
private int noOfRecords;

public List<StaffBean> viewAllStaff(int offSet, int noOfRecords){

List<StaffBean> list = new ArrayList<StaffBean>();
StaffBean _staffBean;
try {
con = ConnectionProvider.getConnection();
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select SQL_CALC_FOUND_ROWS * from tblstaffdetails limit "+offSet+","+noOfRecords);
//+offSet+","+noOfRecords);
//SQL_CALC_FOUND_ROWS
while(rs.next()){
_staffBean = new StaffBean();
_staffBean.setStaffName(rs.getString("StaffName"));
_staffBean.setstaffId(rs.getInt("staffId"));
_staffBean.setActiveORInactive(rs.getString("ActiveORInactive"));
_staffBean.setStafftype(rs.getString("Stafftype"));
list.add(_staffBean);
}
rs.close();
rs = stmt.executeQuery("SELECT FOUND_ROWS()");
if(rs.next())
this.noOfRecords = rs.getInt(1);

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


return list;

}
public int getNoOfRecords() {
return noOfRecords;
}
}

连接提供商 包 com.staff.DB;

  import java.sql.*;

public class ConnectionProvider {
static Connection con;
static String url;

public static Connection getConnection() throws SQLException{
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/StaffAllocation","root", "success");
}catch(ClassNotFoundException cnf){
cnf.printStackTrace();
}

return con;

}

}

我的 GetAllDetailServlet.java 是

  package com.staff.servlet;
import java.io.IOException;
import java.util.List;
import java.sql.*;

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 com.staff.bean.StaffBean;
import com.staff.DAO.GetAllDetailDAO;
import com.staff.DB.*;

@WebServlet("/GetAllDetailServlet")
public class GetAllDetailServlet extends HttpServlet{




/**
* Servlet implementation class GetAllDetailsServlet
*/


private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public GetAllDetailServlet() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub

int page = 1;
int recordsPerPage = 4;
if(request.getParameter("page") != null)
page = Integer.parseInt(request.getParameter("page"));
GetAllDetailDAO allDetailDAO = new GetAllDetailDAO();
List<StaffBean> list = allDetailDAO.viewAllStaff((page-1)*recordsPerPage, recordsPerPage);
int noOfRecords = allDetailDAO.getNoOfRecords();
int noOfPages = (int) Math.ceil(noOfRecords * 1.0 / recordsPerPage);
request.setAttribute("staffList", list);
request.setAttribute("noOfPages", noOfPages);
request.setAttribute("currentPage", page);
RequestDispatcher view = request.getRequestDispatcher("jsp/displayAllDetail.jsp");
view.forward(request, response);

}
}

我的 DisplayAllDetail.jsp 是

  <html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> :: All Details</title>
</head>
<body>
<fieldset>
<table border="1" cellpadding="4" cellspacing="4" align="center">
<tr>
<th>staffId</th>
<th>StaffName</th>
<th>ActiveORInactive</th>
<th>Stafftype</th>
<c:forEach var="_staffBean" items="${staffList}">
<tr>
<td>${_staffBean.staffId}</td>
<td>${_staffBean.StaffName}</td>
<td>${_staffBean.ActiveORInactive}</td>
<td>${_staffBean.Stafftype}</td>
</tr>
</c:forEach>
</tr>
</table>
<c:if test="${currentPage != 1}">
<td><a href="getAll.do?method=get&page=${currentPage - 1}">Prev</a></td>
</c:if>
<table border="1" cellpadding="5" cellspacing="5" align="center">
<tr>
<c:forEach begin="1" end="${noOfPages }" var="i">
<c:choose>
<c:when test="${currentPage eq i }">
<td>${i}</td>
</c:when>
<c:otherwise>
<td><a href="getAll.do?method=get&page=${i}">${i}</a></td>
</c:otherwise>
</c:choose>
</c:forEach>
</tr>
</table>
<c:if test="${currentPage lt noOfPages }">
<td><a href="getAll.do?method=get&page=${currentPage+1 }">Next</a></td>
</c:if>
</fieldset>
</body>
</html>

我的错误是

  HTTP Status 500 - An exception occurred processing JSP page /jsp/displayAllDetail.jsp at line 22
type Exception report

message An exception occurred processing JSP page /jsp/displayAllDetail.jsp at line 22

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 /jsp/displayAllDetail.jsp at line 22

19: <c:forEach var="_staffBean" items="${staffList}">
20: <tr>
21: <td>${_staffBean.staffId}</td>
22: <td>${_staffBean.StaffName}</td>
23: <td>${_staffBean.ActiveORInactive}</td>
24: <td>${_staffBean.Stafftype}</td>
25: </tr>

堆栈跟踪: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) com.staff.servlet.GetAllDetailServlet.doGet(GetAllDetailServlet.java:56) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

根本原因

    javax.el.PropertyNotFoundException: Property 'StaffName' not found on type   com.staff.bean.StaffBean
javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237)
javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214)
javax.el.BeanELResolver.property(BeanELResolver.java:325)
javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
org.apache.el.parser.AstValue.getValue(AstValue.java:183)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:1026)
org.apache.jsp.jsp.displayAllDetail_jsp._jspx_meth_c_005fforEach_005f0(displayAllDetail_jsp.java:157)
org.apache.jsp.jsp.displayAllDetail_jsp._jspService(displayAllDetail_jsp.java:99)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
com.staff.servlet.GetAllDetailServlet.doGet(GetAllDetailServlet.java:56)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

注意 Apache Tomcat/7.0.42 日志中提供了根本原因的完整堆栈跟踪。

最佳答案

尝试声明

    private String staffName;
private String activeORInactive;
private String stafftype;

并且不使用大写字母。

建议您关注Java Code convertions

关于java - 从数据库检索表 : javax. el.PropertyNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20214877/

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