This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Retrieving a directory listing from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Retrieving a directory listing from JSP" Watch "Retrieving a directory listing from JSP" New topic
Author

Retrieving a directory listing from JSP

Michael Arnett
Ranch Hand

Joined: Mar 22, 2001
Posts: 65
Hi all,
simply put is this possible from a specific object (ie Directory or File Object) from within JSP? I realize there are ways of doing it with Runtime object and "ls" / "dir", but I was wondering if there was any "cleaner" way than parsing the returning stream from these processes. Thanks in advance!
-MLA

Sun Certified Programmer for the Java 2 Platform 1.4
Sam Dalton
Author
Ranch Hand

Joined: Jul 26, 2001
Posts: 170
I would have thought you could do this from JSP exactly the same way as you can from a Java App. Create a new java.io.File object (new File (path)), call the listFiles method and use the returned array of files to print out the names (through the use of File.getPath() or such like.
Not sure on the directories that you will be able to see. Give it a go and see.
S


<a href="http://www.samjdalton.com" target="_blank" rel="nofollow">Sam Dalton</a>,<br />Co-author of [http://www.amazon.com/exec/obidos/tg/detail/-/1590592255/qid=1068633302//ref=sr_8_xs_ap_i0_xgl14/104-4904002-9274339?v=glance&s=books&n=507846]Professional JSP 2.0[/URL] (October 2003)<br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/1861007701/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional SCWCD Certification</a><br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/186100561X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional Java Servlets 2.3</a>
Trevor Dunn
Ranch Hand

Joined: Jun 13, 2001
Posts: 84
You can definately do this is jsp, the way Sam has described. I have done it.
Trevor
SAFROLE YUTANI
Ranch Hand

Joined: Jul 06, 2001
Posts: 257
Sure, you can do this, but the directories that you will see will be from the server that the JSP is running. You wont be able to see the client's directory structure since the JSP is compiled and executed on the server, so dont waste your time if this is your intention.
SAF
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieving a directory listing from JSP
 
Similar Threads
getting different session ids from jsp to servlet
how to know the directory from which a jsp was requested
classpath problem..
Creating an EJB from Active Directory
Tomcat, JSP and Applet