我在部署 JSF 页面时收到此错误。我使用Hibernate。我想用一个Java类创建一个简单的JSP表单。
javax.servlet.ServletException: PWC1232: 超出了嵌套请求调度的最大深度: 20
我的faces-config.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
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">
<managed-bean>
<managed-bean-name>modelTime</managed-bean-name>
<managed-bean-class>org.projet.ModelTime</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule> <display-name> home</display-name>
<from-view-id> /index.jsp</from-view-id>
<navigation-case> <from-outcome>newTimesheet</from-outcome>
<to-view-id> /newTimesheet.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
我的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>Time</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>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>*.jsp</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
</web-app>
我的newTimesheet.jsp
:
<%@ page session="true" isThreadSafe="true" import="org.projet.*,java.net.*, java.io.*, java.util.*,net.sf.hibernate.*,net.sf.hibernate.cfg.*,net.sf.hibernate.expression.*" %>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>NewTimesheet</title>
</head>
<body topmargin="0" leftmargin="0" vlink="#0000FF" alink="#0000FF">
<div align="left">
<table border="0" cellpadding="0" cellspacing="0" bordercolor="#111111" width="84%" height="228" align="left">
<tr>
<td width="13%" height="35" align="left" valign="top"> </td>
<td width="87%" height="35" align="left" valign="bottom">
<font face="Arial"><b>Create a new "timesheet"</b></font></td>
</tr>
<tr>
<td width="14%" height="192" align="left" valign="top"> </td>
<td width="86%" height="192" align="left" valign="top">
<form method="POST" action="newTimesheet.jsp">
<input type="hidden" name="CID" value="1">
<font face="Courier New"><font size="2"><br>
<br>
Category: </font>
<input type="text" name="formCategoryMsg" size="38"><font size="2"><br>
Description: </font><input type="text" name="formCategoryDescription" size="38"><br>
</font></p>
<p align="left"><font face="Courier New">
<input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></font></p>
</form>
<p> </td>
</tr>
</table>
</div>
</body>
</html>
<%!
这是如何造成的,我该如何解决?
此条目
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
导致FacesServlet
在无限循环中运行,因为 JSF 在解析视图时将委托给 JSP servlet,但您已经映射了FacesServlet
以侦听与 servletcontainer 的内置 JSP servlet 相同的 URL 模式!
将其替换为更特定于 JSF 的 URL 模式,例如 *.jsf
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
并将 JSF 请求 URL 更改为以 *.jsf
结尾。
与具体问题无关,您的表单没有使用 JSF 标记和托管 Bean 绑定。所以我想知道 JSF 配置与您有何关系。您可能想先花时间学习 JSF。