The solution which is given by Mr. farzad maybe work
when the files are under your web application
directory and if you don't use war or ears because
you can not access out of the web application
directory where you normally place your jsps htmls or
images. So if you want to really create a file
accessing facade for your web application which allows
to browse a directory and it subdirectory you must
create a servlet which facilities this purpose you can
define your root directory as context-parameter in the
web.xml and then the developed servlet (which you must
write it) use these parameter to find the real
location of the files and directory.
First your servlet must show the directory content of
the specified root directory by means of java.io.File
class facilities(especially its list() method) and
provide a link for each item in the directory (you can
add more images if you want to have more user-friendly
UI bit your servlet can generate a simple list of
links)
Every time that user selects a file from this page a
new GET request must be sent to the servlet which
contains the relative path of the selected file
The servlet then must use this relative path in
combination of the root path specified in web.xml to
locate the real location of the file or directory
Then you can use File class facilities to determine
whether use selected a folder or file <<java.io.File
's isDirectory() method)(Keep in mind that you don't
need to provide the type of case in your page as its
link parameter because system can found it only by
means of its name!)
if the selected case is a file you can use the
HttpServletResponse facility like getOutputStream to
write the content of it in the response object but
before writing the content you must set the content
type of the response properly by any means that you
can support (for example by using the extension of the
file or self detection that java utilities provide).
And in the case of the directories you can simply list
the content of it again by means of File facilities as
described above for showing root content.