Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
116 views
in Technique[技术] by (71.8m points)

java - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...