2012-10-08 26 views
0

如何以編程方式重定向到web.xml中定義的錯誤頁面?如何以編程方式重定向到異常錯誤頁面?

<error-page> 
    <exception-type>java.lang.Exception</exception-type> 
    <location>/error.xhtml</location> 
</error-page> 

如何獲得/error.xhtml通過FacesContext

有時可能會在overriden方法中發生異常,並且我不能拋出異常並需要手動處理異常,例如自己重定向到錯誤頁面。

+0

如果你這麼說,我不知道。但該鏈接絕不會幫助,我已經有我的自定義異常錯誤頁面,它工作正常。我需要獲取錯誤網站的網址以重定向到它。 – djmj

+0

我不認爲有這樣的方式從web.xml中獲取錯誤頁面值。任何你可以手動發送重定向的地方,你應該能夠拋出所需的異常來顯示web.xml中定義的錯誤頁面。如果你的意思是重寫的方法拋出了一個不同於錯誤頁面所需的異常類型,你可以捕獲該異常,然後拋出你想要的異常。 – worpet

回答

1

它可以使用Omnifaces庫進行檢索。

從文檔:

This configuration enum parses the /WEB-INF/web.xml and all /META-INF/web-fragment files found in the classpath and offers methods to obtain information from them which is not available by the standard Servlet API.

http://showcase.omnifaces.org/utils/WebXml

相關問題