问题
Im working in a web application using JSF 2
and richFaces 4
and I want to handle exceptions with an error page. I used the JSF standard. Every thing works good but when an exception is throwed I have the error page with the exception details but we are not really redirected to the error page because in the address bar I have the URL of the page where the exception was thrown. Due to this problem I have other problems with links and images paths in the error page.
Thanks in advance.
回答1:
That's not possible using the standard API facilities. If you redirect, then the information about the exception would get lost.
As to your concrete problem,
Due to this problem I have other problems with links and images paths in the error page.
that should never have formed a problem. This is just developer's own mistake. Apparently you're making them relative to the request URL, which is indeed asking for trouble. You should make them relative to the domain root instead.
E.g.
<a href="#{request.contextPath}/index.xhtml">Index</a>
<img src="#{request.contextPath}/resources/images/logo.png" />
But much better is to use real JSF components instead of plain vanilla HTML. They will automatically prepend the context path.
<h:link value="Index" outcome="/index.xhtml" />
<h:graphicImage name="images/logo.png" />
来源:https://stackoverflow.com/questions/9259579/redirect-to-an-error-page-in-jsf