Spring Security应用程序中Sitemesh未修饰的自定义错误页面

在带有Spring Security(3.2.0.RC2)和Sitemesh(2.4.2)的Spring MVC(3.2.4)应用程序中,web.xml文件具有以下条目:

 403 /error?code=403  

映射到ErrorController:

 @RequestMapping("error") public String displayErrorPage( @RequestParam(value = "code", defaultValue = "0") int code, Model model, final HttpServletRequest request, Principal principal) { // ... return "errorPage"; } 

它通过InternalResourceViewResolver显示errorPage.jsp(应用程序中没有其他视图解析器)。

安全性正常,当未经授权的用户尝试访问受保护的页面时,会显示errorPage.jsp,但该页面未进行装饰。 应用程序中的每个其他页面都没有任何问题进行修饰,并且errorPage.jsp与其他装饰没有任何问题的JSP存在于同一目录中。 此应用程序使用Servlet 3.0规范。

这似乎是一个Sitemesh错误(请参阅: http : //forum.spring.io/forum/spring-projects/security/37742-sitemesh-decoration-problem ),可以通过重定向解决。 由于各种原因,我不想在JSP页面中进行重定向,所以我更改了我的控制器:

 @RequestMapping("error") public String displayErrorPage( @RequestParam(value = "code", defaultValue = "0") int code, RedirectAttributes redirectAttributes, final HttpServletRequest request, Principal principal) { // ... redirectAttributes.addFlashAttribute("myAttribute", myAttribute); return "redirect:/displayError"; } @RequestMapping("displayError") public String displayError() { return "errorPage"; }