【发布时间】:2013-01-15 21:39:00
【问题描述】:
我按照这个解决方案无效:https://stackoverflow.com/a/1835742/666468
我正在尝试输出此地图:
//protected Map<String,String> getImageTagAttributes()
Image image = new Image(resource);
for (Map<String, String> foo : image.getImageTagAttributes()) {
String key = foo.getKey();
String value = foo.getValue();
//output here
}
但我收到此错误:只能迭代数组或 java.lang.Iterable 的实例
我也导入了 java.util.Iterator,但没有运气。
附言我希望我可以安装和使用 JSTL,但这不是我的决定。
【问题讨论】:
-
image.getImageTagAttributes()返回了什么?Map具有键/值对机制。您需要使用EntrySet来迭代Map。 -
按照以下解决方案中的建议使用迭代器:stackoverflow.com/questions/672916/…
-
你是怎么错过你找到的答案中的
entrySet()方法的? -
@BalusC,我认为
countries.entrySet()是所讨论的示例所独有的,而不是我所特有的。我在 Java 方面的知识充其量只是新手。
标签: java jsp map iteration aem