[英]What is the right way to handle redirect in Spring Boot?
经过研究有关弹簧靴和以前的弹簧mvc框架之间差异的主题。 我很困惑,需要一些帮助! 如何重定向到html页面,因为通常在页面目标没有控制器方法的情况下尝试重定向将返回HTTP 404。
如果我下面有处理注册的控制器方法,请确认:
@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();
}
我收到找不到HTTP 404错误的提示。 是否必须具有特定于错误.html页面的Controller方法? 如果不是必需的,该如何运行。
将您的响应重定向到“ /wrong.html”后,spring需要知道如何处理“ /wrong.html”。 也许,您没有为'/wrong.html'做任何处理程序,所以spring不知道如何处理它并响应404。
这个答案可能会对您有所帮助: 如何在Spring中提供.html文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.