spring - servlet-context.xml_Beluga_白鲸-程序员宅基地

技术标签: spring  【 Java 基础 】  web  

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">


	<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射,并在Controller类中实现按方法名解析 -->
	<bean
		class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />
	<bean
		class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" />

	<context:component-scan base-package="com.sqjy.pages" />

	<!-- Controller类作为一个解析器 -->
	<bean
		class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />

	<!-- JSP视图解析器 -->
	<bean id="InternalResourceViewResolver"
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="requestContextAttribute" value="rc" />
		<property name="viewClass"
			value="org.springframework.web.servlet.view.JstlView" />
		<property name="prefix" value="/WEB-INF/pages/" />
		<property name="suffix" value=".jsp" />
	</bean>

	<!-- 对普通文件的解析 -->
	<bean id="urlFilenameViewController"
		class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />

	<!-- DAO异常处理 -->
	<bean id="exceptionResolver"
		class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
		<property name="exceptionMappings">
			<value>
				org.springframework.dao.DataAccessException=dataAccessFailure
			</value>
		</property>
	</bean>

	<!-- 上传文件时,解析器不控制文件大小,改为Action中判断 -->
	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

	<!-- URL Mapping Configration -->
	<bean id="simpleUrlHandlerMapping"
		class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
		<property name="mappings">
			<value>
				*.html=urlFilenameViewController
			</value>
		</property>
	</bean>

</beans>



解释01:

         

        <!-- URL Mapping Configration -->
	<bean id="simpleUrlHandlerMapping"
		class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
		<property name="mappings">
			<value>
				*.html=urlFilenameViewController
			</value>
		</property>
	</bean>


         如果url里面有带.html则直接在WEB-INF下面找到相关的jsp,如果有相关的jsp就会直接访问,不会受到web里面的Spring制约,例如:www.xxx/play.html会找到WEB-INF/pages 下面的paly.jsp(PlayHandler.java没有定义返回的@RequestMapping("/play"))


版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/u012246458/article/details/46006253

智能推荐

随便推点