J.Joe J.Joe - 1 year ago 185
Java Question

About Spring MVC can't resolve static resource in the WEB-INF

My WEB structure like this :
enter image description here

My Spring-MVC config like this :

<mvc:resources location="/WEB-INF/static/" mapping="/static/**" />

And my servlet config like this :

<!-- Servlet Dispatcher -->
<!-- 加载 -->
<!-- 配置启动延时 -->

When config like that the web project can't resolve the static resrouce , but if i change the url-pattern to '/'


The web can resolve it .

I want to know why and there are other way to resolve the static resource if the url-pattern is not the '/' , thanks (●'◡'●)

Answer Source

If you are using suffix mapping (*.something), then Spring uses just the first part (without the suffix). This is interpreted by spring as just /index in your url-pattern (without the suffix).

And hence you get 404.

Please find the documentation of Spring UrlPathHelper#getPathWithinServletMapping for better description what is being used in the mapping process:

To fix your problem in the current servlet mapping

servlet mapping = "/*.html"; request URI pattern = "/a.html"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download