mvc:view-controller直接转发页面
2024-08-31 07:58:57
在springMVC中,通过@RequestMapping发送请求地址,转发到目标页面,但是,有时候想直接访问页面,
不想通过xxx.jsp直接访问页面,可以通过springmvc.xml配置文件中的mvc:view-controller标签做到页面的直接访问。
实例参考 :http://blog.csdn.net/yhl_jxy/article/details/51265077
在上面的实例中修改spirng-mvc.xml配置文件如下:
<?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:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
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-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd">
<!-- 配置自动扫描的包,扫描到@controller注解的类是控制器,是使用注解的前提 -->
<context:component-scan base-package="com.lanhuigu.springmvc"/>
<!-- 视图解析器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 配置前缀 -->
<property name="prefix" value="/WEB-INF/views/"/>
<!-- 配置后缀 -->
<property name="suffix" value=".jsp"/>
</bean>
<!-- 配置直接转发的页面 -->
<mvc:view-controller path="/success" view-name="success"/>
<!-- 解决mvc:view-controller配置后RequestMapping映射地址报404的问题 -->
<mvc:annotation-driven></mvc:annotation-driven>
</beans>
这个时候,我们可以在浏览器直接访问success.jsp页面:
http://localhost:9000/SpringMVC/success
不用通过访问某个RequestMapping地址,返回到success页面,也不需要通过success.jsp的绝对路径访问。
通过这样直接转发页面的配置,不影响RequestMapping映射地址请求转发页面。
最新文章
- Eclipse的自动排版设置(format)
- JMeter设置集合点
- 设置JVM参数,查看堆大小
- 4、SQL基础整理(规范函数)
- python numpy 的运算
- Hbase学习记录(1)|伪分布式安装
- [Effective C++ --008]别让异常逃离析构函数
- 编写Linux/Unix守护进程
- JAVA基础第六组(5道题)
- SSL/TLS 握手过程详解
- jdbcTemplate的queryForList
- ArcGIS对SLD样式的支持
- C# DataGridView改变行颜色无效问题
- 实际操作--create DB link
- [Android] 获取系统顶部状态栏(Status Bar)与底部导航栏(Navigation Bar)的高度
- 微信access_token请求之简单缓存方法封装
- 项目中遇到的IE8浏览器访问页面过慢问题
- centos7.5下安装teamview
- jq 分页
- PyalgoTrade 交易(五)