为了账号安全,请及时绑定邮箱和手机立即绑定

慕课网分页问题

慕课网分页问题

好好认真学习 2017-10-16 22:33:31
<%@ 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>jsp页面的 ${result.dataList } ${ student.gender eq 2}${result.totalRecord }的原理是什么 怎么在servlet里面找不到?
查看完整描述

2 回答

?
慕粉4186495

TA贡献1条经验 获得超0个赞

result,student是传到页面的对象,所有的数据都封装在这个对象里面。dataList,gender,totalRecord是对象里面的属性。jsp页面用el表达式把数据取出来。

查看完整回答
反对 回复 2017-10-17
?
qq_雁过留声_2

TA贡献21条经验 获得超47个赞

这是El表达式,能对数据进行读取,循环,判断等操作,使用时需要依赖jstl架包,在JSP中引入jstl标签。你这种将后台代码耦合在JSP中的写法强烈建议不要这么做,否则JSP的诞生失去了意义。jstl以及El自行百度,比我们在这里说清楚的多

查看完整回答
反对 回复 2017-10-17
  • 2 回答
  • 1 关注
  • 1870 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信