亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

正在回答

1 回答

<%@ page language="java" contentType="text/html; charset=UTF-8"
??? pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>學生信息</title>
</head>
<%
?? ?// 獲取請求的上下文
?? ?String context = request.getContextPath();
%>
<script type="text/javascript">
// 當前第幾頁數據
var currentPage = ${result.currentPage};

// 總頁數
var totalPage = ${result.totalPage};

function submitForm(actionUrl){
?? ?var formElement = document.getElementById("stuForm");
?? ?formElement.action = actionUrl;
?? ?formElement.submit();
}

// 第一頁
function firstPage(){
?? ?if(currentPage == 1){
?? ??? ?alert("已經是第一頁數據");
?? ??? ?return false;
?? ?}else{
?? ??? ?submitForm("<%=context %>/sublist/SublistServlet?pageNum=1");
?? ??? ?return true;
?? ?}
}

// 下一頁
function nextPage(){
?? ?if(currentPage == totalPage){
?? ??? ?alert("已經是最后一頁數據");
?? ??? ?return false;
?? ?}else{
?? ??? ?submitForm("<%=context %>/sublist/SublistServlet?pageNum=" + (currentPage+1));
?? ??? ?return true;
?? ?}
}

// 上一頁
function previousPage(){
?? ?if(currentPage == 1){
?? ??? ?alert("已經是第一頁數據");
?? ??? ?return false;
?? ?}else{
?? ??? ?submitForm("<%=context %>/sublist/SublistServlet?pageNum=" + (currentPage-1));
?? ??? ?return true;
?? ?}
}

// 尾頁
function lastPage(){
?? ?if(currentPage == totalPage){
?? ??? ?alert("已經是最后一頁數據");
?? ??? ?return false;
?? ?}else{
?? ??? ?submitForm("<%=context %>/sublist/SublistServlet?pageNum=${result.totalPage}");
?? ??? ?return true;
?? ?}
}
function initPage(){
?? ?var genderRequest = "${gender}" ;
?? ?var genderVal = 0;
?? ?var genderElement = document.getElementById("gender");
?? ?if(genderRequest != ""){
?? ??? ?genderVal = parseInt(genderRequest);
?? ?}
?? ?
?? ?var options = genderElement.options;
?? ?var i = 0;
?? ?for(i = 0; i < options.length; i++){
?? ??? ?if(options[i].value == genderVal){
?? ??? ??? ?options[i].selected=true;
?? ??? ??? ?break;
?? ??? ?}
?? ?}
?? ?
}
</script>
<body onload="initPage();">
?? ?<div style="margin-left: 100px; margin-top: 100px;">
?? ??? ?<div>
?? ??? ??? ?<font color="red">${errorMsg }</font>
?? ??? ?</div>
?? ??? ?<div>
?? ??? ??? ?<form action="<%=context %>/sublist/SublistServlet"?? id="stuForm"? method="post">
?? ??? ??? ??? ?姓名
?? ??? ??? ??? ?<input type="text" name="stuName" id="stu_name" style="width:120px" value="${stuName }">
?? ??? ??? ??? ?&nbsp;
?? ??? ??? ??? ?性別
?? ??? ??? ??? ?<select name="gender" id="gender" style="width:80px">
?? ??? ??? ??? ??? ?<option value="0">全部</option>
?? ??? ??? ??? ??? ?<option value="1">男</option>
?? ??? ??? ??? ??? ?<option value="2">女</option>
?? ??? ??? ??? ?</select>
?? ??? ??? ??? ?&nbsp;&nbsp;
?? ??? ??? ??? ?<input type="submit" value="查詢">
?? ??? ??? ?</form>
?? ??? ?</div>?? ??? ?
?? ??? ?<br>
?? ??? ?學生信息列表:<br>
?? ??? ?<br>
?? ??? ?<!-- 后臺返回結果為空 -->
?? ??? ?<c:if test="${fn:length(result.dataList) eq 0 }">
?? ??? ??? ?<span>查詢的結果不存在</span>
?? ??? ?</c:if>
?? ??? ?
?? ??? ?<!-- 后臺返回結果不為空 -->
?? ??? ?<c:if test="${fn:length(result.dataList) gt 0 }">
?? ??? ??? ?<table border="1px" cellspacing="0px"
?? ??? ??? ??? ?style="border-collapse: collapse">
?? ??? ??? ??? ?<thead>
?? ??? ??? ??? ??? ?<tr height="30">
?? ??? ??? ??? ??? ??? ?<th width="130">姓名</th>
?? ??? ??? ??? ??? ??? ?<th width="130">性別</th>
?? ??? ??? ??? ??? ??? ?<th width="130">年齡</th>
?? ??? ??? ??? ??? ??? ?<th width="190">家庭地址</th>
?? ??? ??? ??? ??? ?</tr>
?? ??? ??? ??? ?</thead>
?? ??? ??? ??? ??? ?<c:forEach items="${result.dataList }" var="student">
?? ??? ??? ??? ??? ??? ?<tr>
?? ??? ??? ??? ??? ??? ??? ?<td><c:out value="${student.stuName }"></c:out></td>
?? ??? ??? ??? ??? ??? ??? ?<td>
?? ??? ??? ??? ??? ??? ??? ??? ?<c:if test="${ student.gender eq 1}">男</c:if>
?? ??? ??? ??? ??? ??? ??? ??? ?<c:if test="${ student.gender eq 2}">女</c:if>
?? ??? ??? ??? ??? ??? ??? ?</td>
?? ??? ??? ??? ??? ??? ??? ?<td><c:out value="${student.age }"></c:out></td>
?? ??? ??? ??? ??? ??? ??? ?<td><c:out value="${student.address }"></c:out></td>
?? ??? ??? ??? ??? ??? ?</tr>
?? ??? ??? ??? ??? ?</c:forEach>
?? ??? ??? ?</table>
?? ??? ??? ?<br> 共${result.totalRecord }條記錄共${result.totalPage }頁&nbsp;&nbsp;當前第${result.currentPage }頁&nbsp;&nbsp;
?? ??? ??? ?<a href="#" onclick="firstPage();">首頁</a>&nbsp;&nbsp;
?? ??? ??? ?<a href="#" onclick="nextPage();">下一頁</a>&nbsp;&nbsp;
?? ??? ??? ?<a href="#" onclick="previousPage();">上一頁</a>&nbsp;&nbsp;
?? ??? ??? ?<a href="#" onblur="lastPage();">尾頁</a>?? ?
?? ??? ?</c:if>
?? ?</div>
</body>
</html>

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Java 分頁原理與實踐(上)
  • 參與學習       65014    人
  • 解答問題       150    個

通過總結常見的分頁樣式,手把手帶你實現java常見的分頁功能

進入課程

sublistStudent.jsp的代碼

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號