How to list files in a directory and make them downloadable

    I have a JSP on which Iam displaying a link (eg :Display All Files) which upon clicking calls a struts action class which does a Dir read and does a listing of all the files .
I want to display these files as links and when clicked I want the download window to pop up so that the user can download the file.
   Any  idea how I can do this in Java ?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nothing special just generate an html page that contains links to the files like
<a href="file1 path">download file1</a>
<a href="file2 path">downloda file2</a>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You'll need a servlet that is able to read the file from the local hard disk and send it to the client. If your servlet i called 'GetFile', then you would add links in your JSP page somethign like the folloiwng:

<a href="GetFile?path=1.txt">file1</a>
<a href="GetFile?path=2.txt">file1</a>

Depending on how your server is setup, you might find that your servlet cant access the local file store, in which case the best solution would be to place your files in a database for the servlet to access.

Either way, the servlet will extract the path from the JSP paramater posted to it, open the file based on that path, then send the file found back to the client.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.