javascript - SpringMVC如何正确配置静态资源(css,js,images)?

 妈妈的话CPC-8_645 发布于 2022-11-09 13:32

WEB.XML



    
  
      qiye
      org.springframework.web.servlet.DispatcherServlet
      
            contextConfigLocation
            /WEB-INF/qiye-servlet.xml
        
        1
  
 
  
      qiye
      /
  
  
  

qiye-servlet.xml



http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
   http://www.springframework.org/schema/beans     
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
     
    
    
        
        
    

我加上了
但是页面报404错误.
如果去掉 SpringMVC视图就正常.但是css文件,js文件,图片加载不出来.
http://127.0.0.1:28080/Qiye/j...
我这这样访问的 ,有错吗?

home文件夹下都是前端html

3 个回答
  • <mvc:default-servlet-handler/>

    这个确实很方便,但还是不建议使用,推荐使用静态资源映射标签

    <!--静态资源访问(缓存一周) -->
    <mvc:resources location="/images/" mapping="/images/**" cache-period="604800"/>
    <mvc:resources location="/js/" mapping="/js/**" cache-period="604800"/>
    <mvc:resources location="/css/" mapping="/css/**" cache-period="604800"/>
    2022-11-12 01:59 回答
  • 静态文件放在webapp目录下,设置过滤器或spring配置静态资源目录

    2022-11-12 01:59 回答
  • 把home文件夹挪到WebContent目录下就可以了。配置上

    <mvc:default-servlet-handler/>
    2022-11-12 01:59 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有