Search code examples
jsfweb.xmlurl-pattern

Prefix URL-Mapping in JSF causing FileNotFound-Error


I´m a JSF-Beginner and try to build a small JSF2 webapplication with Spring and Hibernate. My Server of Choice is the JBOSS 7.1 AS.

I´ve encountered an odd Error while trying to map a servlet with a Prefix URL-Pattern. This is the part of the web.xml that declares the Servlet:

<servlet>
    <servlet-name>FacesServlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>FacesServlet</servlet-name>
    <url-pattern>/webapplication/*</url-pattern>
</servlet-mapping>

If I now direct my Browser to "localhost:8080/myapp/webapplication/index.xhtml" I get a Mojarra/Facelets generated Error: "/index.xhtml Not Found in ExternalContext as a Resource". If I instead configure the URL-Pattern to "*.xhtml" everything is working fine.

I have simply no idea why the Prefix-Pattern isn´t working :/

Greetings


Solution

  • I found the solution :D!

    When using a prefix-pattern I thought i had to place my xhtml-files in a folder of that name. For example I used the pattern "/webapplication/*" so I created a folder "webapplication" and placed my webfiles in there. Now, when directing my Browser to "{host}/myapp/webapplication/index.xhtml" I expected the Server to search the files in "{root}/webapplication/index.xhtml". Instead, the Servlet resolved the URL as "{host}/myapp/index.xhtml". Because the file isn´t placed there, I get a FileNotFound-Error.

    I also learned not to give my resource-folders the same name as my url-patterns.