Spring MVC

  1. 在Spring MVC程序中,配置Web.xml文件,要配置两个Servlet。

    • 第一个是org.springframework.web.context.ContextLoaderServlet,用于在Web程序启动的时候,就加载一个配置文件,该配置文件的内容是为所有其web组件所共享的。无需接受请求即加载该文件,web程序启动的时候即加载了这个文件。示例如下:

      <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
      <context-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>/WEB-INF/spring/root-context.xml</param-value>
      </context-param>
      <!-- Creates the Spring Container shared by all Servlets and Filters -->
      <listener>
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
    • 第二个是org.springframework.web.servlet.DispatcherServlet,该Servlet的作用在于,处理各种web请求,只有当接受到请求,才会将这个DispatcherServlet所产生的上下文保存在Request中。示例如下:

      <!-- Processes application requests -->
      <servlet>
          <servlet-name>appServlet</servlet-name>
          <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
          <init-param>
              <param-name>contextConfigLocation</param-name>
              <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
          </init-param>
          <load-on-startup>1</load-on-startup>
          <async-supported>true</async-supported>
      </servlet>
      <servlet-mapping>
          <servlet-name>appServlet</servlet-name>
          <url-pattern>/</url-pattern>
      </servlet-mapping>
      
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值