Question

I'm deploying my app to WildFly 8 and have attempted to configure it so that a custom 404 error page is given by adding the following into my web.xml

<error-page>  
    <error-code>404</error-code>  
    <location>/error.jsf</location>  
</error-page>

This works fine when I try to access non-JSF pages that don't exit. For example if I attempt to access a page called IDoNotExist.html, then my error page is displayed correctly.

If however, I attempt to access a JSF page that doesn't exist, e.g. IDoNotExist.jsf, then I don't get my custom error page - I just get a blank page and the following error is logged to WildFly.

WARNING [javax.enterprise.resource.webcontainer.jsf.context] (default task-8) JSF1091: No mime type could be found for file  
/IDoNotExist.jsp.  To resolve this, add a mime-type mapping to the applications web.xml.  

Note that the error log references a .JSP page whereas I attempted to acces a .JSF page.

I've tried adding a mime type mapping for JSP pages, and although that gets rid of the error message on the console, I still don't see my custom 404 page for non-existant JSF pages.

I've also thought that some exception is maybe being thrown before the page is rendered so I've tried adding an exception error handler in web.xml, but this has made no difference either.

Is there something missing from my web.xml file or is some other configuration required?

My web.xml is simply:

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <error-page>
        <error-code>404</error-code>
        <location>/error.jsf</location>
    </error-page>
</web-app>

Thanks.

Was it helpful?

Solution

I've managed to fix this issue by defining the JSF servlet mapping to respond to *.xhtml files instead of using the default .jsf

<servlet-mapping>
    <servlet-name>FacesServlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

When I use *.xhtml as my jsf mapping, then custom 404 pages are correctly handled.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top