我有下面列出的JSF设置。如果我打电话
http://localhost:8080/newSheet.jsf
我确实获得了原始的xhtml页面内容,而不是渲染的html输出。
我知道在SO上已多次询问过这个问题。答案是web.xml
设置不正确导致FacesServlet不被调用。
但是我的情况有所不同。我在FacesServlet.service()
上有一个断点,每次都会被击中。我还检查过,它是用所需的URL调用的。
的web.xml
<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">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!--
FacesServlet is main servlet responsible to handle all request.
It acts as central controller.
This servlet initializes the JSF components before the JSP is displayed.
-->
<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>*.jsf</url-pattern>
</servlet-mapping>
</web-app>
newSheet.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
</h:head>
<h:body>
<h:form>
<h1>
<h:outputText>Add a new sheet</h:outputText>
</h1>
<p>
<h:outputText>Description</h:outputText>
<h:inputText value="{#addSheet.description}" />
</p>
<p>
<h:outputText>Widht</h:outputText>
<h:inputText value="{#addSheet.width}" />
</p>
<p>
<h:outputText>Height</h:outputText>
<h:inputText value="#{addSheet.height}" />
</p>
<h:commandButton value="Submit" action="#{addSheet}"/>
</h:form>
</h:body>
</html>