第一种:
@RequestMapping(value = "/index.html", method = RequestMethod.GET)
public String index(Model model) {
return second(model);
}
@RequestMapping(value = "/second.html", method = RequestMethod.GET)
public String second(Model model) {
//put some staff in model
return "second";
}
第二种:
@RequestMapping(value = "/index.html", method = RequestMethod.GET)
public View index(Model model) {
return new RedirectView("second.html");
}
@RequestMapping(value = "/second.html", method = RequestMethod.GET)
public String second(Model model) {
//put some staff in model
return "second";
}
第三种:
@RequestMapping(value = "/rate", method = RequestMethod.POST)
public String rateHandler(HttpServletRequest request) {
//your controller code
String referer = request.getHeader("Referer");
return "redirect:"+ referer;
}
其中,referer可为:
- 外部URL。如:"redirect:http://www.baidu.com/",重定位后会打开http://www.baidu.com/
- 绝对路径。如:"redirect:/redirect/re",如果当前URL为“localhost:8180/spring3/home/redirect”,则重定位后的URL为“http://localhost:8180/spring3/redirect/re”。
- 相对路径。如:"redirect:compare?input1=123&input2=32",如果当前URL为“localhost:8180/spring3/home/redirect2/re”,则重定位后的URL为“http://localhost:8180/spring3/home/redirect2/compare?input1=123&input2=32”
参考:
http://stackoverflow.com/questions/5077783/redirect-in-controllers-spring3
http://stackoverflow.com/questions/804581/spring-mvc-controller-redirect-to-previous-page
分享到:
相关推荐
spring mvc重定向导致内存溢出解决方案
弹簧重定向 在Spring中重定向的不同方法
本文介绍了在Spring中实现重定向的三种不同方法,在执行这些重定向时如何处理/传递属性以及如何处理HTTP POST请求的重定向。关于Spring 重定向(Redirect)指南的相关知识大家参考下本
钉钉扫码登录讲解 一、扫码登录参数准备 ... AppId 应用唯一标识 AppSecret 应用密钥 redirect_uri 重定向地址 loginTmpCode 临时授权码 ③、选择《服务端API》选项->《身份验证》->《扫码登录第三方网站》,得到教程
您可能感兴趣的文章:浅谈在django中使用redirect重定向数据传输的问题基于vue-router 多级路由redirect 重定向的问题Spring 重定向(Redirect)指南及相关策略问题详解Java从后台重定向(redirect)到另一个项
13.5.3. 重定向(Rediret)到另一个视图 13.5.3.1. RedirectView 13.5.3.2. redirect:前缀 13.5.3.3. forward:前缀 13.6. 本地化解析器 13.6.1. AcceptHeaderLocaleResolver 13.6.2. CookieLocaleResolver 13.6.3. ...
主要介绍了springboot转发重定向实现方式解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
在asp.net中页面重定向:Server.Execute(“m2.aspx”); 服务器保存此页转向前的数据后,使页面转向到m2.aspx执行, 再返回本页继续执行.再将三者结果合并后返回给浏览器. 以上都是服务器端页面转向所以浏览器不出现页...
dropwizard-redirect-bundle.zip,一个简单的dropwizard包,允许http重定向。
3.其他隐含对象 1)cookie JSTL并没有提供设定cookie的动作, 例:要取得cookie中有一个设定名称为userCountry的值,可以使用${cookie.userCountry} 来 取得它。 2)header和headerValues header 储存用户...
重定向会话错误使用Luminus版本“ 2.9.12.60”生成整我先决条件您将需要安装 2.0或更高版本。跑步要为该应用程序启动Web服务器,请运行: lein run执照版权所有:copyright:2018 FIXME问题ACCESS localhost:3000 / ...
redirect是重定向,浏览器跳转后显示新的地址。 对比之下forward更加高效,并且它有助于隐藏实际地址,但是有些情况则必须使用redirect,否则会报异常。 jsp中动态include和静态include的区别? 答:动态include用...
【WEB】转发(forward)和重定向(redirect)的区别 38 forward(转发): 38 redirect(重定向): 39 区别: 39 【WEB】实现会话跟踪的技术有哪些? 40 【WEB】什么是ORM 42 【反射】反射中,Class.forName和...
3、String 是最基本的数据类型吗? 8 4、float 型float f=3.4是否正确? 8 5、语句float f=1.3;编译能否通过? 8 6、short s1 = 1; s1 = s1 + 1;有什么错? 8 7、Java 有没有goto? 8 8、int 和Integer 有什么区别? 9 9...
3、String 是最基本的数据类型吗? 8 4、float 型float f=3.4是否正确? 8 5、语句float f=1.3;编译能否通过? 8 6、short s1 = 1; s1 = s1 + 1;有什么错? 8 7、Java 有没有goto? 8 8、int 和Integer 有什么区别? 9 9...
使用用户界面组件模型和JSF事件模型,包括支持可添加书签的页面以及POST、REDIRECT、GET模式。使用为模型数据验证设立的新的JSR-303bean验证标准。创建可以使用Ajax的定制用户界面组件。使用定制的非用户界面组件来...
使用用户界面组件模型和JSF事件模型,包括支持可添加书签的页面以及POST、REDIRECT、GET模式。使用为模型数据验证设立的新的JSR-303bean验证标准。创建可以使用Ajax的定制用户界面组件。使用定制的非用户界面组件来...