Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I list all the files in folder on tomcat?

I have got a folder with many excel documents in it on tomcat and i want those files to be available when i got go the that folder's url in the browser (eg http;//localhost:8080/myfolder)

at the moment when i try to access a folder i get a 404 error. by if i try to access a file that is in that folder, it works.

like image 669
code511788465541441 Avatar asked Aug 15 '11 17:08

code511788465541441


People also ask

How do I access Tomcat files?

In order to access your system files from browser using tomcat,you have to create context path for the system files in tomcat server. xml like below. Now you can see the files in your browser.By typing the below url.

Where are Tomcat files located?

By default, these files are located at TOMCAT-HOME/conf/server. xml and TOMCAT-HOME/conf/web.

What does files list path Dir do?

list() returns the array of files and directories in the directory defined by this abstract path name. The method returns null, if the abstract pathname does not denote a directory.

Where does Tomcat store uploaded files?

By the sounds of it, your application is storing files in the current directory of the JVM, which happens to be the "bin" directory when you launch the web server via NetBeans. If so, you will find them, in whatever the current directory is when Tomcat is launched as a windows service.


1 Answers

The DefaultServlet of Tomcat is by default configured to not show directory listings. You need to open Tomcat's own /conf/web.xml file (look in Tomcat installation folder), search the <servlet> entry of the DefaultServlet and then change its listings initialization parameter from

<init-param>     <param-name>listings</param-name>     <param-value>false</param-value> </init-param> 

to

<init-param>     <param-name>listings</param-name>     <param-value>true</param-value> </init-param> 

Keep in mind that this affects all folders of your webapp. If you want to enable this for only an individual folder, you've got to write some Servlet code yourself which does the job with help of the java.io.File API in servlet side to collect the files and some bunch of HTML/CSS in JSP side to present it in a neat fashion.

like image 156
BalusC Avatar answered Sep 24 '22 02:09

BalusC