eclipse Tomcat 工作正常,但我无法访问 http://localhost:8080/

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2848194/
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-09-10 19:24:39  来源:igfitidea点击:

Tomcat works but I can't reach http://localhost:8080/

eclipsetomcat6

提问by Milan

When I run Tomcat from the windows tray, it starts and I can't reach http://localhost:8080/Tomcat homepage, but if I run it from Eclipse, it works, my applications works, but I can't reach the http://localhost:8080/...

当我从 Windows 托盘运行 Tomcat 时,它启动并且我无法访问http://localhost:8080/Tomcat 主页,但是如果我从 Eclipse 运行它,它可以工作,我的应用程序可以工作,但我无法访问http://localhost:8080/...

How to solve it? Or is it normal?

如何解决?还是正常的?

Thanks!

谢谢!

回答by VonC

This maybe normal, according to this thread:

根据这个线程,这可能是正常的:

This is normal.
To see why, double-click on the Tomcat server in the Servers view. This will open the Tomcat configuration editor. Click on the "Open launch configuration" link in the Overview section. This will open the launch configuration properties dialog. Select the Arguments tab and examine the contents of the VM Arguments field.

Note that the catalina.homeproperty points to your Tomcat installation, but catalina.basepoints to a ".metadata\.plugins\org.eclipse.wst.server.core\tmp" directory under your workspace.
Thus, you are running a separate instance of Tomcat. The "webapps" directory under the ".metadata\...\tmp" directory contains only an "empty" ROOT webapp plus any web projects you have added to the server. This is why you get the 404.

In the Tomcat configuration editor, you can uncheck the "Run modules directly from the workspace (do not modify the Tomcat installation)" option and catalina.baseand catalina.homewill both be set to your Tomcat installation.
Be aware that in this configuration, the Tomcat server in Eclipse "owns" your Tomcat installation.
Every time you start the Tomcat server from Eclipse, the Tomcat files under the Servers project in your workspace will overwrite the files in your installation.

It was assumed the most would want to keep their Tomcat installation independent from Eclipse Tomcat server, so the default is to create a separate Tomcat instance.
With separate instances, you can run the Tomcat installation at the same time as the Eclipse Tomcat server provided you modify one or both of them so that the ports they use do not conflict.

If you would like the standard Tomcat webapps present while keeping the separate Tomcat instance in Eclipse, switch to the Modules tab in the Tomcat configuration editor and use the "Add External Web Module" button to manually add the desired webapps. Note that this will add a little bit to the startup time for the server.

这是正常的。
要了解原因,请在“服务器”视图中双击 Tomcat 服务器。这将打开 Tomcat 配置编辑器。单击概述部分中的“打开启动配置”链接。这将打开启动配置属性对话框。选择 Arguments 选项卡并检查 VM Arguments 字段的内容。

请注意,该catalina.home属性指向您的 Tomcat 安装,但catalina.base指向.metadata\.plugins\org.eclipse.wst.server.core\tmp您的工作区下的“ ”目录。
因此,您正在运行一个单独的 Tomcat 实例。“ webapps”目录下的“ .metadata\...\tmp”目录仅包含一个“空”ROOT webapp以及您添加到服务器的任何Web项目。这就是你得到 404 的原因。

在 Tomcat 配置编辑器中,您可以取消选中“直接从工作区运行模块(不要修改 Tomcat 安装)”选项,catalina.base并且catalina.home都将设置为您的 Tomcat 安装。
请注意,在此配置中,Eclipse 中的 Tomcat 服务器“拥有”您的 Tomcat 安装。
每次从 Eclipse 启动 Tomcat 服务器时,您工作区中 Servers 项目下的 Tomcat 文件都会覆盖您安装中的文件。

假设大多数人希望他们的 Tomcat 安装独立于 Eclipse Tomcat 服务器,所以默认是创建一个单独的 Tomcat 实例。
对于单独的实例,您可以与 Eclipse Tomcat 服务器同时运行 Tomcat 安装,前提是您修改其中一个或两个,以便它们使用的端口不冲突。

