如何在不使用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方法,但我不知道如何获取数据
答案 0 :(得分:0)
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>