首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

DispatcherServlet在web.xml中的配备

2012-09-21 
DispatcherServlet在web.xml中的配置servletservlet-namechapter2/servlet-nameservlet-classorg.

DispatcherServlet在web.xml中的配置

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


DispatcherServlet也可以配置自己的初始化参数,覆盖默认配置:
摘自Spring Reference
参数
描述
contextClass
实现WebApplicationContext接口的类,当前的servlet用它来创建上下文。如果这个参数没有指定, 默认使用XmlWebApplicationContext。
contextConfigLocation
传给上下文实例(由contextClass指定)的字符串,用来指定上下文的位置。这个字符串可以被分成多个字符串(使用逗号作为分隔符) 来支持多个上下文(在多上下文的情况下,如果同一个bean被定义两次,后面一个优先)。
namespace
WebApplicationContext命名空间。默认值是[server-name]-servlet。


因此我们可以通过添加初始化参数

  <servlet>        <servlet-name>chapter2</servlet-name>        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>        <load-on-startup>1</load-on-startup>        <init-param>            <param-name>contextConfigLocation</param-name>            <param-value>classpath:spring-servlet-config.xml</param-value>        </init-param>    </servlet>

热点排行