i have an doubt that i dont how to use the following
java code in
jsp page to built an menu.since i am not familiar with jsp, can anyone help me.
The code:
<code>
package learnings;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
public class PageDisplay {
public static void main(
String[] args) {
Map<String, Collection> menuLabel = new PageDisplay().populateMenuItems();
Set<String> chapterNames = menuLabel.keySet();
for (Iterator iter = chapterNames.iterator(); iter.hasNext() {
String chapterName = (String) iter.next();
System.out.println(chapterName);
Collection<String> subTopicCollections = menuLabel.get(chapterName);
for (Iterator iterator = subTopicCollections.iterator(); iterator
.hasNext() {
String subtopicName = (String) iterator.next();
System.out.println("******" + subtopicName);
}
}
}
/*public Map<String, Collection> getMenuLabels() {
Map<String, Collection> menuLabel = new LinkedHashMap<String, Collection>();
Collection temp = null;
Collection<DataBean> dataBeanCollection = populateDummyValues();
for (Iterator iter = dataBeanCollection.iterator(); iter.hasNext() {
DataBean bean = (DataBean) iter.next();
temp = menuLabel.get(bean.getChapterName());
if (temp == null) {
temp = new ArrayList<DataBean>();
}
temp.add(bean.getSubTopicName());
menuLabel.put(bean.getChapterName(), temp);
}
System.out.println(menuLabel);
return menuLabel;
}
private Collection<DataBean> populateDummyValues() {
Collection<DataBean> dataBeanCollection = new ArrayList<DataBean>();
DataBean bean = null;
int temp = 0;
// Select * from tableName where subject = 'JAVA';
for (int index =0; index <= 20; index++) { // instead of this use while (resultset.next()) {
bean = new DataBean();
if (index % 5 == 0) {
temp++;
}
bean.setChapterName("Chapter-" + temp); // rs.getString("Chapter";
bean.setSubTopicName("SubTopicName-" + index); // rs.getString("Subtopic";
dataBeanCollection.add(bean);
} // }
return dataBeanCollection;
}*/
private Map<String, Collection> populateMenuItems() {
Map<String, Collection> menuLabel = new LinkedHashMap<String, Collection>();
Collection tempList = null;
int temp = 0;
String chapterName, subTopicName;
// Select * from tableName where subject = 'JAVA';
for (int index =0; index <= 20; index++) { // instead of this use while (resultset.next()) {
if (index % 5 == 0) {
temp++;
}
chapterName = "Chapter-" + temp; // rs.getString("Chapter";
subTopicName = "SubTopicName-" + index; // rs.getString("Subtopic";
tempList = menuLabel.get(chapterName);
if (tempList == null) {
tempList = new ArrayList<DataBean>();
}
tempList.add(subTopicName);
menuLabel.put(chapterName, tempList);
} // }
System.out.println(menuLabel);
return menuLabel;
}
}
</code>