1. org.springframework.web.servlet.DispatcherServlet

所在jar包:

    <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>

默认配置文件:

  DispatcherServlet.properties

上下文:

  该DispatcherServlet默认使用WebApplicationContext作为上下文。

2. DispatcherServlet的作用:

  DispatcherServlet是前端控制器设计模式的实现,提供Spring Web MVC的集中访问点,而且负责职责的分派,主要负责流程的控制。

  对应的是 controller 级别的配置,作用范围是控制层上下文。

3. DispatcherServlet怎么配置

  servlet-name :随便取。这里配置成[test]。Spring默认配置文件为"/WEB-INF/[servlet名字]-servlet.xml"。

  load-on-startup : web.xml中可配置多个servlet。 load-on-startup可指定在系统启动时按顺序加载servlet。

  url-pattern :表示哪些请求交给Spring Web MVC处理。此处会处理所有URI为"appName/test/*"的请求。

    <!--Spring view分发器-->
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/test/*</url-pattern>
</servlet-mapping>

4. [servlet名字]-servlet.xml里面的配置

4.1 mvc:annotation-driven

  <mvc:annotation-driven />

为什么要配置annotation-driven:

  <mvc:annotation-driven />注册了Spring MVC分发请求到控制器所必须的DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter实例。
如果没有<mvc:annotation-driven/>,那么所有的Controller可能就没有解析。

4.2 context:component-scan

    <context:component-scan base-package="com.test.web.controller" />

context:component-scan又干了啥:

a). 有了<context:component-scan>,另一个<context:annotation-config/>标签根本可以移除掉,因为已经被包含进去了。
b). <context:component-scan>提供两个子标签:<context:include-filter>和<context:exclude-filter>各代表引入和排除的过滤。
c). spring会自动去扫描base-package下面或者子包下面的Java文件,如果扫描到有@Component @Controller@Service等这些注解的类,则把这些类注册为bean。

4.3 mvc:interceptors

<mvc:interceptors>
<bean class="com.test.web.MyInteceptor" />
</mvc:interceptors>

拦截器,拦截所有url。

心血来潮,稍微研究了一下DispatcherServlet。所知有限,这里就不介绍更多。

以下为所有参考的文章:

第三章 DispatcherServlet详解 ——跟开涛学SpringMVC
http://jinnianshilongnian.iteye.com/blog/1602617

web.xml配置文件中的servlet和servlet-mapping
http://blog.csdn.net/u013815649/article/details/50435819

使用@Controller注解为什么要配置<mvc:annotation-driven />
http://blog.csdn.net/jbgtwang/article/details/7359592

spring mvc拦截器和<mvc:annotation-driven />的详解
http://www.cnblogs.com/yangzhilong/p/3725849.html

Spring组件扫描<context:component-scan/>使用详解
http://www.cnblogs.com/maybo/p/5189516.html

<context:component-scan>使用说明
http://blog.csdn.net/chunqiuwei/article/details/16115135

Spring MVC 教程,快速入门,深入分析(推荐阅读)

http://elf8848.iteye.com/blog/875830

web.xml配置DispatcherServlet (***-servlert.xml)的更多相关文章

  1. 在web.config配置中添加xml内容

    在web.config 中添加需要的内容时, 就是在<configuration>节点内添加一个新的<configSections>元素, 在configSections元素中 ...

  2. SpringMVC、SpringMVC XML配置(纯XML方式)

    1.引入SrpingMVC所使用的Java包: cglib-nodep-2.1_3.jar.commons-logging.jar.spring-aspects-4.1.7.RELEASE.jar.s ...

  3. 02_MyBatis项目结构,所需jar包,ehcache.xml配置,log4j.properties,sqlMapConfig.xml配置,SqlMapGenerator.xml配置

     项目结构(所需jar包,配置文件) sqlMapConfig.xml的配置内容如下: <?xmlversion="1.0"encoding="UTF-8&qu ...

  4. web.xml配置DispatcherServlet

    1. org.springframework.web.servlet.DispatcherServlet 所在jar包: <dependency> <groupId>org.s ...

  5. 2.6.1 XML配置:创建XML文件

    (1) 工程名右击---New--file  --  newfile窗口中:filename中输入testng.xml testng.xml 文件中打开后,切换到source 标签中.进行编辑. 内容 ...

  6. Spring MVC Web.xml配置

    Web.xml spring&spring mvc 在web.xml中定义contextConfigLocation参数,Spring会使用这个参数去加载所有逗号分隔的xml文件,如果没有这个 ...

  7. springmvc学习指南 之---第27篇 spring如何实现servlet3.0无web.xml 配置servlet对象的

    writedby 张艳涛 基于web.xml配置,有人说麻烦,tomcat给按照servlet3.0,实现了基于注解@WebServlet,有人说springmvc的springmvc.xml配置麻烦 ...

  8. SpringBoot零XML配置的Spring Boot Application

    Spring Boot 提供了一种统一的方式来管理应用的配置,允许开发人员使用属性properties文件.YAML 文件.环境变量和命令行参数来定义优先级不同的配置值.零XML配置的Spring B ...

  9. 02_Spring Bean的装配模式_基于XML配置方式

    一.三种实例化Bean的方式 1.使用类构造器实例化(默认无参数) <bean id="bean1" class="com.demo1.Bean1"> ...

随机推荐

  1. Clion调试ROS包

    1. 安装 从官网下载最新版本的Clion https://www.jetbrains.com/clion/ 并解压到指定的目录,例如: /home/xkc/software/clion-2017.2 ...

  2. Linux知识(6)----卸载安装的包

    命令步骤: sudo apt-get purge PACKAGE_NAME sudo apt-get autoremove 例如卸载ffmpeg包: sudo apt-get purge ffmpeg ...

  3. 关于php开发中的字符编码问题总结的几个要点

    用php这么久,今天终于要彻底总结下php乱码问题,因为实在是吃过不少亏啊 1:header("content-type:text/html;charset=utf-8")或者&l ...

  4. 系统wmiprvse.exe占用CPU非常高,求解决

    1.wmiprvse.exe是微软Windows操作系统的一部分.用于通过WinMgmt.exe程序处理WMI操作.文件位置有二处: C:\WINDOWS\system32\wbem\wmiprvse ...

  5. MDX Cookbook 02 - 除数为零的问题

    先直接看一个例子 - WITH MEMBER [Date].[Calendar Year].[CY 2006 vs 2005 Bad] AS ], FORMAT_STRING = 'Percent' ...

  6. Spring MVC实现上传文件报错解决方案

    报错代码: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.sp ...

  7. NIO-新的io操作方式

    1.BIO带来的挑战 BIO即阻塞IO,不管是磁盘IO,还是网络IO,数据在写入OutputStream或者从InputStream读取时都有可能发生阻塞,一旦有阻塞,当前线程将会被挂起,即线程进入非 ...

  8. Python操作redis系列之 列表(list) (五)

    # -*- coding: utf- -*- import redis r =redis.Redis(host=,password=") 1. Lpush 命令将一个或多个值插入到列表头部. ...

  9. eclipse preference plugin development store and get

    eclipse plugin development: E:\workspaces\Eclipse_workspace_rcp\.metadata\.plugins\org.eclipse.pde.c ...

  10. win32 进程崩溃时禁止弹出错误对话框

    在程序初始化的时候加入以下代码即可: SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);    _set_abort_behav ...