在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映射地址请求转发页面。

最新文章

  1. Eclipse的自动排版设置(format)
  2. JMeter设置集合点
  3. 设置JVM参数,查看堆大小
  4. 4、SQL基础整理(规范函数)
  5. python numpy 的运算
  6. Hbase学习记录(1)|伪分布式安装
  7. [Effective C++ --008]别让异常逃离析构函数
  8. 编写Linux/Unix守护进程
  9. JAVA基础第六组(5道题)
  10. SSL/TLS 握手过程详解
  11. jdbcTemplate的queryForList
  12. ArcGIS对SLD样式的支持
  13. C# DataGridView改变行颜色无效问题
  14. 实际操作--create DB link
  15. [Android] 获取系统顶部状态栏(Status Bar)与底部导航栏(Navigation Bar)的高度
  16. 微信access_token请求之简单缓存方法封装
  17. 项目中遇到的IE8浏览器访问页面过慢问题
  18. centos7.5下安装teamview
  19. jq 分页
  20. PyalgoTrade 交易(五)

热门文章

  1. 用Python+selenium打开IE浏览器和Chrome浏览器的问题
  2. 利用string 字符串拷贝
  3. [系统资源攻略]memory
  4. 51nod1185 威佐夫游戏 V2【博弈论】
  5. 将项目上传到Github之使用git命令上传
  6. FusionCharts,双折线图和双柱状图
  7. SBC37x交叉编译平台QT+OPENCV【2】虚拟机Vbox下Ubuntu的磁盘扩容
  8. JAVA反映机制A
  9. Shallow Heap 和 Retained Heap的区别
  10. ABCDE