标...">

<mvc:resources> 标签的使用

作者: lovePython | 来源:发表于2015-08-19 11:10 被阅读7784次

spring mvc 的<mvc:resources mapping="***" location="***">标签是用来进行配置静态资源访问的。

<servlet>  
    <servlet-name>springMVC</servlet-name>  
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
    <load-on-startup>1</load-on-startup>  
</servlet>  
  
<servlet-mapping>  
    <servlet-name>springMVC</servlet-name>  
    <url-pattern>/</url-pattern>  
 </servlet-mapping>  

spring mvc会在WEB-INF下扫描一个springMVC-servlet.xml文件,如果没有提供,将会报一个文件找不到的异常。
由于spring mvc拦截了所有请求

<servlet-mapping>
    <servlet-name>springMVC</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

访问静态资源文件的时候也会被DispatcherServlet拦截,而且会进行一系列复杂的处理,所以对静态资源必须进行特殊的配置。

<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"    
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
    xmlns:mvc="http://www.springframework.org/schema/mvc"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd     
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">     
  
    <mvc:resources mapping="/javascript/**" location="/static_resources/javascript/"/>  
    <mvc:resources mapping="/styles/**" location="/static_resources/css/"/>  
    <mvc:resources mapping="/images/**" location="/static_resources/images/"/>  
    <mvc:default-servlet-handler />  
      
      
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        <property name="prefix" value="/WEB-INF/views/"/>  
        <property name="suffix" value=".jsp"/>  
    </bean>  
  
</beans>  

相关文章

  • <mvc:resources> 标签的使用

    spring mvc 的标...

  • 第二篇

    2.在HTML里打多个空格需要使用标签,一般标签有<;=<,> => =空格回车标签有...

  • HTML 4.01版

    复习 排版标签:p hr br pre 字体标签: 转义字符:<> 清单标签:有序列表...

  • 2019-03-20第二天

    常用的标签有 标题标签H系列 段落标签p系列 换行标签br 横线标签hr 常用的实体有<<>> © 空...

  • 2019-05-27第二天

    常用的标签有 标题标签H系列 段落标签p系列 换行标签br 横线标签hr 常用的实体有<<>> © 空...

  • jQuery html函数

    jQuery 的html()函数自动把不安全的标签 标签和&符号escape了 script标签被转换成 & lt...

  • 使用express搭建在线便利贴

    大致思路: 前端:整体使用瀑布流布局,拥有对便利贴的增删改查功能,对标签的拖拽功能等。使用 MVC 设计模式,实现...

  • 转载:mvc、mvp、mvvm使用关系总结

    标签:android/架构 MVC MVC全名是Model View Controller,是模型(model)-...

  • <meta>标签的使用

    控制显示区域各种属性: width – viewport的宽度 heig...

  • [spring]applicationContext.xml-m

    紧接着上文,我们来学习mvc标签。 Spring版本:4.3.14。 6.mvc 命名空间   mvc命名空间内的...

网友评论

  • blowyourheart:spring的东西还是要多了解
  • blowyourheart:原来spring会默认扫描一个叫 ${servlet-name}-servlet.xml的问题,了解了。

本文标题:<mvc:resources> 标签的使用

本文链接:https://www.haomeiwen.com/subject/dfhgqttx.html