我在这里再问一个问题,我前一段时间尝试过这个问题(今天),但我已经重建了我的代码。所以,我的问题是,当我单击按钮显示数据库中的详细信息时,它显示一个错误,找不到属性,我很困惑为什么会出现这个错误,这是一个错误的例子,如我可以看到它可以在我输出数据库时读取数据库中的元素,并在控制台中显示它pic of error )
//empServlet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
empServices empserv= new empServices();
ArrayList <empGetSet> empgs = new ArrayList<empGetSet>();
if (request.getParameter("process")!=null && request.getParameter("process").equals("showdis")) {
empgs.addAll(empserv.getAll());
request.setAttribute("empdet", empgs);
RequestDispatcher rd = request.getRequestDispatcher("showdet.jsp"); //forward to xxxpage after submit by button
rd.forward(request,response);
}
//empServices
package emppackage;
import java.util.ArrayList;
public class empServices {
empServlet empservlet = new empServlet();
empDAO empdao = new empDAO();
public ArrayList <empGetSet> getAll()
{
return empdao.getAllEmp();
}
//empDAO
public ArrayList<empGetSet> getAllEmp()
{
ArrayList<empGetSet> empdetails = new ArrayList<empGetSet>();
try {
Connection conn = getConnection();
String showsql = "SELECT *FROM csemp;";
PreparedStatement psread= conn.prepareStatement(showsql);
ResultSet rsread = psread.executeQuery();
while (rsread.next())
{
empGetSet readgetset = new empGetSet();
readgetset.setFname(rsread.getString(1));
//System.out.println(readgetset.getFname());
System.out.println(rsread.getString(1));
readgetset.setLname(rsread.getString(2));
readgetset.setNameRes(rsread.getString(3));
readgetset.setSerials(rsread.getString(4));
readgetset.setJrss(rsread.getString(5));
readgetset.setBand(rsread.getString(6));
readgetset.setAcct(rsread.getString(7));
readgetset.setPMPs(rsread.getString(8));
readgetset.setsJRSS(rsread.getString(9));
readgetset.setOpenSeatDesc(rsread.getString(10));
readgetset.setReqSkills(rsread.getString(11));
readgetset.setReqBand(rsread.getString(12));
readgetset.setDreject(rsread.getString(13));
readgetset.setsRreject(rsread.getString(14));
readgetset.setDetActPlan(rsread.getString(15));
readgetset.setDataComplete(rsread.getString(16));
readgetset.setStat(rsread.getString(17));
empdetails.add(readgetset);
}
psread.close();
conn.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return empdetails;
}
这是我的Getters和Setters,具有相同的命名约定 package emppackage;
public class empGetSet {
private String Fname;
private String Lname;
private String NameRes;
private String Serials;
private String Jrss;
private String Band;
private String Acct;
private String PMPs;
private String sJRSS;
private String OpenSeatDesc;
private String ReqSkills;
private String ReqBand;
private String Dreject;
private String Rreject;
private String DetActPlan;
private String DataComplete;
private String Stat;
public String getFname() {
return Fname;
}
public void setFname(String Fname) {
this.Fname=Fname;
}
public String getLname() {
return Lname;
}
public void setLname(String Lname) {
this.Lname=Lname;
}
public String getNameRes() {
return NameRes;
}
public void setNameRes(String NameRes) {
this.NameRes=NameRes;
}
public String getSerials() {
return Serials;
}
public void setSerials(String Serials) {
this.Serials=Serials;
}
public String getJrss() {
return Jrss;
}
public void setJrss(String Jrss) {
this.Jrss=Jrss;
}
public String getBand() {
return Band;
}
public void setBand(String Band) {
this.Band=Band;
}
public String getAcct() {
return Acct;
}
public void setAcct(String Acct) {
this.Acct=Acct;
}
public String getPMPs() {
return PMPs;
}
public void setPMPs(String PMPs) {
this.PMPs=PMPs;
}
public String getsJRSS() {
return sJRSS;
}
public void setsJRSS(String sJRSS) {
this.sJRSS=sJRSS;
}
public String getOpenSeatDesc() {
return OpenSeatDesc;
}
public void setOpenSeatDesc(String OpenSeatDesc) {
this.OpenSeatDesc=OpenSeatDesc;
}
public String getReqSkills() {
return ReqSkills;
}
public void setReqSkills(String ReqSkills) {
this.ReqSkills=ReqSkills;
}
public String getReqBand() {
return ReqBand;
}
public void setReqBand(String Acct) {
this.Acct=Acct;
}
public String getDreject() {
return Dreject;
}
public void setDreject(String Dreject) {
this.Dreject=Dreject;
}
public String getRreject() {
return Rreject;
}
public void setsRreject(String Rreject) {
this.Rreject=Rreject;
}
public String getDetActPlan() {
return DetActPlan;
}
public void setDetActPlan(String DetActPlan) {
this.DetActPlan=DetActPlan;
}
public String getDataComplete() {
return DataComplete;
}
public void setDataComplete(String DataComplete) {
this.DataComplete=DataComplete;
}
public String getStat() {
return Stat;
}
public void setStat(String Stat) {
this.Stat=Stat;
}
}
这是我的.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Show Details</title>
</head>
<body>
<div align="right"><a href="loggedin.jsp"><button>Back</button></a></div>
<form action ="empServlet" method="get">
<table border =1 cellpadding="18">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Name of Resource (LN ID Format)</th>
<th>Serial Number</th>
<th>JRSS</th>
<th>Band</th>
<th>Account (Proposed)</th>
<th>PMP Seat</th>
<th>Seat JRSS</th>
<th>Open Seat Description</th>
<th>Required Skills</th>
<th>Required Band low/high</th>
<th>Date of Rejection</th>
<th>Reason for Rejection</th>
<th>Detailed Action Plan</th>
<th>Target Date of Completion</th>
<th>Status(Ongoing/Closed)</th>
<th colspan=2>Do This</th>
</tr>
</thead>
<tbody>
<c:forEach items ="${empdet}" var="empdet" >
<tr>
<td><c:out value ="${empdet.Fname}" /></td>
<td><c:out value ="${empdet.Lname}" /></td>
<td><c:out value ="${empdet.NameRes}" /></td>
<td><c:out value ="${empdet.Serials}" /></td>
<td><c:out value ="${empdet.Jrss}" /></td>
<td><c:out value ="${empdet.Band}" /></td>
<td><c:out value ="${empdet.Acct}" /></td>
<td><c:out value ="${empdet.PMPs}" /></td>
<td><c:out value ="${empdet.sJRSS}" /></td>
<td><c:out value ="${empdet.OpenSeatDesc}" /></td>
<td><c:out value ="${empdet.ReqSkills}" /></td>
<td><c:out value ="${empdet.ReqBand}" /></td>
<td><c:out value ="${empdet.Dreject}" /></td>
<td><c:out value ="${empdet.Rreject}" /></td>
<td><c:out value ="${empdet.DetActPlan}" /></td>
<td><c:out value ="${empdet.DataComplete}" /></td>
<td><c:out value ="${empdet.Stat}" /></td>
<td><a href="empServlet?Serials=${empdet.Serials}&process=update">Update</a></td>
<td><a href="empServlet?Serials=${empdet.Serials}&process=delete">Delete</a></td>
</c:forEach>
</tbody>
</table>
<br>
<a href="empServlet?&process=showdis">Show All</a>
</form>
</body>
</html>