3 Replies - 5278 Views - Last Post: 12 March 2012 - 01:54 AM

#1 AngelRaj  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 01-December 11

Choosing a Folder instead of a file

Posted 18 January 2012 - 09:35 PM

Hello everyone,

I would like to develop an application which chooses a folder and display the name of all files in that folder.

How can I achieve this?

The jsp or html page should let me to select the folder and I should have a servlet to do the next action.

Can anyone please give me an idea about this? Is there any API?
Is This A Good Question/Topic? 0
  • +

Replies To: Choosing a Folder instead of a file

#2 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1156
  • View blog
  • Posts: 2,538
  • Joined: 05-May 05

Re: Choosing a Folder instead of a file

Posted 20 January 2012 - 04:44 PM

Utilize the Java's File API. In your Servlet, get a list of the files you want to present to your user and render them into the HTML. Make them links with POST parameters, so you can get the directory that the user wants to explore next. I went ahead and made a DirectoryServlet to give you some idea of how it could be done. This servlet is only for files in your web root, although it could easily be adapted to display files outside it. File downloads outside your web root must be initiated from inside servlet code, which is more work, but your files won't be publicly accessible. DirectoryServlet is something you might find as a part of the web interface to a public code repository.

I saw your other post with a Javascript snippet. If your going to use an AJAX-based solution, you don't have to change the servlet. All you need to do is extract the anchor tags from the response html, which I'm sure a parser exists for. For each anchor tag, extract the inner html, display that in your combo box. Save the value of href in a map, which you'll use in your next asynchronous call.

This post has been edited by blackcompe: 20 January 2012 - 04:54 PM

Was This Post Helpful? 0
  • +
  • -

#3 AngelRaj  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 01-December 11

Re: Choosing a Folder instead of a file

Posted 11 March 2012 - 10:42 PM

I apologize for the delay in reponding back as I was busy with some other project.

Thanks Ryan, your Directory Servlet helped me out. It sorted both of my issues.. Thank you so much :smile2:
Was This Post Helpful? 0
  • +
  • -

#4 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1156
  • View blog
  • Posts: 2,538
  • Joined: 05-May 05

Re: Choosing a Folder instead of a file

Posted 12 March 2012 - 01:54 AM

Awesome. Glad it got some use.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1