【发布时间】:2011-11-22 11:09:14
【问题描述】:
当用户在获得 HTTP 500 后看不到页面(没有特定权限时)时如何显示自定义错误页面 -
org.springframework.security.access.AccessDeniedException: 访问被拒绝
自定义 hasPermission() 方法的异常。
您可以查看我之前的问题 here 以查看我的代码。
【问题讨论】:
标签: spring struts2 spring-security
当用户在获得 HTTP 500 后看不到页面(没有特定权限时)时如何显示自定义错误页面 -
org.springframework.security.access.AccessDeniedException: 访问被拒绝
自定义 hasPermission() 方法的异常。
您可以查看我之前的问题 here 以查看我的代码。
【问题讨论】:
标签: spring struts2 spring-security
在您的 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>
所以这取决于您选择如何配置它。详情请参阅。
我的建议是不要将每个异常都作为原始异常抛出,最好创建自己的异常包装器并将此类异常包装在其中,这将帮助您以更好的方式组织代码
希望这会对你有所帮助。
【讨论】: