Redirect to an error page in JSF

烂漫一生 提交于 2019-12-06 08:31:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!