spring3 redirect(重定向)

第一种:

@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可为:
[list]
[*]外部URL。如:"redirect:http://www.baidu.com/",重定位后会打开[url]http://www.baidu.com/[/url]
[*]绝对路径。如:"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”
[/list]

参考:
[url]http://stackoverflow.com/questions/5077783/redirect-in-controllers-spring3[/url]
[url]http://stackoverflow.com/questions/804581/spring-mvc-controller-redirect-to-previous-page[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值