【问题标题】:JSP Example to connect to MS SQL database using Tomcat使用 Tomcat 连接到 MS SQL 数据库的 JSP 示例
【发布时间】:2012-08-24 08:32:33
【问题描述】:

我正在尝试使用 jsp 检索数据,但它显示 错误:org.apache.jasper.JasperException:在第 13 行处理 JSP 页面 /databaseTest.jsp 时发生异常

我的代码是:

<%@taglib  uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.io.*,java.util.*,java.sql.*" %>
<%@page import="javax.servlet.http.*,javax.servlet.*" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSTL sql:query Tag</title>
</head>
<body>
   <sql:setDataSource var="ds" driver="com.mysql.jdbc.Driver"
 url="jdbc:mysql://localhost/JSPTUTORIAL"
 user="root"  password="root"/>
    <sql:query dataSource="${ds}" var="result">
        SELECT * FROM Employees;
    </sql:query>
    <h4>Employee Table</h4>
    <table border="1" width="100%">
        <tr>
            <th>Employee ID</th>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Age</th>
        </tr>
        <c:forEach var="row" items="${result.rows}"/>
            <tr>
                <td><c:out value="${row.id}"/></td>
                <td><c:out value="${row.first}"/></td>
                <td><c:out value="${row.last}"/></td>
                <td><c:out value="${row.age}"/></td>
            </tr>
    </table>
</body>

【问题讨论】:

    标签: jsp datasource java-ee-5


    【解决方案1】:

    语法代码是正确的。我在IDE中过去并检查。也许这段代码和 /databaseTest.jsp 不匹配。请检查一下。

    我建议不要在实际项目中使用标签。例如,在 Spring 中,您可以创建 bean 并使用依赖注入设置所有数据(登录名、密码等)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-07
      • 2016-11-18
      • 1970-01-01
      • 1970-01-01
      • 2011-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多