问题
How can I make Shiro redirect errors in a Web app?
I have configured my web.xml
<error-page>
<error-code>500</error-code>
<location...</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>...</location>
</error-page>
And it works fine. But when Shiro is active and I raise a 500 error on purpose the page stays blank.
回答1:
I think I got it... It was blank because the method onAccessDenied()
was returning false
wherever a problem happened.
To fix it, one possible solution is this:
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response)
throws Exception {
if(!executeLogin(request, response)){
//throw exception
} else {
return true;
}
}
Of course make sure your error pages defined in web.xml
are anon
in your shiro.ini
e.g.
[urls]
/error500.xhtml = anon
来源:https://stackoverflow.com/questions/44848142/shiro-error-redirection