【发布时间】:2018-08-23 10:24:44
【问题描述】:
我尝试在 jsf 中制作一个 hello world 程序。我想在eclipse中运行xhtml文件(我还没用过Java),但我无法启动它。我只收到一般错误
HTTP 状态 404 - 未找到:说明源服务器未找到目标资源的当前表示或不愿透露存在的表示。
我的其他 .jsp 文件运行没有问题。当我运行 xhtml 文件时,这是在浏览器中显示的确切链接:http://localhost:8080/JSFProjectHello/faces/hello-world.xhtml 有 jsf 项目的文件:
/JSFProjectHello/WebContent/hello-world.xhtml
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:a="http://xmlns.jcp.org/jsf/passthrough">
<h:head>
<title>Hello World - Input Form</title>
</h:head>
<h:body>
<h:form>
<h:inputText id="name" value="#{theUserName}"
a:placeholder="What's your name?" />
<h:commandButton value="Submit" action="myresponse" />
</h:form>
</h:body>
</html>
.
/JSFProjectHello/WebContent/hello-world.xhtml
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Hello World - Response</title>
</h:head>
<h:body>
Hello, #{theUserName}
</h:body>
</html>
.
/JSFProjectHello/WebContent/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>JSFProjectHello</display-name>
<welcome-file-list>
<welcome-file>hello-world.xhtml</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>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
。 最后,我应该补充一下,我使用 Java8 并作为服务器 Tomcat9。我已经将此库导入到项目中:
/JSFProjectHello/WebContent/WEB-INF/lib/javax.faces-2.2.8-sources.jar
【问题讨论】:
-
/WebContent/在这里合适吗?我的应用程序中有web。 -
仔细阅读@JasperDeVries 发布的链接。 faces 文件夹是多余的