当前位置:   article > 正文

springmvc 请求经过controller后静态资源无法访问的问题

请求的资源为controller层,不可用

经过RequestMapping(“xx”)后 转发请求时会在url里面附带地址,

导致访问静态资源文件失败,

 

解决办法是在 spring-mvc.xml文件中加上

<mvc:default-servlet-handler/>

<!-- 由于在web.xml中定义的url拦截形式为“/”表示拦截所有的url请求,
包括静态资源例如css、js等。所以需要在springmvc.xml中添加资源映射标 -->
<mvc:resources location="/static/js/" mapping="/*/static/js/**"/>
<mvc:resources location="/static/css/" mapping="/*/static/css/**"/>
<mvc:resources location="/static/fonts/" mapping="/*/static/fonts/**"/>
<mvc:resources location="/static/images/" mapping="/*/static/images/**"/>
<mvc:resources location="/static/lib/" mapping="/*/static/lib/**"/>



以及在web.xml里加上
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/static/*</url-pattern>
</servlet-mapping>

转载于:https://www.cnblogs.com/alexhere/p/7177249.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/946723
推荐阅读
相关标签
  

闽ICP备14008679号