Java 如何在 localhost:8080/test/index.html 中打开我的资源?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20987714/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 05:45:24  来源:igfitidea点击:

How to open my resource in that localhost:8080/test/index.html?

javaeclipsejakarta-eetomcat

提问by Shans Muga

Tomcat started in eclipse and also I'm able to open the following URL in the browser:

Tomcat 在 Eclipse 中启动,我也可以在浏览器中打开以下 URL:

http://localhost:8080/test/index.html

But, I'm not able to open my resource in that page.

但是,我无法在该页面中打开我的资源。

Error that I am getting is:

我得到的错误是:

HTTP Status 404 - /
type Status report
message http:/test/index.html
description The requested resource (/test/index) is not available.
Apache Tomcat/6.0.29

回答by Bj?rn Steinemann

Please, try the following steps in eclipse to deploy the project as a WAR Fileand not as an EAR File:

请在 Eclipse 中尝试以下步骤,将项目部署为WAR 文件而不是EAR 文件

  1. In the Project Explorerright click on test(which is the name of your project, if I got it right)
  2. In the context menu choose Export->WAR file
  3. In the dialog window that pops up click the Browse...button to choose the destination folder for the deployment. This should be the web application folder of your Tomcatinstallation: <TOMCAT_INSTALLATION>/webappswhere <TOMCAT_INSTALLATION>is the folder you have installed Tomcat in.
  4. Click Finish
  1. Project Explorer右键单击test(这是您项目的名称,如果我没听错的话)
  2. 在上下文菜单中选择 Export->WAR file
  3. 在弹出的对话窗口中单击Browse...按钮选择部署的目标文件夹。这应该是您Tomcat安装的 Web 应用程序文件夹:您安装 Tomcat 的文件夹<TOMCAT_INSTALLATION>/webapps在哪里<TOMCAT_INSTALLATION>
  4. 点击 Finish

Now start your Tomcat server. Assuming you have the index.htmlfile in the WebContentfolder of the testproject in Eclipse, you should see the content of index.htmlin your browser when you open the URL.

现在启动您的 Tomcat 服务器。假设您在 Eclipse中的项目文件夹中有该index.html文件,那么当您打开 URL 时,您应该会在浏览器中看到 的内容。WebContenttestindex.html