<sql:query var="varname" [dataSource="dataSource"] [maxRows="maxRows"] [scope="page|session|request|application"] sql="sqlQuery" [startRow="startRow"]其中:
[ ]
:[ ]
中的内容为可选项;<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%> <!DOCTYPE html> <html> <head> <title>编程帮(www.lmcjl.com)</title> </head> <body> <body> <sql:setDataSource var="test" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/test" user="root" password="root" /> <sql:query dataSource="${test}" var="result"> SELECT * FROM website; </sql:query> <table border="1" width="100%"> <tr> <th>id</th> <th>name</th> <th>url</th> <th>age</th> <th>country</th> </tr> <c:forEach var="row" items="${result.rows}"> <tr> <td><c:out value="${row.id}" /></td> <td><c:out value="${row.name}" /></td> <td><c:out value="${row.url}" /></td> <td><c:out value="${row.age}" /></td> <td><c:out value="${row.country}" /></td> </tr> </c:forEach> </table> </body> </html>
本文链接:http://task.lmcjl.com/news/16209.html