eclipse - 我的第一个 JSF 程序出错。 Tomcat 和 Eclipse

标签 eclipse jakarta-ee tomcat jsf-2

我是 Java 的初学者。我正在使用 eclipse Helios 和 Tomcat 7。

我配置了服务器并编写了我的第一个 JSF 页面,但出现了这个错误:

HTTP Status 404 - /
type Status report
message /
description The requested resource (/) is not available.
Apache Tomcat/7.0.27

第一页的代码是这样的:

<?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:f="http://java.sun.com/jsf/core"      
      xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <title>JSF 2.0 Hello World</title>
    </h:head>
    <h:body>
        <h3>JSF 2.0 Hello World Example - hello.xhtml</h3>

    </h:body>
</html>

然后我将端口更改为 8088。但是当我在浏览器中键入 localhost:8088 时,我得到了同样的错误。

最佳答案

这可能是由几个常见原因引起的:

  • 很可能是因为您在启动时尝试访问类似这样的内容:localhost:8080/MyProject/

    要做到这一点,您必须在 web.xml 中指定欢迎文件列表:

    <welcome-file-list>
       <welcome-file>index.xhtml</welcome-file>
     </welcome-file-list>
    

    如果您还没有指定 servlet 映射,请添加这些行:

      <servlet-mapping>
       <servlet-name>Faces servlet</servlet-name>
       <url-pattern>*.xhtml</url-pattern>
      </servlet-mapping>
    

    确保您的 index.xhtml 文件位于网页文件夹中。

  • 您已将您尝试访问的 .xhtml 文件放置在 Wep 页面文件夹之外的某处。

  • 您正在尝试访问一些不存在的 .xhtml。

我敢打赌这是第一个,因为日志错误显示:资源 (/),所以您可能正在尝试访问欢迎文件。

希望对您有所帮助!

关于eclipse - 我的第一个 JSF 程序出错。 Tomcat 和 Eclipse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10154579/

相关文章:

android - BuildConfig.DEBUG 保持为真

java - 查找 Eclipse 项目中的错误数

java - 使用 hibernate 在 JPA 中配置 EntityManager

java - Tomcat - 未找到 Spring DataSource JNDI 但它存在

eclipse - 更新sts或安装扩展时出现问题

c++ - Eclipse CDT 中优化的项目结构

Spring 加载 : Integration with Spring MVC maven project

java - Netty 比 Tomcat 慢

java - Hibernate 使用 hbm.xml 将多个类映射到一个表

java - 将 JoinColumn 参数 insertable 和 updateable 设置为 null