首页 > 解决方案 > 找不到网页 HTTP 404 - JSF 页面

问题描述

我是 JSF 的新手,需要帮助来解决问题。我正在创建简单的项目(JSFForm)。

当我执行该项目时,它显示了以下消息。

找不到网页 - HTTP 404。

在 URL 上:http://localhost:8080/JSFForm/faces/index.xhtml。

我已经包含了 jsf-api-2.2.2.jarjavax.faces-2.2.8.jar库。

我正在使用Apache Tomcat 9

这是index.xhtml代码:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
 xmlns:f="http://java.sun.com/jsf/core"
 xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</h:head>
    <h:body>
    <h:form>
        <h:inputText/>
        <h:inputTextarea/>
        <h:inputSecret/>
        <h:inputHidden/>
    </h:form>
    </h:body>
</html>

这是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>JSFForm</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>/faces/*</url-pattern>
  </servlet-mapping>
</web-app>

这是faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd"
version="2.3">
</faces-config>

这是我在 Eclipse 上使用的引用库的屏幕截图:

引用的库

这是运行程序后在浏览器上查看页面源的屏幕截图:

查看页面来源

这是Java 构建路径的屏幕截图:

Java 构建路径

这是Project Facets的屏幕截图:

项目方面

标签: javajspservletsjsf-2http-status-code-404

解决方案


推荐阅读