【问题标题】:Custom Error Page Not Decorated by Sitemesh in Spring Security ApplicationSpring Security 应用程序中的 Sitemesh 未装饰自定义错误页面
【发布时间】:2013-11-23 08:01:48
【问题描述】:

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

<error-page>
    <error-code>403</error-code>
    <location>/error?code=403</location>
</error-page>

映射到 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 规范。

【问题讨论】:

    标签: java jsp spring-mvc spring-security sitemesh


    【解决方案1】:

    这似乎是一个可以通过重定向解决的 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";
    }
    

    【讨论】:

      猜你喜欢
      • 2013-08-25
      • 2011-03-28
      • 2017-09-21
      • 2016-01-21
      • 2016-01-17
      • 1970-01-01
      • 2015-10-04
      • 2017-01-06
      • 2017-02-07
      相关资源
      最近更新 更多