File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Select Directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Select Directory" Watch "Select Directory" New topic
Author

Select Directory

Niall Loughnane
Ranch Hand

Joined: Dec 07, 2006
Posts: 208
Hi,

Anyone know how to either in html or in JSP how to select a directory,

what i'm trying to do is to let the user press a button a web page and a pop-up dialog comes up where the user can select a directory to upload files from,

Any ideas - Thanks in advance,

Niall
Shashi Prakash
Ranch Hand

Joined: Mar 28, 2007
Posts: 40
The file which suer is going to uplaod will be uploaded at server. right??

If yes then how can a user who is browsing can access your server or so...I

guess you should handle this directory oath from backend...


Thanks,<br />Target Scwcd<br />SCJP 1.4
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Here's a little HTML form that allows the user to select a file and upload it:This takes care of allowing a user to select a file from any directory. If you've ever attached a file to an e-mail in Hotmail or any other web e-mail program, they all use something like this only prettier.
Niall Loughnane
Ranch Hand

Joined: Dec 07, 2006
Posts: 208
Thanks for the sample code

but

what im trying to do is to let the user press a button, perhaps "select directory", and a pop up screen comes up and the user can select a directory where there are multiple files that the user wants to upload,

the html code is brilliant for a single file but what happens if there is multiple files in a directory that the user wants to upload?

Thanks in advance
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

The user can only upload one file per "input type=file" element. You could provide four of them, then the user could upload four files. HTML doesn't have anything fancy like what you are proposing.
Niall Loughnane
Ranch Hand

Joined: Dec 07, 2006
Posts: 208
sound Paul

but is it possible by JSP?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

All the browser sees is HTML. It makes no difference whether you use JSP or something else to generate that HTML.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

It is possible to write this yourself using Javascript on the client and Java on the server. For the client, use Javascript to create your popup.

For the server side of things, look at the java.io.File class to learn how to read directory structures from within Java.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Select Directory