eclipse - 尝试在 tomcat 上部署我的 Web 应用程序的 war 文件时出现 HTTP 状态 404 错误

标签 eclipse jsp tomcat

我知道之前有人问过这个问题,但给出的任何答案都没有解决我的问题。

我在 Eclipse 中使用 JSP 创建了一个名为 JSP_web_application_01 的 Web 应用程序,我使用的是 ubuntu 12.04 LTS。我在 WebContent 目录中有 index.jsp 文件。我使用命令提示符制作了它的 .war 文件,为了部署它,我将它放在 tomcat 的 webapps 文件夹中,并使用命令 sudo $CATALINA_HOME/bin/shutdown.sh 停止了 tomcat,然后再次通过 sudo $CATALINA_HOME/启动它bin/startup.sh

它膨胀了 .war 文件 (JSP_web_application_01.war) 并创建了 JSP_web_application_01 文件夹结构和所有内容,但当我尝试从浏览器访问它时,我得到的是一个 http 404 状态代码:

http://localhost:8080/JSP_web_application_01/

我明白了:

HTTP Status 404 - /JSP_web_application_01/
type Status report
message /JSP_web_application_01/
description The requested resource is not available.
Apache Tomcat/7.0.47

这是我的 web.xml 文件,位于 WebContent/WEB-INF 文件夹中

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
    <display-name>JSP_web_application_01</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>
</web-app>

这是我第一次尝试托管 Web 应用程序。因此,我们将不胜感激任何帮助。

最佳答案

你的步骤似乎没问题,用单个文件替换欢迎文件列表,如果你想加载 index.html 。那么,

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
    <display-name>JSP_web_application_01</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

在将项目部署为 .war 之前,还要清理并构建项目以消除错误

阅读herehere了解有关部署描述符的更多信息。

希望对您有所帮助!

关于eclipse - 尝试在 tomcat 上部署我的 Web 应用程序的 war 文件时出现 HTTP 状态 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20896581/

相关文章:

java - 如何在云上部署Maven Web服务?

java - 我无法在 Eclipse 中配置 JavaFx SDK 路径

visual-studio - 从 Visual Studio 迁移到 Eclipse

java.util.并发.ExecutionException : Failed to initialize component

java - BasicTomcat 身份验证失败

android - 如何解决这个 : 'Running android lint' issue

java - Jsp - 访问 pdf - 使用 URL- "save or open"窗口在单击时显示错误

html - 图像未显示在 JSP 页面上

java - 多进程监听端口时,tomcat为什么会收到请求?

ruby-on-rails - Ruby on Rails - Controller 更改未被识别