如果您希望在 Eclipse 中保留单独的 Tomcat 实例的同时出现标准的 Tomcat webapps,请切换到 Tomcat 配置编辑器中的 Modules 选项卡并使用“Add External Web Module”按钮手动添加所需的 webapps。请注意,这会增加服务器的启动时间。

Note this is for tomcat versions that use WTP x1.5 (seems to be tomcat 5 or below), in tomcat with WTP(Web tools platform) x2.0 and above you no longer get that option. Instead you need to go into server properties and hit switch location which will then show a proper path. then you go into the server config (double clicking the server opens config) and change the "Server Location" to "use Tomcat instillation" (the middle one).2

请注意,这是针对使用 WTP x1.5(似乎是 tomcat 5 或更低版本)的 tomcat 版本,在使用 WTP(Web 工具平台)x2.0 及更高版本的 tomcat 中,您不再获得该选项。相反,您需要进入服务器属性并点击开关位置,然后将显示正确的路径。然后进入服务器配置(双击服务器打开配置)并将“服务器位置”更改为“使用Tomcat灌输”(中间的)。2

回答by Filza Naser

Understanding Web Application Structure

了解 Web 应用程序结构

A web application is a collection of web resources, such as JSP pages, HTML pages, servlets, and configuration files, organized into a hierarchy as specified in the Servlet specification. You have two ways in which to organize a web application: packed and unpacked. The packed form is called a web archive (WAR) file, and the unpacked form is a collection of directories stored on the file system. The unpackaged format is convenient for web application developers, as it allows them to replace individual files while the application is being developed and debugged. However, in a deployment environment, it's often more convenient to provide a single file that can be automatically deployed. This reduces the deployment process to placing the file and setting up system resources. Tomcat can also automatically expand a web application once the server has booted. The automatic expansion of WAR files is configured in the server.xml file as part of the element that configures hosts.

Web 应用程序是 Web 资源的集合,例如 JSP 页面、HTML 页面、servlet 和配置文件,按照 Servlet 规范中的规定组织成一个层次结构。您可以通过两种方式组织 Web 应用程序:打包和解包。打包形式称为 Web 归档 (WAR) 文件,解压缩形式是存储在文件系统上的目录集合。未打包的格式对于 Web 应用程序开发人员来说很方便,因为它允许他们在开发和调试应用程序时替换单个文件。但是,在部署环境中,提供可以自动部署的单个文件通常更方便。这减少了放置文件和设置系统资源的部署过程。一旦服务器启动,Tomcat 还可以自动扩展 Web 应用程序。WAR 文件的自动扩展在 server.xml 文件中配置为配置主机的元素的一部分。

Web Application Context

Web 应用程序上下文

Each web application corresponds to a context component, as discussed in Chapter 1, and you assign a context path to each. The default context is called ROOT and corresponds to the name of the server with no other context information. For example, the ROOT web application on your local machine will correspond to http://localhost:8080.If you've configured Domain Name System (DNS) settings for your server, it may also be accessible from a location such as

每个 Web 应用程序对应一个上下文组件,如第 1 章所述,您可以为每个应用程序分配一个上下文路径。默认上下文称为 ROOT,对应于没有其他上下文信息的服务器名称。例如,您本地计算机上的 ROOT Web 应用程序将对应于http://localhost:8080.如果您为服务器配置了域名系统 (DNS) 设置,它也可以从以下位置访问,例如

Users access other web applications by requesting a context relative to the server. For example, users can access Tomcat's manager web application with the following URL:

用户通过请求与服务器相关的上下文来访问其他 Web 应用程序。例如,用户可以使用以下 URL 访问 Tomcat 的管理器 Web 应用程序:

http://
localhost:8080/manager.

Applications that you place in the webapps folder are named after the directory they're in. So, you can access the web application in the tomcat-docs directory with the following: http://localhost:8080/tomcat-docs.Each application on the server is known by its name, and users can access resources according to the remainder of the uniform resource locator (URL) after the web application's name.

您放置在 webapps 文件夹中的应用程序以其所在的目录命名。因此,您可以使用以下内容访问 tomcat-docs 目录中的 Web 应用程序: http://localhost:8080/tomcat-docs.服务器上的每个应用程序都以其名称为已知,并且用户可以根据 Web 应用程序名称后的统一资源定位符 (URL) 的其余部分访问资源。