472,328 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

JSP Tree Structure

Hi,

I am struggling with the following problem. Can somebody pls help me?.

I have a file name and have a folder File f1= new File("path of the folder");. The folder is a complicated folder structure i.e. contains various files and sub folders which contains further subfolders etc. I want to show the whole folder structure(like tree structure). But, the following code shows only the "WebContent" structure.Please find below the following code:

Expand|Select|Wrap|Line Numbers
  1. File f1 = new File("D:/eclipse/workspace/cms/WebContent");
  2. File[] contents = f1.listFiles();
  3. for (int j=0; j<contents.length; j++) 
  4. {
  5.  
  6.     if(contents[j].isDirectory())
  7.     {
  8.         out.println("Directory : "+contents[j].getName()+"<br/>");
  9.     }
  10.     else
  11.     {
  12.         out.println("Files :"+contents[j].getName()+"<br/>");
  13.     }
  14.  
  15. }
  16.  

If anybody knows the answer, please let me know....

Thanks in Advance,



V. Prasath
Apr 8 '09 #1
3 4324
chaarmann
785 Expert 512MB
make a method from your source, pass as parameter the path (that what you hardcoded in f1), and then call your method recursively. That means, if it's a directory, call yourself with new path parameter, made up of old path+current directory name.
Apr 8 '09 #2
Hi,

Thanks for your reply....

How can i make a method in jsp? I don't know how to make a method for this kind of code. Please let me know if you know....


Thanks in Advance.
Apr 8 '09 #3
chaarmann
785 Expert 512MB
Ok, herewith I let you know that I know. :-)

Classes and methods are the basics of Java programming. If you don't know how to define a method with parameters, then do Sun's Java tutorial first to get the basic knowledge.

If you know how to write a method, but you don't know how to do that in JSP, read the jsp tutorials. For a quick start, I'll give you an example:
Expand|Select|Wrap|Line Numbers
  1. <%!
  2. private String printFolder(String fullFolderName)
  3. {
  4.  return "printFolder was called with: " + fullFolderName;
  5. }
  6. %>
  7.  
  8. Now I am calling my method. It returns:
  9. <%= printFolder("root") %>
  10.  
Apr 8 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Steve Johnson | last post by:
Been banging my head on this for two days now. Hope someone can help! My test program below is in the form of a single JSP, with a Node class...
2
by: ragha | last post by:
Dear friends I am emulating thr tree structure mentioned in the article http://www.15seconds.com/issue/010921.htm I have succesfully created...
1
by: googleo | last post by:
Hi, in my application I want to handle and store data in a hierarchic data structure. For example: persons who manage houses; houses have...
1
by: Srihari | last post by:
I'm trying to develop a tree structure using javascript. The node values of the tree are generating from a mysql table depending on login. The tree...
4
by: Stephan Tobies | last post by:
Hi everyone, I am looking for a good data structure that could be used to represent families of trees with shared sub-trees and copy-on-write...
3
by: _DS | last post by:
Problem with mapping a directory tree to a tree control: It takes a while to recurse subdirs and map them to nodes. This is solved in some books...
1
by: David Hirschfield | last post by:
I've written a tree-like data structure that stores arbitrary python objects. The objective was for the tree structure to allow any number of...
5
by: hankypan1 | last post by:
Hi All, I need a tree data structure for my application. It is the non -cyclic simple tree where i can have any number of children node and each...
8
by: =?ISO-8859-1?Q?m=E9choui?= | last post by:
Problem: - You have tree structure (XML-like) that you don't want to create 100% in memory, because it just takes too long (for instance, you...
0
by: mac | last post by:
I found that with memory allocating techniques used nowadays (addresses alignment, eg. on 32bit machines) one can detect loops in a tree structure...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.