【问题标题】:how to fetch a SQLtable to my JSP如何将 SQLtable 提取到我的 JSP
【发布时间】:2017-10-08 06:56:25
【问题描述】:

如何在不使用 JavaScript 或 ajax 的情况下将 SQL 表提取到我的 JSP 中

我想要 JSP 中的所有代码

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
</head>
<body>

    <%
       //i need to write the code here
    %>

</body>
</html>

注意:我在 spring 和 hibernate 中创建了 save 方法,但我不知道如何获取数据

【问题讨论】:

    标签: java spring hibernate jsp


    【解决方案1】:
       Add this tag 
    
        <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>  
    
       // then DB details
    
     <sql:setDataSource
            var="myDS"
            driver="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3306/databaseName"
            user="root" password="password"
        />
        //Your query
        <sql:query var="listDetails"   dataSource="${myDS}" > SELECT * FROM TableName ;
         </sql:query>
    
         //Then comes view
         <c:forEach var="listDetails" items="${listDetails.rows}">
          <tr>
           <td><c:out value="${listDetails.id}" /></td>
          </tr>
         </c:forEach>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-28
      • 2014-01-17
      • 1970-01-01
      相关资源
      最近更新 更多