zsf_993113
敲代码泡妹可能吗
2019-03-20 22:25

springMVC项目跑起来却访问不了静态资源文件?

5
  • spring
  • java-ee

springmvc访问不了静态资源文件

<web-app>
  <display-name>Archetype Created Web Application</display-name>

  <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>*.html</url-pattern>
  </servlet-mapping>

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>loginIndex.jsp</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <filter>
        <description>字符集过滤器</description>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <description>字符集编码</description>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <!-- 路径映射 -->
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>*.html</url-pattern>
    </filter-mapping>

</web-app>

web.xml

<!-- 1.自动扫描包,实现支持注解的IOC  -->
    <!-- 自动扫描该包,使springmvc认为包下用了@Controller注解的类是控制器 -->
    <context:component-scan base-package="com.bi.controller" />
    <!-- 2.配置注解的处理器映射器和处理器适配器 -->
    <mvc:annotation-driven />
    <!-- 3.Spring MVC不处理静态资源  -->
    <mvc:default-servlet-handler/>

    <mvc:resources mapping="/assets/**" location="/WEB-INF/assets/" cache-period="31536000"/>
    <mvc:resources mapping="/images/**" location="/WEB-INF/images/" cache-period="31536000"/>
    <!-- 4.配置内部视图解析器 -->
    <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>

spring.xml
访问不了文件
报错信息
尝试过,在servlet加默认的方式,不行。
是不是哪里还有问题,或者是页面写法有问题?

<link rel="stylesheet" href="assets/css/bootstrap.min.css">
    <link rel="stylesheet" href="assets/css/font-awesome.min.css">
    <link rel="stylesheet" href="assets/css/themify-icons.css">
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答

为你推荐

换一换