SpringMVC 前端控制器的配置 day2

第一步 配置一个servlet

这个servlet的名字我们定义成

<servlet-name>springmvc</servlet-name>

类型是:也就是说这个是一个DispatcherServlet,是前端控制器

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

在这里可以配置加载springmvc这个前端控制器的配置文件,可以是一个xml文件,文件中包含处理器映射器、处理器适配器等

可以使用contextConfigLocation手动的配置我们自己想要加载的配置文件,如果不配置的话也可以,这个servlet会默认加载WEB-INF目录下的springmvc-servlet.xml,这里就不做配置了

第二步 配置servlet-mapping

servlet-mapping的作用就是通过一个servlet-name建立起servlet-class和url-pattern建立联系,使得url映射到servlet-class所指定的类中

<servlet-mapping>
  	<servlet-name>springmvc</servlet-name>
  	<url-pattern>*.action</url-pattern>
</servlet-mapping>

第三步 配置前端控制器加载的配置文件springmvc-servlet.xml

这个xml文件就是一个管理bean对象的容器:这些bean对象包括处理器映射器、处理器适配器、视图解析器、具体的处理器对象

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" 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.2.xsd 
		http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-3.2.xsd 
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">

	<!-- 配置Handler -->
	<bean id="itemsController1" name="/queryItems.action" class="cn.itcast.ssm.controller.ItemsController1" />
	
	<!-- 处理器映射器 
	将bean的name作为url进行查找 ,需要在配置Handler时指定beanname(就是url) 
	所有的映射器都实现 HandlerMapping接口。
	-->
	<bean
		class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />

	<!-- 处理器适配器 所有处理器适配器都实现 HandlerAdapter接口 -->
	<bean
		class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
	
	<!-- 视图解析器
	解析jsp解析,默认使用jstl标签,classpath下的得有jstl的包
	 -->
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver"/>
	
</beans>

这里面首先是一个beans对象,里面包含很多个bean对象,这些bean对象有的是具体的被处理对象,有的是处理对象的组件,这些组件所用的类,需要在beans的首部添加一些约束,包括包含这些类的镜像下载地址

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值