File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes clarification for jsp code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "clarification for jsp code" Watch "clarification for jsp code" New topic
Author

clarification for jsp code

shyamkumar bopannachengalaiah
Ranch Hand

Joined: Dec 30, 2008
Posts: 100
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

Joined: Jan 10, 2002
Posts: 61769
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: clarification for jsp code