配置:<mvc:default-servlet-handler/>
1>静态资源:除了Servlet、Controller之外的资源,如:js,css,png,html等
2>当请求静态资源:...xx/xx/xx.js,...xx/xx/xx.css,...xx/xx/xx.png等
如上请求会逐步回溯到【/】,即会进入DispatcherServlet,则会有HanderMapping
取查找Hanler,自然无法找到。此时如果没有如上配置,则404.
3>如果有如上配置,则在项目中会自动注册【/**】的一个handler,且此handler
会在最后映射请求,如果是项目中存在指定的静态资源,则会转向静态资源。
XML :
<?xml version="1.0" encoding="utf-8"?>
<!-- xmlns:xml name space 是每一个schema唯一标识 -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> <!-- 扫描所有控制器中的注解 -->
<context:component-scan base-package="com.c61.controller"></context:component-scan>
<!--
MVC中基于注解开发,导入注解驱动
<mvc:annotation-driven/>
-->
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<!-- 支持的格式:application/json -->
<value>application/json</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- 视图解析器:解析视图
控制器方法的返回值,会被视图解析器捕获。"abc"
根据捕获的内容,解析出一个视图地址:/abc.jsp
-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!--
静态资源:html,js,css,jpg
访问404 解决
-->
<mvc:default-servlet-handler/> <!-- 声明异常处理器 -->
<bean class="com.c61.ex.resolver.MyExceptionResolver"></bean> <!-- 拦截器配置 -->
<!--
/a/b
inter1
inter2
拦截顺序:先配置先拦截
具体顺序:pre1==pre2==contorller==post2==post1==after2==after1
-->
<mvc:interceptors>
<mvc:interceptor>
<!-- 定义要拦截的路径
/inter/* 匹配 /inter/a /inter/b inter/cssdafasfsafs
不能匹配/inter/a/b
/inter/** 匹配 /inter/a /inter/xxsjaflsajf /inter/a/b/c/e/d/xxxcvx
*注意:exclude-mapping不能单独使用。要配合mapping使用
:在mapping匹配的范围中排除一些个。
-->
<mvc:mapping path="/inter/**"/>
<mvc:mapping path="/a/b"/>
<mvc:mapping path="/c/**"/>
<mvc:exclude-mapping path="/inter/test/*"/>
<mvc:exclude-mapping path="/c/b/**"/>
<!-- 声明拦截器 -->
<bean class="com.c61.interceptor.MyInterceptor"/>
</mvc:interceptor>
<mvc:interceptor>
<!-- 定义要拦截的路径 -->
<mvc:mapping path="/inter/test"/>
<!-- 声明拦截器 -->
<bean class="com.c61.interceptor.MyInterceptor2"/>
</mvc:interceptor>
</mvc:interceptors>
<!-- 声明文件上传解析器
注意:此解析器,id必须为:multipartResolver
-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 最大允许的上传大小 byte -->
<property name="MaxUploadSize" value="2097152"></property>
</bean>
<!--
注册,验证码生成器
-->
<bean id="captcha" class="com.google.code.kaptcha.servlet.KaptchaExtend">
<constructor-arg>
<props>
<!-- 是否有边框 边框颜色 边框粗细 -->
<prop key="kaptcha.border">no</prop>
<prop key="kaptcha.border.color">105,179,90</prop>
<prop key="kaptcha.border.thickness">20</prop>
<prop key="kaptcha.textproducer.font.color">black</prop>
<prop key="kaptcha.image.width">200</prop>
<prop key="kaptcha.image.height">50</prop>
<prop key="kaptcha.textproducer.font.size">40</prop>
<prop key="kaptcha.session.key">code61</prop>
<prop key="kaptcha.textproducer.char.length">4</prop>
<prop key="kaptcha.textproducer.font.names">Arial,Courier</prop>
<!-- <prop key="kaptcha.background.clear.from">black</prop>
<prop key="kaptcha.background.clear.to">255,0,0</prop> -->
</props>
</constructor-arg>
</bean>
</beans>

啦啦啦

SpringMVC -- 梗概--源码--贰--静态资源的访问问题的更多相关文章

  1. SpringMVC -- 梗概--源码--贰--下载

    1.配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version=&qu ...

  2. SpringMVC -- 梗概--源码--贰--上传

    1.配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version=&qu ...

  3. SpringMVC -- 梗概--源码--贰--拦截器:Interceptor

    附:实体类 1.配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app versi ...

  4. SpringMVC -- 梗概--源码--贰--异常管理

    附:实体类 Class : User package com.c61.entity; import java.text.SimpleDateFormat; import java.util.Date; ...

  5. SpringMVC -- 梗概--源码--贰--RestFul收参(了解) @PathVariable

    1>定制方式: //如下两个路径都可以访问到如下方法,请求路径不同,则name61和pwd61匹配到的值不同 //http://localhost:8989/appname/ful/lime/1 ...

  6. SpringMVC -- 梗概--源码--贰--mvc:annotation-driven

    1>在springMVC的处理流程中,有两个重要组件:HandlerMapping和HandlerAdapter 分别负责解析Handler和执行Handler 2>如果配置了<mv ...

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

    经过RequestMapping(“xx”)后 转发请求时会在url里面附带地址, 导致访问静态资源文件失败, 解决办法是在 spring-mvc.xml文件中加上 <mvc:default-s ...

  8. SpringMVC -- 梗概--源码--壹--springMVC json处理

    附:实体类 Class : User package com.c61.entity; import java.text.SimpleDateFormat; import java.util.Date; ...

  9. SpringMVC -- 梗概--源码--壹--数据传递

    附:实体类 Class : User package com.c61.entity; import java.text.SimpleDateFormat; import java.util.Date; ...

随机推荐

  1. solr报错 ERROR SolrDispatchFilter null:ClientAbortException: java.net.SocketException: Broken pipe 原因是nginx截断了请求

    [root@localhost nginx]# lltotal 36drwx------. 2 www root 4096 Aug 13 13:25 client_body_tempdrwxr-xr- ...

  2. Hibernate注解方式一对多自关联关系映射

    MySQL版数据库表结构   DROP TABLE IF EXISTS SYS_DICT_ITEM; CREATE TABLE SYS_DICT_ITEM( ITEM_CODE ) NOT NULL, ...

  3. python获取上一个月第一天0点的unix时间戳

    这两天做统计,需要用到当月第一天0点0分0秒的unix timestamp,上个月第一天0点的unix时间戳,三个月前月第一天的0点的Unix时间戳,六个月前当月第一天的0点的Unix时间戳,现在整理 ...

  4. MFC函数——CWnd::OnCreate

    CWnd::OnCreate afx_msg int OnCreate( LPCREATESTRUCT lpCreateStruct ); 返回值: OnCreate必须返回0以继续CWnd对象的创建 ...

  5. node学习笔记3——文件操作fs

    文件操作关键字: http('fs') ——  请求 node 里面的 http 模块 readFile ——  读文件,参数包括 文件名,回调函数 writeFile ——  写文件,参数包括 文件 ...

  6. Union和Union All的区别[转]

    来源:http://blog.csdn.net/wanghai__/article/details/4712555/ 假设我们有一个表Student,包括以下字段与数据: drop table stu ...

  7. Linux中的绝对路径和相对路径

    一.介绍 1,文件路径 什么是文件的路径? 答:这个文件存放的地方,可以联想为 文件的“家”. 在Linux中,存在着绝对路径和相对路径 绝对路径:路径的写法一定是由根目录 / 写起的,例如 /usr ...

  8. Unity------Unity 脚本基类 MonoBehaviour 与 GameObject 的关系

    Unity 脚本基类 MonoBehaviour 与 GameObject 的关系 标签: unity脚本 2017-03-27 12:55 395人阅读 评论(0) 收藏 举报  分类: Unity ...

  9. (https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014550004)Topic: Caught java.io.CharConversionException. ERRORCODE=-4220, SQLSTATE=null

    270002WDPN                                            3 Posts                             0 people l ...

  10. hibernate 中的session和事务(Transaction)

    在使用hibernate开发时,遇到最多的就是session与事务,那么他们两个有什么关系呢?下面我来抛砖引玉: 1.session是hibernate中的以及缓存机制,是用来对数据进行增删改查的一个 ...