无法使用jsp从mysql数据库获取数据

qgzx9mmu  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(422)

我试图用jsp从数据库中检索数据,并将它们投影到html页面。我使用ServletScriptlet,但发现jstl是一种更好的方法,所以我选择了它。问题是,在编译时,页面确实返回错误: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. 我试着用标准java从同一个数据库中获取数据,结果成功了。。。但这里不是。我的特定页面的源代码是:

  1. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  2. <%@page import="java.sql.*" %>
  3. <%@page import="java.lang.String" %>
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>Main Menu</title>
  8. </head>
  9. <style>
  10. body {
  11. background-color: lightblue;
  12. }
  13. </style>
  14. <sql:setDataSource var = "snapshot" driver = "com.mysql.jdbc.Driver"
  15. url = "jdbc:mysql://127.0.0.1:3306/CARDATA"
  16. user = "toomlg4u"/>
  17. <sql:query dataSource = "${snapshot}">USE CARDATA;</sql:query>
  18. <sql:query dataSource = "${snapshot}" var = "result">
  19. SELECT * FROM Users;
  20. </sql:query>
  21. <table border = "1" width = "100%">
  22. <tr>
  23. <th>ID</th>
  24. <th>Full Name</th>
  25. <th>Password</th>
  26. <th>Email</th>
  27. </tr>
  28. <c:forEach var = "row" items = "${result.rows}">
  29. <tr>
  30. <td> <c:out value = "${row.userId}"/></td>
  31. <td> <c:out value = "${row.realName}"/></td>
  32. <td> <c:out value = "${row.userName}"/></td>
  33. <td> <c:out value = "${row.passWord}"/></td>
  34. <td> <c:out value = "${row.email}"/></td>
  35. </tr>
  36. </c:forEach>
  37. </table>
  38. </body>
  39. </html>

感谢您的每一点帮助!
p、 s:这只是一个小项目,不是专业项目。
编辑
我将jconnector复制到$catalina\u home的lib文件夹中,所以现在它显示表,但没有值。。。奇怪的是我上面的两个问题。。。

yjghlzjz

yjghlzjz1#

您尚未导入文件中的标记库
添加

  1. <%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix="c" %>
  2. <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>

到页面顶部。
表也有5列,但只有4个标题列。
您还可以删除<%@页导入标记

相关问题