3
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
<sql:setDataSource var="dataSource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/cloud" user="root" password="root"
scope="session" />
<sql:query var="qryProvider" >
SELECT * FROM `provider`;
</sql:query>
<table>
<c:forEach var="row" items="${qryProvider.rows}">
<tr>
<td>${row.display_name}</td>
</tr>
</c:forEach>
</table>
我得到了以下錯誤:如何使用JSTL SQL標籤
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error() that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /testJSTL.jsp at line 8
5: url="jdbc:mysql://localhost:3306/cloud" user="root" password="root"
6: scope="session" />
7:
8: <sql:query var="qryProvider" >
9: SELECT * FROM `provider`;
10: </sql:query>
11:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:567)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:456)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.lang.NullPointerException"
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
org.apache.jsp.testJSTL_jsp._jspService(testJSTL_jsp.java:94)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
我試圖按照this tut,但它給了我一個錯誤,如果我寫
<sql:query var="qryProvider" dataSource="${dataSource}" >
我對此新來說,有人可以指出我正確的方向嗎?
可以在此處找到此類servlet的一個示例:[在使用MVC模式的JSP頁面中的HTML
來源
2015-09-11 11:33:03 RamChithra
你也可以添加一些解釋嗎? – Robert
替換你的代碼和進口SQL包
或 導入SQL包和 刪除;從您的選擇語句
來源
2016-02-06 11:18:09 Nilesh
相關問題