1

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:

enter image description here

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
auser
  • 6,307
  • 13
  • 41
  • 63

1 Answers1

2

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.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • The problem with placing index.xhtml outside the /web directory whilst maintaining the /web/* URL mapping is that the request http://localhost/myapp/index.xhtml will return the raw index.xhtml file. In the original message I did not mention that I have a RestEasy servelet mapped to /rest/* and what I'm trying to do is to make sure that webpage requests are handled by the JSF FacesServlet and for the REST requests to be handled by the ResteasyServlet. – auser Jan 12 '13 at 12:17
  • Then just use a mapping of `*.xhtml`? – BalusC Jan 12 '13 at 12:20
  • Yes, I could do that however, what would happen to a request for `http://localhost/rest/some-method.xhtml`? I think this would be routed to FacesServlet too right? – auser Jan 12 '13 at 12:24
  • Put the rest servlet in front of the faces servlet in web.xml. The first match wins. – BalusC Jan 12 '13 at 12:28