尝试启动我的Web服务时,我收到以下错误消息: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;
}


}

最佳答案

其Jasper例外。

serv.setId(rs.getString("jobid"));  // error here


您在服务类中提到了setID。然后,属性为id。

所以你需要那样做

<td><c:out value="${job.id}"/></td>


因此,在bean类中,您不应具有不同的propname和getter setter。应该是一样的。

因此,请更改getter和setter。

添加getJobid和setJobid。

关于java - javax.el.PropertyNotFoundException:找不到属性“jobId”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32740580/

10-10 10:03