UrlFilenameViewController控制器实现跳转页面
使用UrlFilenameViewController控制器:
使用该控制器与ParameterizableViewController控制器相比可以省去实视图名的配置,直接通过url解析,例如访问是的login.do,那么视图名就是login。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- 定义控制器,该控制器直接跳转到一个页面,该控制器根据请求的url,解析出视图名,省去了视图名的配置 -->
<bean id="loginController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>
<!-- 定义映射器 -->
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<!-- key中的login.do表示请求的url,loginController表示具体处理的控制器 -->
<prop key="login.do">loginController</prop>
</props>
</property>
</bean>
<!-- 配置url解析器 -->
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<!-- 视图处理类,这里使用的是JSTL -->
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<!-- 返回的逻辑名称的前缀 -->
<property name="prefix" value="/WEB-INF/jsp/"/>
<!-- 返回的逻辑名称的后缀 -->
<property name="suffix" value=".jsp"/>
<!-- 最后返回的url是/jsp/逻辑名.jsp -->
</bean>
</beans>
使用UrlFilenameViewController控制器:
使用该控制器与ParameterizableViewController控制器相比可以省去实视图名的配置,直接通过url解析,例如访问是的login.do,那么视图名就是login。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- 定义控制器,该控制器直接跳转到一个页面,该控制器根据请求的url,解析出视图名,省去了视图名的配置 -->
<bean id="loginController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>
<!-- 定义映射器 -->
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<!-- key中的login.do表示请求的url,loginController表示具体处理的控制器 -->
<prop key="login.do">loginController</prop>
</props>
</property>
</bean>
<!-- 配置url解析器 -->
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<!-- 视图处理类,这里使用的是JSTL -->
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<!-- 返回的逻辑名称的前缀 -->
<property name="prefix" value="/WEB-INF/jsp/"/>
<!-- 返回的逻辑名称的后缀 -->
<property name="suffix" value=".jsp"/>
<!-- 最后返回的url是/jsp/逻辑名.jsp -->
</bean>
</beans>