2010-09-20 55 views

回答

5

通常處理自定義錯誤頁面更多的是與servlet規範而不是實際的應用程序容器。因此,把這種最常見的地方是在你的web.xml,像這樣:

<error-page> 
    <error-code>404</error-code> 
    <location>/my-404.jsp</location> 
</error-page> 
<error-page> 
    <error-code>500</error-code> 
    <location>/my-500.jsp</location> 
</error-page> 

如果以上仍不能正常工作,請確認您有正確的XSD在web.xml,很容易使用這個舊版本會導致JBoss回退到舊版本的servlet API,該版本無法識別上述標籤。在一般情況下,這個工作對我來說使用Servlet 2.5:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns="http://java.sun.com/xml/ns/javaee" 
     xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> 

出於興趣,JBoss的5.0.x版本和5.1.0,全球web.xml文件位於server/<your server>/deployers/jbossweb.deployer/web.xml,並ROOT.war是server/<your server>/deploy/ROOT.war。這將允許您爲服務器內的所有應用程序創建自定義錯誤頁面。