我试图用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
答案 0 :(得分:0)
所以我终于找到一个错误。我下载了不正确的库javax.faces-2.2.8-sources.jar,正确的库应该是javax.faces-2.2.8.jar