使用JSP技术实现一个简单的在线测试系统的实例(2)

<h1>成绩榜</h1> <%! //降序排序 public <K, V extends Comparable<? super V>> Map<K, V> sortByValueDescending(Map<K, V> map) { List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(map.entrySet()); Collections.sort(list, new Comparator<Map.Entry<K, V>>() { public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) { int compare = (o1.getValue()).compareTo(o2.getValue()); return -compare; } }); Map<K, V> result = new LinkedHashMap<K, V>(); for (Map.Entry<K, V> entry : list) { result.put(entry.getKey(), entry.getValue()); } return result; } %> <% if(application.getAttribute("scorelist")==null){ out.print("<h3>没有成绩</h3>"); } else{ //遍历显示所有成绩(Map遍历) Map<String, Integer> score_list= (Map<String, Integer>)application.getAttribute("scorelist"); score_list=sortByValueDescending(score_list); Set s=score_list.keySet(); Iterator it=s.iterator(); while(it.hasNext()){ String username=(String)it.next(); int score=score_list.get(username); out.print("<h3>"+username+":"+score+"</h3>"); } } %>

6、完整流程

使用JSP技术实现一个简单的在线测试系统的实例

使用JSP技术实现一个简单的在线测试系统的实例

使用JSP技术实现一个简单的在线测试系统的实例

使用JSP技术实现一个简单的在线测试系统的实例

到此这篇关于使用JSP技术实现一个简单的在线测试系统的实例详解的文章就介绍到这了,更多相关JSP技术实现一个简单的在线测试系统内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wxwssj.html