Mobile app version of vmapp.org
Login or Join
Sarah324

: Tomcat serving static content with directory listings I have Tomcat 7 configured to serve static contents from a directory: <Host appBase="webapps" name="localhost"> ... <Context

@Sarah324

Posted in: #Apache #Localhost #Tomcat #WebsiteDeployment

I have Tomcat 7 configured to serve static contents from a directory:

<Host appBase="webapps" name="localhost">
...
<Context docBase="/var/projectA/static" path="/projectA/" />
</Host>


This is available at localhost:8080/projectA/. Is it possible to somehow enable directory listings for this context?

I know it's possible to do this with Apache in front of Tomcat, but that's not what I'm looking for.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Sarah324

1 Comments

Sorted by latest first Latest Oldest Best

 

@Si4351233

Convert your directory /var/projectA/static to a simple application:


create a directory WEB-INF/
in WEB-INF/ create the file web.xml with this content:



<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app>
<servlet>
<servlet-name>DirectoryListing</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>DirectoryListing</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>



This way the directory listing is only active for your specified context and not global.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme