SpringMVC拦截配置

1.SpringMVC拦截器的配置

<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 "或其它的区别

  1. ”/“表示拦截所有请求,包括静态文件,如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“结尾的请求,不会拦截静态文件






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值