学习SpringMVC(十四)之关于重定向
2016-05-22 13:47
447 查看
一般情况下,contrller方法返回的字符串的值会被当成逻辑视图名处理。
但是如果返回的字符串中带forward:或redirect:前缀时,SpringMVC会对他们进行特殊处理,将forward:和redirect:当成指示符,其后字符串作为URL来处理
例如:
forward:/index.jsp 将会完成一个到index.jsp页面的转发操作
redirect:/index.jsp 将会完成一个到index.jsp页面的重定向操作
在controller中:
但是如果返回的字符串中带forward:或redirect:前缀时,SpringMVC会对他们进行特殊处理,将forward:和redirect:当成指示符,其后字符串作为URL来处理
例如:
forward:/index.jsp 将会完成一个到index.jsp页面的转发操作
redirect:/index.jsp 将会完成一个到index.jsp页面的重定向操作
在controller中:
package com.cgf.springmvc.handlers; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @RequestMapping(value="/springmvc") @Controller public class MyRedirect { @RequestMapping(value="/testMyRedirect") public String testMyRedirect(){ System.out.println("testMyRedirect"); return "redirect:/index.jsp"; } }在index.jsp页面中:
<a href="springmvc/testMyRedirect">Test MyRedirect</a><br>
相关文章推荐
- 第二章、4.java类和对象
- eclipse设置新建jsp文件默认字符编码为utf-8
- java.lang.IllegalStateException: Cannot forward after response has been committed
- 3种Java从文件路径中获取文件名的方法
- JAVA基础之线程
- JAVA基础之多态成员特点
- Struts2跳转带参数问题
- JAVA基础之多态
- 将别处的web project 导入 eclipse 以后,为什么run as里 没有 run on server 选项
- MyEclipse中文乱码问题
- JAVA基础之进制转换,查表法的应用
- java.lang.ClassCastException: org.ksoap2.SoapFault
- JAVA基础之数组
- Struts2 HelloWorld!
- JAVA基础之函数
- Convention 插件(2)—— Annotation
- JAVA基础之其他流程控制语句:循环嵌套
- Java核心技术体系
- JAVA基础之流程控制语句:循环结构
- JAVA之旅(五)——this,static,关键字,main函数,封装工具类,生成javadoc说明书,静态代码块