我在尝试启动网络服务时收到此错误消息:org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: Property 'jobId' not found on type com.bridge.service.Service
奇怪的是,jobId
在服务和我的数据库中定义它将从中提取数据。
以下是应该访问数据的函数。
public List<Service> getAllData() {
List<Service> data = new ArrayList<Service>();
try {
Class.forName(jdbc_driver);
// Connect to DB
Connection conn = DriverManager.getConnection(db_url, USER, PASS);
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery("SELECT * FROM email_data");
while (rs.next()) {
Service serv = new Service();
//UUID id = null;
serv.setId(rs.getString("jobId")); // error here
serv.setName(rs.getString("jobName"));
serv.setStatus(rs.getString("jobStatus"));
serv.setStart(rs.getTimestamp("start"));
serv.setFinish(rs.getTimestamp("finish"));
data.add(serv);
}
rs.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) {
System.err.println("listing data, ya fucked up boi");
System.err.println(e.getMessage());
}
return data;
}
此外,在我的JSP文件中,它应该抓取数据,它被列为名为jobId
的变量,如下所示。
<body>
<table border=1>
<thead>
<tr>
<th>Job ID</th>
<th>Job Name</th>
<th>Job Status</th>
<th>Start Time</th>
<th>Finish Time</th>
<th colspan=2>Action</th>
</tr>
</thead>
<tbody>
<c:forEach items="${jobs}" var="job">
<tr>
<td><c:out value="${job.jobId}"/></td>
<td><c:out value="${job.jobName}"/></td>
<td><c:out value="${job.jobStatus}"/></td>
<td><c:out value="${job.start}"/></td>
<td><c:out value="${job.finish}"/></td>
<td><a href="ServiceController?action=edit&jobId=<c:out value="${job.jobId}"/>">Update</a></td>
<td><a href="ServiceController?action=delete&jobId=<c:out value="${job.jobId}"/>">Delete</a></td>
</tr>
</c:forEach>
</tbody>
</table>
<p><a href="ServiceController?action=insert">Add Job</a></p>
有什么想法吗?我在这里不知所措。
编辑:这是Service.java:
public class Service {
private String jobId;
private String jobName;
private String jobStatus;
private Timestamp jobStart;
private Timestamp jobFinish;
public Service() {
// empty constructor
}
public Service(String id, String n, String s) {
jobId = id;
jobName = n;
jobStatus = s;
}
public String getId() {
return this.jobId;
}
public String getName() {
return this.jobName;
}
public String getStatus() {
return this.jobStatus;
}
public void setId(String id) {
this.jobId = id;
}
public void setName(String name) {
this.jobName = name;
}
public void setStatus(String status) {
this.jobStatus = status;
}
public void setStart(Timestamp time) {
this.jobStart = time;
}
public void setFinish(Timestamp time) {
this.jobFinish = time;
}
// SQL Info
static final String jdbc_driver = "com.mysql.jdbc.Driver";
static final String db_url = "jdbc:mysql://localhost:3306/email_data";
// SQL creds
static final String USER = "<redacted>";
static final String PASS = "<redacted>";
public void hygienePost(Service serv) throws Exception {
NewTask.toRabbit(serv.getId(), serv.getName(), serv.getStatus());
// System.out.println(serv.getId()+serv.getName()+serv.getStatus());
}
public List<Service> getAllData() {
List<Service> data = new ArrayList<Service>();
try {
Class.forName(jdbc_driver);
// Connect to DB
Connection conn = DriverManager.getConnection(db_url, USER, PASS);
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery("SELECT * FROM email_data");
while (rs.next()) {
Service serv = new Service();
// UUID id = null;
/*
serv.setId(rs.getString("jobId"));
serv.setName(rs.getString("jobName"));
serv.setStatus(rs.getString("jobStatus"));
serv.setStart(rs.getTimestamp("start"));
serv.setFinish(rs.getTimestamp("finish")); data.add(serv);
*/
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
// The column count starts from 1
for (int i = 1; i < columnCount + 1; i++) {
String name = rsmd.getColumnName(i);
System.out.println(rs.getString(1));
}
}
rs.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) {
System.err.println("listing data, ya fucked up boi");
System.err.println(e.getMessage());
}
return data;
}
}
答案 0 :(得分:2)
它的贾斯珀例外。
serv.setId(rs.getString("jobid")); // error here
您在服务类中提到了setID。然后属性是id。
所以你需要这样做
<td><c:out value="${job.id}"/></td>
所以你不应该在bean类中有不同的propname和getter setter。应该是一样的。
所以请更改getter和setter。
添加getJobid和setJobid。
答案 1 :(得分:1)
您在jobid
方法中使用小写i
撰写getAllData()
,但使用大写I
进行宣传。
正如我从您发布的代码中看到的那样,jobId的getter方法是setID()
。因此我的猜测是你的财产被称为id而不是jobId。确保您的Service类看起来像这样:
public class Service {
private String jobId;
public void setJobId(String jobId) {
this.jobId = jobId;
}
public String getJobId() {
return this.jobId;
}
}
@Siva首先发现了这个错误。因此,如果这纠正了您的错误,请考虑投票而不是我。
答案 2 :(得分:1)
serv.setId(rs.getString("jobId"));
资本我。