• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

clarification for jsp code

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Sheriff
Posts: 67642
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic