tijuvj
tijuvj

Reputation: 83

How to display server directory as tree in jsp?

I want to list contents of a server directory in JSP and also user to select one directory,so that if the user selects a directory then correct sub directories is displayed as hierarchical tree.

Knows how to get the name of directory and its sub-directories (using Java).Help me to find how this name is passed and implement in JSP.

Upvotes: 1

Views: 2403

Answers (4)

tijuvj
tijuvj

Reputation: 83

Find my solution using JQuery File Tree .

http://www.abeautifulsite.net/blog/2008/03/jquery-file-tree/

Upvotes: 1

coding_idiot
coding_idiot

Reputation: 13734

View is different from what you can get in server-side.

Step 1 Learn how to implement a javascript tree in your JSP

http://plugins.jquery.com/tag/tree/

Step 2 Then simply pass the tree variables from the server-side to construct the actual directory tree you're looking for.

Upvotes: 0

duffymo
duffymo

Reputation: 308763

You won't be able to list the contents of an entire server; perhaps just the directory structure in your Java web app context.

I'd recommend looking at a JavaScript widget library that provides a tree. Learn how to use it. Figure out how to write a servlet to get the File structure, load it into the JSON or other data format that the widget needs, and you're done.

You can't do it just with Java. You need something to let you render it in the browser.

Upvotes: 0

MadConan
MadConan

Reputation: 3767

I'm certainly not going to write the whole thing, but to address your specific points of

Knows how to get the name of directory and its sub-directories (using Java).

This has been done a million times here and elsewhere. Just build a list of files or file names recursively. You need to be careful of memory/stack overflow issues, so I recommend setting a maximum depth and file count.

Help me to find how this name is passed...

You could put the List<File> or List<String> into session or the request attributes.

... and implement in JSP.

That's for you.

Upvotes: 0

Related Questions