第一种:
第二种:
第三种:
其中,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]
@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]