Building a Java LinkedHashMap and iterating over it always comes in handy. In a class you can have something like:
private Map myLinks = new LinkedHashMap();
public Map getLinks() {
return myLinks;
}
public void setMyLinks(String key, String value) {
this.myLinks.put(key, value);
}
...
for(int j=0; j<links.getLength(); j++)
{
setMyLinks( ((Element)links.item(j)).getAttribute("url"),
getText(links.item(j)) );
}
Then in a JSP you can do something like:
Map thisMyLinks = ThisState.getMyLinks();
for (Iterator it=thisStateLinks.keySet().iterator(); it.hasNext(); )
{
Object key = it.next();
Object value = thisStateLinks.get(key);
out.println("<li><a href=\"" + key.toString() + "\">" +
value.toString() + "</a></li>");
}
No comments:
Post a Comment