Spring MVC framework[1] Configuration

All contents are referenced from Spring In Action

servlet-context.xml specified in web.xml is used by DispatcherServlet to defines its request-processing context.

web.xml:

	<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/<strong><span style="color:#ff0000;">servlet-context.xml</span></strong></param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
		
	<servlet-mapping>
		<servlet-name>appServlet</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>

in servlet-context.xml , Spring’s mvc namespace includes a new <mvc:resources> element that handles requests for static content.

servlet-context.xml:

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory-->
 <resources mapping="/resources/**" location="/resources/" /> <!-- ** is Ant-style wildcard -->
As configured here, any requests whose paths begin with /resources will be automatically served from the /resources folder at the root of the application

DispatcherServlet consults one or more handler mappings in order to know which controller to dispatch a request to.

 one of the mappings, DefaultAnnotationHandlerMapping maps requests to controller methods that are annotated with @RequestMapping.

we’ll also use annotations to bind request parameters to handler method parameters, perform validation, and perform message conversion. 

To turn on annotation-driven features of Spring MVC, put <mvc:annotation-driven> in servlet-context.xml.

servlet-context.xml:

	<!-- Enables the Spring MVC @Controller programming model -->
	<annotation-driven />

<mvc:annotation-driven> registers several features, including JSR-303 validation support, message conversion, and support for field formatting.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值