gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 07:12:57 24 4
gpt4 key购买 nike

在带有 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(应用中没有其他 View 解析器)。

安全工作正常,当未经授权的用户试图访问安全页面时显示 errorPage.jsp,但页面未修饰。应用程序中的每个其他页面都经过修饰,没有任何问题,并且 errorPage.jsp 与其他经过修饰的 JSP 位于同一目录中,没有任何问题。此应用程序使用 Servlet 3.0 规范。

最佳答案

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

@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";
}

关于java - Spring Security 应用程序中 Sitemesh 未修饰的自定义错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19907706/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com