zoukankan      html  css  js  c++  java
  • mvc:view-controller直接转发页面

    在springMVC中,通过@RequestMapping发送请求地址,转发到目标页面,但是,有时候想直接访问页面,

    不想通过xxx.jsp直接访问页面,可以通过springmvc.xml配置文件中的mvc:view-controller标签做到页面的直接访问。

    实例参考 :http://blog.csdn.net/yhl_jxy/article/details/51265077

    在上面的实例中修改spirng-mvc.xml配置文件如下:

     1 <?xml version="1.0" encoding="UTF-8"?>  
     2 <beans xmlns="http://www.springframework.org/schema/beans"  
     3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
     4        xmlns:mvc="http://www.springframework.org/schema/mvc"  
     5        xmlns:p="http://www.springframework.org/schema/p"  
     6        xmlns:context="http://www.springframework.org/schema/context"  
     7        xmlns:aop="http://www.springframework.org/schema/aop"  
     8        xmlns:tx="http://www.springframework.org/schema/tx"  
     9        xsi:schemaLocation="http://www.springframework.org/schema/beans  
    10             http://www.springframework.org/schema/beans/spring-beans-4.1.xsd  
    11             http://www.springframework.org/schema/context   
    12             http://www.springframework.org/schema/context/spring-context-4.1.xsd  
    13             http://www.springframework.org/schema/aop   
    14             http://www.springframework.org/schema/aop/spring-aop-4.1.xsd  
    15             http://www.springframework.org/schema/tx   
    16             http://www.springframework.org/schema/tx/spring-tx-4.1.xsd  
    17             http://www.springframework.org/schema/mvc   
    18             http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd  
    19             http://www.springframework.org/schema/context   
    20             http://www.springframework.org/schema/context/spring-context-4.1.xsd">  
    21     <!--  配置自动扫描的包,扫描到@controller注解的类是控制器,是使用注解的前提  -->
    22     <context:component-scan base-package="com.lanhuigu.springmvc"/>
    23     <!-- 视图解析器 -->
    24     <bean id="viewResolver"
    25           class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    26           <!-- 配置前缀 -->
    27           <property name="prefix" value="/WEB-INF/views/"/>
    28           <!-- 配置后缀 -->
    29           <property name="suffix" value=".jsp"/>
    30     </bean>
    31     <!-- 配置直接转发的页面 -->
    32     <mvc:view-controller path="/success" view-name="success"/>
    33     <!-- 解决mvc:view-controller配置后RequestMapping映射地址报404的问题 -->  
    34     <mvc:annotation-driven></mvc:annotation-driven>
    35 </beans>


    这个时候,我们可以在浏览器直接访问success.jsp页面:

    http://localhost:9000/SpringMVC/success

    不用通过访问某个RequestMapping地址,返回到success页面,也不需要通过success.jsp的绝对路径访问。

    通过这样直接转发页面的配置,不影响RequestMapping映射地址请求转发页面。

  • 相关阅读:
    智能语音
    设置View大小随屏幕自动放大
    程序经常在第一次启动时崩溃
    苹果员工的休假时间记录
    未解决知识点:edgesForExtendedLayout
    关于iOS的autolayout中导航栏的疑问
    iOS比较好用的抽屉第三方:JASidePanels
    versions使用心得
    使用Xcode7上传app的error整理:ERROR ITMS-90535,ERROR ITMS-90529,ERROR ITMS-90049
    subversions上传新文件Xcode中不显示
  • 原文地址:https://www.cnblogs.com/sharpest/p/7707549.html
Copyright © 2011-2022 走看看