[英]What is the right way to handle redirect in Spring Boot?
After research on subjects concerning differences between spring boot and previous spring mvc frameworks. 经过研究有关弹簧靴和以前的弹簧mvc框架之间差异的主题。 I am confused and need some help!
我很困惑,需要一些帮助! How to do redirect to an html page since normally trying to redirect without the page target having a controller method returns HTTP 404.
如何重定向到html页面,因为通常在页面目标没有控制器方法的情况下尝试重定向将返回HTTP 404。
if I have this controller method below that handles registration confirm: 如果我下面有处理注册的控制器方法,请确认:
@RequestMapping(value = "/registrationConfirm", method = RequestMethod.GET)
public String confirmRegistration(final HttpServletRequest request, Model
model, @RequestParam("token") final String token){
Locale locale = request.getLocale();
final String result = userService.validateConfirmationToken(token);
if (result.equals("valid")) {
final User user = userService.getUser(token);
authWithoutPassword(user);
model.addAttribute("message",
messages.getMessage("message.accountVerified", null, locale));
return "redirect:/home.html?lang=" + locale.getLanguage();
}
model.addAttribute("message", messages.getMessage("auth.message." +
result, null, locale));
model.addAttribute("expired", "expired".equals(result));
model.addAttribute("token", token);
return "redirect:/wrong.html?lang=" + locale.getLanguage();
}
I am getting http 404 error not found. 我收到找不到HTTP 404错误的提示。 Is it a must to have a Controller method specific for wrong.html page?
是否必须具有特定于错误.html页面的Controller方法? if it is not required, how to run it that way.
如果不是必需的,该如何运行。
After your response is redirected to '/wrong.html', spring need to know how to handle '/wrong.html'. 将您的响应重定向到“ /wrong.html”后,spring需要知道如何处理“ /wrong.html”。 Maybe, You made no handler for '/wrong.html', so spring doesn't know how to handle it and responses 404.
也许,您没有为'/wrong.html'做任何处理程序,所以spring不知道如何处理它并响应404。
This answer might help you : How to serve .html files with Spring 这个答案可能会对您有所帮助: 如何在Spring中提供.html文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.