File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Tree view in a servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Tree view in a servlet?" Watch "Tree view in a servlet?" New topic

Tree view in a servlet?

Ann Toh
Ranch Hand

Joined: Jul 18, 2003
Posts: 45
can anyone tell me how to write a tree view in a servlet??
i hav gone to this website and i hav download its jar file but i do not know how to write it into a servlet. so can anybody tell me how??
Thanx in advance...

[ October 08, 2003: Message edited by: Michael Ernest ]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

This is the fifth time in the past week that you have posted this exact same question. If you are not getting answers to your question, it may be because: no one knows the answer, it cannot be done, or you are not framing the question with enough information for anyone to try and help you.
Repeated postings will not get you any better or faster answers. If you are not getting answers to your question, you should elaborate on what you are trying to do in the topic that you have already started.
And, using 'urgent' in your subject rather than a meaningful phrase will usually get your topic ignored by some of the best answerers in these forums. It's seen as rude -- sort of like trying to push ahead in line at the grocery store.
I'm not trying to be mean or anything, but you are not making effective use of these forums as a resource.

[Asking smart questions] [About Bear] [Books by Bear]
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
The following might help, even if not all of it is applicable to JavaRanch:

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
paul wheaton

Joined: Dec 14, 1998
Posts: 20972

Is your servlet going to be stateless?
Are you wanting one of those trees that's using the "+" and "-" stuff? Or, do you just want to show the whole tree?
It would seem that if you want to use a specific product, you would want the assistance of those folks, unless it is such a popular product that lots of other people use it (like tomcat or jboss).
Are you for sure using that product, or are you willing to try doing it from scratch?
Are you familiar with servlets and html in general?

permaculture Wood Burning Stoves 2.0 - 4-DVD set
Ann Toh
Ranch Hand

Joined: Jul 18, 2003
Posts: 45
Hi Paul Wheaton,
thanx for ur help...i want those trees to have "+" and "-". Actually, i want the tree to show a directory structure juz like the window explorer.
i would like to use the product to do my program, but if there is other better product, i would use that.
im quite new in servlets, im not so familiar with servlets yet..
Do u hav any idea on how to write trees in servlet??
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Seems to me what you want is better created using JavaScript - JavaScript can dynamically change the display on the user's browser WITHOUT going back to the server. There are tons of JavaScript resources on the net.
Once you have created a prototype page that does the display you want, then you can work on creating a page dynamically from a servlet or JSP.
Ann Toh
Ranch Hand

Joined: Jul 18, 2003
Posts: 45
can anybody tell me how to know whether the user has click one of the nodes in the tree?? i'm writing in a servlet prog to write into a jsp file.
thanx in advance...

[ October 10, 2003: Message edited by: Ann Toh ]
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8927

Ann Toh
Ranch Hand

Joined: Jul 18, 2003
Posts: 45
The program is what im currently doing. I write the program into a jsp file then i redirect it to the jsp file to display. Can anybody tell me how do i noe whether the user has click which node, and i need to display things that are related to the nodes that the user has juz click??
fos = new FileOutputStream("C:\\Tomcat 4.1\\webapps\\SDC1\\myfile.jsp");
// Connect print stream to the output stream
p = new PrintStream(fos);


p.println("<body bgcolor=\"#ECDFCE\" link=\"blue\" vlink=\"purple\" alink=\"red\" style=\"scrollbar-face-color:#F5DEB3; scrollbar-arrow-color:indianred; scrollbar-track-color : papayawhip; scrollbar-shadow-color:black; scrollbar-highlight-color:''; scrollbar-3dlight-color:#BC7E41; scrollbar-darkshadow-Color:maroon;\" >");
p.println("<table width=\"100%\">");
p.println("<td width=\"50%\">");

File parentNode = new File(dirName + "\\" + user);

if (parentNode.isDirectory())
File[] childNode = parentNode.listFiles();

String parentName = parentNode.getName();

p.println("<%@ taglib uri=\"taglib.tld\" prefix=\"tree\" %>");

p.println("<tree:createTree treePicture=\"images/folder_idle.gif\" nodePicture=\"images/item_doc.gif\" openPicture=\"images/folder_open.gif\" dhtml=\"true\">");
p.println("<tree:addNode code=\"<b>" + parentName + "</b>\">");

for (int i = 0; i < childNode.length; i++)
String fileInDir = childNode[i].getName();
String node = addnode.getCode();

if (childNode[i].isDirectory())


thanx in advance...

[ October 15, 2003: Message edited by: Ann Toh ]
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962

Ann, the taglibs can only be used in a JSP. If you write the taglib tags into the HTML document being sent to the browser, the browser will think "what the heck is this" and either display an error or simply ignore the unrecognized elements.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Ann Toh
Ranch Hand

Joined: Jul 18, 2003
Posts: 45
Hi Lasse Koskela,
i know that the taglib can only be in jsp file. In this program, i write the tree structure into a jsp file called myfile.jsp. The servlet will run the program and write it into myfile.jsp, after writing it to the myfile.jsp, the servlet will call myfile.jsp to display the tree. the program does work but there is one problem, that is how do i noe whether the user has click which nodes??
san jan

Joined: Sep 26, 2000
Posts: 24
One simple thing is make that '+' a html link or any other html element that has onclick functionality in javascript (if u can also use javascript).
I agree. Here's the link:
subject: Tree view in a servlet?
It's not a secret anymore!