且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在tomcat上列出文件夹中的所有文件?

更新时间:2022-03-10 23:08:33

DefaultServlet默认情况下,的Tomcat配置为不显示目录列表。您需要打开Tomcat自己的 /conf/web.xml 文件(查看Tomcat安装文件夹),搜索< servlet> 输入 DefaultServlet ,然后从

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>

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

请注意,这会影响您的webapp的所有文件夹。如果你只想为一个单独的文件夹启用它,你必须自己编写一些 Servlet 代码,它可以在 java的帮助下完成这项工作。 .io.File servlet端的API用于收集JSP端的文件和一些HTML / CSS,以便以简洁的方式呈现它。

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.