【发布时间】:2018-11-24 14:58:01
【问题描述】:
我正在尝试使用 JSP 从我的数据库中检索数据并将它们投影到一个 html 页面。我使用的是 servlet scriptlet,但发现 JSTL 是一种更好的方法,所以我就这么做了。问题是在编译页面时确实返回错误:The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
我尝试使用标准 java 从同一个数据库中获取数据,并且成功了……但是这里没有。我具体页面的源代码是:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page import="java.sql.*" %>
<%@page import="java.lang.String" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Main Menu</title>
</head>
<style>
body {
background-color: lightblue;
}
</style>
<sql:setDataSource var = "snapshot" driver = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://127.0.0.1:3306/CARDATA"
user = "toomlg4u"/>
<sql:query dataSource = "${snapshot}">USE CARDATA;</sql:query>
<sql:query dataSource = "${snapshot}" var = "result">
SELECT * FROM Users;
</sql:query>
<table border = "1" width = "100%">
<tr>
<th>ID</th>
<th>Full Name</th>
<th>Password</th>
<th>Email</th>
</tr>
<c:forEach var = "row" items = "${result.rows}">
<tr>
<td> <c:out value = "${row.userId}"/></td>
<td> <c:out value = "${row.realName}"/></td>
<td> <c:out value = "${row.userName}"/></td>
<td> <c:out value = "${row.passWord}"/></td>
<td> <c:out value = "${row.email}"/></td>
</tr>
</c:forEach>
</table>
</body>
</html>
感谢每一点帮助!
P.S:这只是一个小项目,不是专业的。
编辑
我将 jconnector 复制到 $CATALINA_HOME 的 lib 文件夹中,所以现在它显示了表格但没有值...奇怪的是我上面的两个查询...
【问题讨论】: