SpringMVC拦截配置
2015-09-02 15:41
471 查看
1.SpringMVC拦截器的配置
”/“表示拦截所有请求,包括静态文件,如js文件,css文件,图片文件等,这时,要想加载静态文件,需要在springmvc配置文件(如:srpingMVC-servlet.xml)中进行配置
,配置如下,粗体部分:
2.”*.do “则表示拦截器只会拦截以”*.do“结尾的请求,不会拦截静态文件
<span style="font-family:Microsoft YaHei;"><!-- Spring MVC配置 --> <servlet> <servlet-name>spring-mvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 可以自定义servlet.xml配置文件的位置和名称,默认为WEB-INF目录下,名称为[<servlet-name>]-servlet.xml,如spring-servlet.xml--> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:com/bdqn/resources/spring/spring-mvc.xml</param-value> </init-param> <!-- 是启动顺序,1表示启动容器时初始化该Servlet --> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring-mvc</servlet-name> <!-- /是拦截所有请求,*.do表示拦截所有以.do结尾的请求 --> <url-pattern>/</url-pattern> </servlet-mapping></span>2.“ / ”和“ *.do "或其它的区别
”/“表示拦截所有请求,包括静态文件,如js文件,css文件,图片文件等,这时,要想加载静态文件,需要在springmvc配置文件(如:srpingMVC-servlet.xml)中进行配置
,配置如下,粗体部分:
<span style="font-family:Microsoft YaHei;"><?xml version="1.0" encoding="UTF-8"?> <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:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" 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 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd "> <!--注解扫描包,主要扫描的是controller --> <context:component-scan base-package="com.bdqn.controller"/> <!-- 添加注解驱动(开启注解) --> <mvc:annotation-driven/> <strong><!-- 静态资源的访问 --> <mvc:resources location="/jsPlugins/" mapping="/jsPlugins/**"/> <mvc:resources location="/images/" mapping="/images/**"/> <mvc:resources location="/scripts/" mapping="/scripts/**"/> <mvc:resources location="/styles/" mapping="/styles/**"/> <mvc:resources location="/seip/" mapping="/seip/**"/> <mvc:resources location="/upload/" mapping="/upload/**"/></strong> <!-- 定义视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/view/" /> <property name="suffix" value=".jsp" /> </bean> <!-- 上传文件配置 、多了个多请求的处理、目的是为了支持多文件上传 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="utf-8" /> <property name="maxUploadSize" value="10485760000" /> <property name="maxInMemorySize" value="40960" /> </bean> <!-- 用来处理json格式转换 --> <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> </list> </property> </bean> </beans></span>
2.”*.do “则表示拦截器只会拦截以”*.do“结尾的请求,不会拦截静态文件
相关文章推荐
- java工厂设计模式
- JAVA操作Excel文件
- 从源码角度分析native层消息机制与java层消息机制的关联
- 注释驱动的 Spring cache 缓存介绍
- MyEclipse下配置mysql驱动的方法
- apktool + eclipse 动态调试无源码apk
- annotation-driven
- Java学习之排序
- MyEclipse 关闭debug
- Spring中的AOP——在Advice方法中获取目标方法的参数
- 集合框架-工具类(java基础)
- Spring3.1 Cache注解
- 成为更高效的Java开发人员要用到的开发工具
- Spring Cache 介绍
- Java轻量级锁
- Java NIO:NIO概述
- databus编译: Execution failed for task ':databus-core:databus-core-impl:compileJava'.
- J2EE、J2SE、J2ME、JDK各个击破(概念级)
- Java 字符串和时间互相转化 +时间戳
- Java NIO:浅析I/O模型