I have a JSF webapp which is exhibiting the following behaviour:
http://localhost/myapp/
returns the raw contents of index.xhtml
http://localhost/myapp/web/
returns a blank page
http://localhost/myapp/web/index.xhtml
returns the error /index.xhtml Not Found in ExternalContext as a Resource
The directory structure of the webapp is shown below:
The web.xml file looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<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_3_0.xsd" version="3.0">
<display-name>myapp</display-name>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/web/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<!-- <welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
-->
</web-app>
I have a breakpoint in the first line of the method javax.faces.webapp.FacesServlet.service
public void service(ServletRequest req,
ServletResponse resp)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) resp;
requestStart(request.getRequestURI()); // V3 Probe hook
This breakpoint is never hit. Is anyone able to shed some light on what may be wrong here or some pointers on where I can start my investigations.
JSF will trim off own URL pattern from the request URL before finding the resource. You need to put /index.xhtml
file exactly there where JSF expects it as per the error message: in /index.xhtml
. So, outside the /web
folder. Note that you can just keep using /web
in request URL.
An alternative is to just map the FacesServlet
on *.xhtml
. This way you don't need to worry about virtual URLs.