3 回答

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超9個(gè)贊
1、在后臺定義一個(gè)Servlet或者Action,接收jsp的參數(shù)去數(shù)據(jù)庫查詢數(shù)據(jù),返回List
2、將從數(shù)據(jù)庫查詢的數(shù)據(jù)放在request中,如request.setAttribute("studentList",studentList),輸出到對應(yīng)的jsp頁面。
3、在jsp頁面引入jstl標(biāo)簽,定義好一個(gè)html表格頭
4、用jstl獲取后臺查詢的數(shù)據(jù),利用<c:foreach>標(biāo)簽循環(huán)輸出到表格的<tr>中。
示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <html> <body> <table class="table table-bordered" > <tr> <th style="text-align:center;width:2%">序號</th> <th style="text-align:center;width:5%">姓名</th> <th style="text-align:center;width:6%">年齡</th> </tr> <c:forEach items="${studentList}" var="student" varStatus="status"> <tr> <td style="text-align:center;">${status}</td> <td style="text-align:center;">${student.username}</td> <td style="text-align:center;">${student.age}</td> </tr> </c:forEach> </table> </body> </html> |
添加回答
舉報(bào)