jsp中Hashmap问题,谁能帮帮忙。
代码如下:<body><%HashMapmap=newHashMap();map.put("a","21.0");map.put("b","21.0");map.put(...
代码如下:
<body>
<%
HashMap map = new HashMap();
map.put("a", "21.0");
map.put("b", "21.0");
map.put("c", "21.0");
map.put("d", "21.0");
Iterator iterator = map.keySet().iterator();
while (iterator.hasNext()) {
String key =iterator.next().toString();
System.out.println("key:"+key);
System.out.println("value:"+map.get(key));
}
%>
运行没有结果。运行提示:
信息: Virtual server server loaded system default web module
严重: Application previously deployed is not at its original location any more : file:/I:/Subject12-11/Subject1/build/web/
信息: [Thread[GlassFish Kernel Main Thread,5,main]] started
信息: {felix.fileinstall.poll (ms) = 5000, felix.fileinstall.dir = C:\Program Files\glassfish-3.0.1\glassfish\modules\autostart, felix.fileinstall.debug = 1, felix.fileinstall.bundles.new.start = true, felix.fileinstall.tmpdir = C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\fileinstall-9081056165298836985, felix.fileinstall.filter = null}
信息: Hibernate Validator bean-validator-3.0-JBoss-4.0.2
信息: Started bundle: file:/C:/Program%20Files/glassfish-3.0.1/glassfish/modules/autostart/osgi-web-container.jar
信息: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
信息: Created HTTP listener http-listener-1 on port 8080
信息: Grizzly Framework 1.9.18-o started in: 15ms listening on port 8080
信息: Perform lazy SSL initialization for the listener 'http-listener-2'
信息: Created HTTP listener http-listener-2 on port 8181
信息: Grizzly Framework 1.9.18-o started in: 0ms listening on port 8181
信息: key:d
信息: value:21.0
信息: key:b
信息: value:21.0
信息: key:c
信息: value:21.0
信息: key:a
信息: value:21.0
运行没有结果,但看错误提示:信息:
key:d
信息: value:21.0
信息: key:b
信息: value:21.0
信息: key:c
信息: value:21.0
信息: key:a
信息: value:21.0
怎么处理? 展开
<body>
<%
HashMap map = new HashMap();
map.put("a", "21.0");
map.put("b", "21.0");
map.put("c", "21.0");
map.put("d", "21.0");
Iterator iterator = map.keySet().iterator();
while (iterator.hasNext()) {
String key =iterator.next().toString();
System.out.println("key:"+key);
System.out.println("value:"+map.get(key));
}
%>
运行没有结果。运行提示:
信息: Virtual server server loaded system default web module
严重: Application previously deployed is not at its original location any more : file:/I:/Subject12-11/Subject1/build/web/
信息: [Thread[GlassFish Kernel Main Thread,5,main]] started
信息: {felix.fileinstall.poll (ms) = 5000, felix.fileinstall.dir = C:\Program Files\glassfish-3.0.1\glassfish\modules\autostart, felix.fileinstall.debug = 1, felix.fileinstall.bundles.new.start = true, felix.fileinstall.tmpdir = C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\fileinstall-9081056165298836985, felix.fileinstall.filter = null}
信息: Hibernate Validator bean-validator-3.0-JBoss-4.0.2
信息: Started bundle: file:/C:/Program%20Files/glassfish-3.0.1/glassfish/modules/autostart/osgi-web-container.jar
信息: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
信息: Created HTTP listener http-listener-1 on port 8080
信息: Grizzly Framework 1.9.18-o started in: 15ms listening on port 8080
信息: Perform lazy SSL initialization for the listener 'http-listener-2'
信息: Created HTTP listener http-listener-2 on port 8181
信息: Grizzly Framework 1.9.18-o started in: 0ms listening on port 8181
信息: key:d
信息: value:21.0
信息: key:b
信息: value:21.0
信息: key:c
信息: value:21.0
信息: key:a
信息: value:21.0
运行没有结果,但看错误提示:信息:
key:d
信息: value:21.0
信息: key:b
信息: value:21.0
信息: key:c
信息: value:21.0
信息: key:a
信息: value:21.0
怎么处理? 展开
2个回答
展开全部
Iterator iterator = map.keySet().iterator();//应该是这里吧
你用keySet()是取不到value的
用Set<Entry<String,Double>> entry=map.entrySet();
然后迭代取得每一个子元素Entry<String,Double>
再用geyKey() getValue()
你用keySet()是取不到value的
用Set<Entry<String,Double>> entry=map.entrySet();
然后迭代取得每一个子元素Entry<String,Double>
再用geyKey() getValue()
追问
用Set> entry=map.entrySet();
然后迭代取得每一个子元素Entry
能不能具体点。
追答
Set> entry=map.entrySet();
Iterator> ite=entry.iterator();
while(ite.hasNext()){
Entry e=(Entry) ite.next();
System.out.println("key:"+e.getKey());
System.out.println("value"+e.getValue());
}
哦 对了 我看错了。
你这里是 map.put("a", "21.0");
你把Entry改成Entry
展开全部
//方法1
for(Iterator<Entry<String, String>> i = map.entrySet().iterator(); i.hasNext(); ) {
Map.Entry<String, String> entry = i.next();
System.out.println("key : " + entry.getKey());
System.out.println("value : " + entry.getValue());
}
//方法2
for(Iterator<String> iterator = map.keySet().iterator(); iterator.hasNext(); ) {
System.out.println("value : " + map.get(iterator.next()));
}
//方法3,不用iterator
for(String elem : map.keySet()) {
System.out.println("key : " + elem);
System.out.println("value : " + map.get(elem));
}
for(Iterator<Entry<String, String>> i = map.entrySet().iterator(); i.hasNext(); ) {
Map.Entry<String, String> entry = i.next();
System.out.println("key : " + entry.getKey());
System.out.println("value : " + entry.getValue());
}
//方法2
for(Iterator<String> iterator = map.keySet().iterator(); iterator.hasNext(); ) {
System.out.println("value : " + map.get(iterator.next()));
}
//方法3,不用iterator
for(String elem : map.keySet()) {
System.out.println("key : " + elem);
System.out.println("value : " + map.get(elem));
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询