467,911 Members | 1,406 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,911 developers. It's quick & easy.

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
  • viewed: 4000
Share:
3 Replies
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
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

Post your reply

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

Similar topics

3 posts views Thread by Steve Johnson | last post: by
1 post views Thread by googleo | last post: by
1 post views Thread by Srihari | last post: by
4 posts views Thread by Stephan Tobies | last post: by
3 posts views Thread by _DS | last post: by
1 post views Thread by David Hirschfield | last post: by
5 posts views Thread by hankypan1 | last post: by
8 posts views Thread by =?ISO-8859-1?Q?m=E9choui?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.