A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 刘国强 中级黑马   /  2013-4-29 17:28  /  3036 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 刘国强 于 2013-5-2 00:23 编辑

在servlet查询出学生的成绩,存入成绩对象,存入list集合排序后,然后将成绩对象存入request,在jsp页面,获取数据显示显示成绩,想在显示页面的数据最前面加上序号,也就是实现排名,应该怎么做
JSP页面代码:
  1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
  2. <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
  3. <%
  4. String path = request.getContextPath();
  5. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  6. %>

  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  8. <html>
  9.   <head>
  10.     <base href="<%=basePath%>">
  11.    
  12.     <title>My JSP 'paixuResualt.jsp' starting page</title>
  13.    
  14.         <meta http-equiv="pragma" content="no-cache">
  15.         <meta http-equiv="cache-control" content="no-cache">
  16.         <meta http-equiv="expires" content="0">   
  17.         <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  18.         <meta http-equiv="description" content="This is my page">
  19.         <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/commons/globals.css"/>
  20.         
  21.   </head>
  22.   
  23. <body>

  24.         



  25.         所在班级:${classname}&nbsp;&nbsp;排名依据:${xueqi }${paiby }
  26.         


  27.         <div id="container">
  28.           <div style="clear:both"></div>
  29.                 <div>
  30.                         
  31.                     <table id="t">
  32.                     
  33.                             <tr>
  34.                                     
  35.                                     <td align="center" colspan="2">学生信息</td>
  36.                                     
  37.                                     <td align="center" colspan="6">第一学期成绩</td>
  38.                                     <td align="center" colspan="6">第二学期成绩</td>
  39.                                     <td align="center" colspan="1">学年总成绩</td>
  40.                                  </tr>
  41.                             <tr>
  42.                                     <th>学号</th>
  43.                                     <th>姓名</th>
  44.                                     <th>数学</th>
  45.                                     <th>语文</th>
  46.                                     <th>英语</th>
  47.                                     <th>平时成绩</th>
  48.                                     <th>评价成绩</th>
  49.                                     <th>学期总成绩</th>
  50.                                     <th>数学</th>
  51.                                     <th>语文</th>
  52.                                     <th>英语</th>
  53.                                     <th>平时成绩</th>
  54.                                     <th>评价成绩</th>
  55.                                     <th>学期总成绩</th>
  56.                                     <th>学年总成绩</th>
  57.                                  </tr>
  58.                                  
  59.                                  
  60.                                  <c:forEach var="stu" items="${classList}" >
  61.                                  
  62.                                     <tr id="3">
  63.                                                 <td width="60px">${stu.stuid}</td>
  64.                                             <td width="60px">${stu.stuname}</td>
  65.                                             <td width="60px">${stu.math_1}</td>
  66.                                             <td width="60px">${stu.lage_1}</td>
  67.                                             <td width="60px">${stu.english_1}</td>
  68.                                             <td width="80px">${stu.pscore_1}</td>
  69.                                             <td width="80px">${stu.fscore_1}</td>
  70.                                             <td width="80px">${stu.zscore_1}</td>
  71.                                             <td width="60px">${stu.math_2}</td>
  72.                                             <td width="60px">${stu.lage_2}</td>
  73.                                             <td width="60px">${stu.english_2}</td>
  74.                                             <td width="80px">${stu.pscore_2}</td>
  75.                                             <td width="80px">${stu.fscore_2}</td>
  76.                                             <td width="80px">${stu.zscore_2}</td>
  77.                                             <td width="80px">${stu.zscore}</td>
  78.                                             
  79.                                          </tr>        
  80.                                          
  81.                                  </c:forEach>
  82.                                                          
  83.                
  84.                     </table>
  85.                   </div>
  86.     </div>
  87.    





  88.   </body>
  89. </html>
复制代码

评分

参与人数 1技术分 +1 收起 理由
黄玉昆 + 1

查看全部评分

2 个回复

倒序浏览
这个最佳解决方案是在数据库中取的时候order by

评分

参与人数 1技术分 +1 收起 理由
黄玉昆 + 1

查看全部评分

回复 使用道具 举报
谢谢各位的回答了,已经找到了解决办法,通过foreach的varStatus="status"属性,然后使用,status.index 来实现添加序号
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马