在研究了春季靴子和之前的春季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错误。是否必须具有特定于wrong.html页面的Controller方法?如果不需要,如何以这种方式运行它。
在您的响应被重定向到'/wrong.html'之后,spring需要知道如何处理'/wrong.html'。也许,你没有为'/wrong.html'做任何处理程序,所以spring不知道如何处理它并回复404。
这个答案可能会对你有所帮助:How to serve .html files with Spring