Tomcat: does not add trailing "/" when searching for a directory

I deployed the .war archive to Tomcat 7.0.22 (Java 1.6, MacOS Lion). The war is called "myapp.war", so Tomcat serves http: // localhost / myapp (extending the war to / webapps / myapp). This is the usual behavior.

When accessing the URL corresponding to the directory, it must add "/". For static files (.css, .js ..) to work correctly, it is necessary, but so far it works with examples of sites that come with Tomcat (for example, visiting http://127.0.0.1:8080/examples unexpectedly migrates to http://127.0.0.1:8080/examples/ ), on my site tomcat does not add "/", which leads to a failure of the search for static files. When manually calling localhost:8080/myapp/ (<- I add a slash) everything works fine.

What should be? Keep in mind that I did not touch on Tomcat settings, I am just experimenting with what comes directly from the Apache ZIP file!

thanks

+4
source share
1 answer

First, you need to explain your situation more. As @mico said, this solution:

 <filter> <filter-name>Jersey Filter</filter-name> <filter-class>com.sun.jersey.spi.container.servlet.ServletContainer</filter-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>your package name(s)</param-value> </init-param> <init-param> <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name> <param-value>.*\.jsp|.*\.css|.*\.png|.*\.js|.*\.gif|.*\.jpg</param-value> </init-param> </filter> <filter-mapping> <filter-name>Jersey Filter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> 

The idea of ​​a solution based on:

defining a ServletContainer jersey as a filter instead of a servlet

You can read more here: http://jersey.576304.n2.nabble.com/Tomcat-trailing-slashes-and-welcome-files-td4684494.html

It says that: If you have a '/*' mapping, then Tomcat won't redirect

One more thing: you should see how tomcat logs your request and solves the main problem.

+1
source

All Articles