当用户在获得 HTTP 500 后无法看到页面(当没有特定权限时)时如何显示自定义错误页面 -
org.springframework.security.access.AccessDeniedException:访问被拒绝
自定义 hasPermission() 方法的异常。
您可以查看我之前的问题 here 查看我的代码。
最佳答案
在您的 struts2 配置文件中,您可以配置全局异常,例如
<global-exception-mappings>
<exception-mapping exception="org.springframework.security.access.AccessDeniedException" result="securityerror" />
<exception-mapping exception="java.lang.Exception" result="error" />
</global-exception-mappings>
<global-results>
<result name="securityerror">/securityerror.jsp</result>
<result name="error">/error.jsp</result>
</global-results>
这将适用于应用程序级别,如果您发现细粒度的异常处理内容,您可以为操作级别本身定义它
<action name="actionspecificexception" class="org.apache.struts.register.action.Register" method="throwSecurityException">
<exception-mapping exception="org.springframework.security.access.AccessDeniedException"
result="login" />
<result>/register.jsp</result>
<result name="login">/login.jsp</result>
</action>
所以这取决于您选择如何配置它。有关详细信息,请参阅。
Exception handling in Struts2
我的建议是不要将每个异常都作为原始异常抛出,更好地创建自己的异常包装器并将此类异常包装在其中,这将帮助您以更好的方式组织代码
希望这会帮助你。
关于spring - 自定义错误页面 + spring security 3 + hasPermission,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8225805/