利用迭代器输出数据时,怎么输出键值呢
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.*,student.info.Student" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <% Map<String, Student> map=new HashMap(); map.put("1", new Student("11071010","赵明",78)); map.put("2", new Student("11071011","李雷",100)); map.put("3", new Student("11071012","韩梅梅",90)); map.put("4", new Student("11071013","大熊",80)); map.put("5", new Student("11071014","李静香",92)); map.put("6", new Student("11071015","胖虎",42)); //Map<String,Student> map=DBUtil.map; Iterator<Student> it=map.values().iterator(); int id=1; while(it.hasNext()){%> 第<%=id %>条:<%out.print(it.next());%> </br> <% id++; } %> </body> </html> package student.info; public class Student { private String stuId, stuName; private double stuScore; public Student(String stuId, String stuName, double stuScore) { super(); this.stuId = stuId; this.stuName = stuName; this.stuScore = stuScore; } public String getStuId() { return stuId; } public void setStuId(String stuId) { this.stuId = stuId; } public String getStuName() { return stuName; } public void setStuName(String stuName) { this.stuName = stuName; } public double getStuScore() { return stuScore; } public void setStuScore(double stuScore) { this.stuScore = stuScore; } @Override public String toString() { return "Student [id=" + stuId + ", name=" + stuName + ", score=" + stuScore + "]"; } }
2-6编程要求在jsp文件中实例化对象,并存入map集合中,利用迭代器将数据输出。请问老师,利用迭代器只能输出学生信息,怎么把对应的键值输出呢
10
收起
正在回答 回答被采纳积分+1
1回答
Java Web基础入门2018版
- 参与学习 716 人
- 提交作业 185 份
- 解答问题 1363 个
会Java?懂前端基础?想学后台开发?那么,赶快来学习《Java Web入门》路径吧。本路径主要介绍Java Web的基础知识,并配有大量案例,定会让你收获多多!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星