views:

1404

answers:

2

Hi,

I have created simple Java Dynamic Web project in Eclipse. I host my project on Glassfish 2.1.1. When I try open p1.jsf page in browser I got following error: javax.servlet.ServletException: PWC1232: Exceeded maximum depth for nested request dispatches: 20.

I have no idea how to correct this error...

Here is may p1.jsf definition:

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
 <%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%&gt;
 <%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%&gt;
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
 <title>Insert title here</title>
 </head>
 <body>
 <f:view>
  <h:outputLabel value="outputLabel"></h:outputLabel>
 </f:view>
 </body>
 </html>

My web.xml:

 <?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_2_5.xsd" id="WebApp_ID" version="2.5">
   <display-name>web4</display-name>
   <welcome-file-list>
     <welcome-file>index.html</welcome-file>
     <welcome-file>index.htm</welcome-file>
     <welcome-file>index.jsp</welcome-file>
     <welcome-file>default.html</welcome-file>
     <welcome-file>default.htm</welcome-file>
     <welcome-file>default.jsp</welcome-file>
   </welcome-file-list>
   <servlet>
     <servlet-name>FacesServlet</servlet-name>
     <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
     <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>
     <servlet-name>FacesServlet</servlet-name>
     <url-pattern>*.jsf</url-pattern>
   </servlet-mapping>
 </web-app>

My faces-config.xml:

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

<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
    version="1.2">

</faces-config>

Error details from Glassfish log:

PWC1406: Servlet.service() for servlet FacesServlet threw exception javax.servlet.ServletException: PWC1232: Exceeded maximum depth for nested request dispatches: 20
 org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:860)
 org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:723)
 org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:558)
 org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:490)
 org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:382)
 com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:410)
 com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:468)
 com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:140)
 com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
 com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
 com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
 javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
 org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
 org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:873)
 org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:723)
 org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:558)
 org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:490)
 org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:382)
 com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:410)
 com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:468)
 com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:140)
 com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
 com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
 com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
 javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
 org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
 org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:873)
 org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:723)
 org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:558)
 org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:490)
 org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:382)
 com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:410)
 com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:468)
 com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:140)
 com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
 com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
 com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
 javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
 org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
 org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:873)
 org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:723)
 org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:558)
 org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:490)
 org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:382)
 com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:410)
 com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:468)
 com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:140)
 com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
 com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
 com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
 javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
A: 

This means that recursive internal forwards occur. A few things to observe:

  • make sure you are accessing the page via the right suffix. i.e. http://localhost:8080/app/p1.jsp, and not p1.page - you have mapped the jsf suffix to be .jsp
  • check your navigation rules in your faces-config.xml
  • make sure you have the following context-param defined:

    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.jsp</param-value>
    </context-param>
    

To summarize - the javax.faces.DEFAULT_SUFFIX determines the file extension under which the page are sought, and the <url-pattern> of the faces-servlet determines the way the jsf pages are accessed by clients (browsers)

Bozho
I am accessing page via address http://localhost:18080/web1/p1.jsp. If I change page file name to p1.jsf and URL pattern to <url-pattern>*.jsf</url-pattern> I still got the same problem. I have added faces-config.xml to the abowe question.
Rafal
but is your file named p1.page ? If so, rename it to .jsp
Bozho
No, file is was named p1.jsp. In post a have made mistake, sorry.
Rafal
then define the context-param as mentioned in my updated answer
Bozho
To sum up, I have (1) changed web page file name to p1.jsf, (2) changed in web.xml file URL patter *<url-pattern>*.jsf</url-pattern>* and (3) added to web.xml file *<context-param><param-name>javax.faces.DEFAULT_SUFFIX</param-name><param-value>.jsf</param-value></context-param>*. I have no navigation rules defined in faces-config.xml.Unfortunately, I still got the same error... **Exceeded maximum depth for nested request dispatches.**
Rafal
In previous comment point 2 should look like this (formatting issue): changed in web.xml file URL patter to <url-pattern>*.jsf</url-pattern>
Rafal
param-value shouldn't be 'jsf'..
Bozho
OK, now works! Thanks!
Rafal
A: 
  1. FacesServlet should be mapped on an url-pattern of *.jsf (or anything else other than *.jsp).
  2. No javax.faces.DEFAULT_SUFFIX is needed in web.xml if you already use JSP. The JSP page itself must actually be named pagename.jsp (and thus not pagename.jsf, this is the root cause of the recursive forward calls).
  3. Open the page in the webbrowser using the *.jsf suffix: http://example.com/context/pagename.jsf (and thus not by pagename.jsp, else you would get RuntimeException: FacesContext not found).
BalusC