Tomcat does not serve static files

I am at the end of my rope on this. I am trying to get a super simple webapp and I can not get tomcat to have 404 static files.

  • I am using tomcat gradle plugin with tomcat version 7.0.39
  • My html file is in hey-world/src/main/webapp/index.html
  • My web.xml as follows:

     <servlet> <servlet-name>Resteasy</servlet-name> <servlet-class> org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher </servlet-class> <init-param> <param-name>javax.ws.rs.Application</param-name> <param-value>HeyWorldApplication</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>/static/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Resteasy</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> 

So, I thought this setting would map localhost:8080/hey-world/static/index.html to a file, but it's 404 every time. Is this a problem with some conventions in the gradle tomcat plugin?

+4
source share
1 answer

The URL patterns used in web.xml / servlet-mapping are often a little simplified. I think in your case, the / * template for Resteasy will work like a trick, so no other display really matters.

For debugging, I suggest that you completely remove the Resteasy servlet and see if you can put static files on the server using a custom URL with your mapping. If this works, enable Resteasy again, but to a different URL pattern (e.g. / Rest / *).

If this works, well then everything really works fine, it's just that URL-mapping for / * blocks something else from working.

The easiest solution is likely to be related to the default static server files (without matching) and will serve the rest of things from another URL.

Alternatively, use two web applications. One with the context root "/ static", one with the context root "/".

+3
source

Source: https://habr.com/ru/post/1484784/


All Articles