Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

clarification for jsp code

 
shyamkumar bopannachengalaiah
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64696
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.

 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.

He tried it, but guessed the wrong tags

Back to the actual problem: create a servlet, implement doGet(), let it call the desired class and put the desired result in the desired scope, forward it to the desired JSP, let the JSP process the result the usual way using JSTL/EL. Map the sevlet in your web.xml and call it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic