从 Eclipse 运行 Tomcat 时出现 HTTP 错误 404
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14392207/
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
HTTP Error 404 when running Tomcat from Eclipse
提问by Anurag Singh
I have installed Eclipse and Tomcat 7. The error is that when I run Tomcat from Eclipse it starts, but after that, when I open localhost:8080
in Google Chrome I get HTTP Error 404()
. How can I solve this, please?
我已经安装了 Eclipse 和 Tomcat 7。错误是当我从 Eclipse 运行 Tomcat 时它会启动,但之后,当我localhost:8080
在 Google Chrome 中打开时,我得到HTTP Error 404()
. 请问我该如何解决?
回答by Vahap Gencdal
First, stop your Tomcat, then double click your server, click Server Locations
and check Use Tomcat Installation (takes control of Tomcat installation)
.
首先,停止您的 Tomcat,然后双击您的服务器,单击Server Locations
并检查Use Tomcat Installation (takes control of Tomcat installation)
。
回答by informatik01
It is because there is no default ROOT web application. When you create some web app and deploy it to Tomcat using Eclipse, then you will be able to access it with the URL in the form of
这是因为没有默认的 ROOT Web 应用程序。当您创建一些 Web 应用程序并使用 Eclipse 将其部署到 Tomcat 时,您将能够使用以下形式的 URL 访问它
http://localhost:8080/YourWebAppName
where YourWebAppNameis some name you give to your web app (the so called application context path).
其中YourWebAppName是您为 Web 应用程序指定的名称(所谓的应用程序上下文路径)。
Quote from Jetty Documentation Wiki(emphasis mine):
来自Jetty Documentation Wiki 的引用(强调我的):
The context pathis the prefix of a URL path that is used to select the web application to which an incoming request is routed. Typically a URL in a Java servlet server is of the format
http://hostname.com/contextPath/servletPath/pathInfo
, where each of the path elements may be zero or more / separated elements. If there is no context path, the context is referred to as the root context.
的上下文路径是被用来选择哪个传入的请求被路由该web应用程序的URL路径的前缀。通常,Java servlet 服务器中的 URL 的格式为
http://hostname.com/contextPath/servletPath/pathInfo
,其中每个路径元素可能是零个或多个/分隔的元素。如果没有上下文路径,则上下文被称为根上下文。
If you still want the default appwhich is accessed with the URL of the form
如果您仍然想要使用表单 URL 访问的默认应用程序
http://localhost:8080
or if you change the default 8080 port to 80, then just
或者,如果您将默认的 8080 端口更改为 80,则只需
http://localhost
i.e. without application context pathread the following (quote from Tutorial: Installing Tomcat 7 and Using it with Eclipse, emphasis mine):
即没有应用程序上下文路径,请阅读以下内容(引自教程:安装 Tomcat 7 并将其与 Eclipse 一起使用,重点是我的):
Copy the ROOT (default) Web app into Eclipse. Eclipse forgets to copy the default apps (ROOT, examples, docs, etc.) when it creates a Tomcat folder inside the Eclipse workspace. Go to C:\apache-tomcat-7.0.34\webapps and copy the ROOT folder. Then go to your Eclipse workspace, go to the .metadata folder, and search for "wtpwebapps". You should find something like
C:\your-eclipse-workspace-location\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
(or.../tmp1/wtpwebapps
if you already had another server registered in Eclipse). Go to thewtpwebapps
folder and paste ROOT (say "yes" if asked if you want to merge/replace folders/files). Then reloadhttp://localhost/
to see the Tomcat welcome page.
将 ROOT(默认)Web 应用程序复制到 Eclipse 中。Eclipse 在 Eclipse 工作区中创建 Tomcat 文件夹时忘记复制默认应用程序(ROOT、示例、文档等)。转到 C:\apache-tomcat-7.0.34\webapps 并复制 ROOT 文件夹。然后转到 Eclipse 工作区,转到 .metadata 文件夹,然后搜索“wtpwebapps”。您应该找到类似的东西
C:\your-eclipse-workspace-location\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
(或者.../tmp1/wtpwebapps
如果您已经在 Eclipse 中注册了另一台服务器)。转到wtpwebapps
文件夹并粘贴 ROOT(如果询问您是否要合并/替换文件夹/文件,请说“是”)。然后重新加载http://localhost/
即可看到Tomcat欢迎页面。
回答by George Fandango
Check the server configuration and folders' routes:
检查服务器配置和文件夹的路由:
Open servers view (Window -> Open view... -> Others... -> Search for 'servers'.
Right click on server (mine is Tomcat v6.0) -> properties -> Click on 'Swicth Location' (check that location's like /servers...
Double click on the server. This will open a new servers page. In the 'Servers Locations' area, check the 'Use Tomcat Installation (takes control of Tomcat Installation)' option.
Restart your server.
Enjoy!
打开服务器视图(窗口 -> 打开视图... -> 其他... -> 搜索“服务器”。
右键单击服务器(我的是 Tomcat v6.0)-> 属性-> 单击“切换位置”(检查该位置是否类似于 /servers...
双击服务器。这将打开一个新的服务器页面。在“服务器位置”区域,选中“使用 Tomcat 安装(控制 Tomcat 安装)”选项。
重新启动您的服务器。
享受!
回答by Hoang Duy Tran
If you changed the location, using option 'Use custom location (does not modify Tomcat installation)' and the deployed directory is "wtpwebapps" then you'll have to:
如果您更改了位置,使用选项“使用自定义位置(不修改 Tomcat 安装)”并且部署的目录是“wtpwebapps”,那么您必须:
- Swtich Location from [workspace metadata] to /Servers/Tomcat v...., click Apply, OK.
- Retart server and if you find 404 error message than the server is working, it just doesn't have the startup file at the web-server location you have chosen. If you traverse to that location, you'll find a bunch of directories that was created. One of which is wtpwebapps, under which there is ROOT. This is your web-server's directory. You will need to go back to installed Tomcat directory and copy the content of <tomcat's installed dir>/web-apps/ROOT to your wtpwebapps. Restart the webserver and you should see the tomcat default page.
- For Server Status, Manager Apps and Host Manager to work, you'll have to copy other subdirectories from <tomcat's installed dir>/webapps (ie. docs, examples, host-manager, manager) to your "webapps" (NOT the wtpwebapps) directory.
- Edit the '<your web directory>/conf/tomcat-users.xml' and enter something like:
- Then edit the '<your web directory>/conf/server.xml', add the attribute:
readonly="true"
into the <Resource/> key of the <GlobalNamingResources/> group. - Restart the server and try to login with the configured credentials.
<role rolename="manager-gui"/> <role rolename="manager-status"/> <role rolename="manager-jmx"/> <role rolename="manager-script"/> <role rolename="admin-gui"/> <role rolename="admin"/> <user username="admin" password="yourpassword" roles="admin, admin-gui, manager-gui"/>
- 从 [工作区元数据] 切换位置到 /Servers/Tomcat v....,单击应用,确定。
- 重新启动服务器,如果您发现 404 错误消息而不是服务器正在运行,则它只是在您选择的 Web 服务器位置没有启动文件。如果你遍历到那个位置,你会发现一堆创建的目录。其中之一是wtpwebapps,其下有ROOT。这是您的网络服务器的目录。您需要返回已安装的 Tomcat 目录并将 <tomcat's installed dir>/web-apps/ROOT 的内容复制到您的 wtpwebapps。重新启动网络服务器,您应该会看到 tomcat 默认页面。
- 要使服务器状态、管理器应用程序和主机管理器正常工作,您必须将其他子目录从 <tomcat 的已安装目录>/webapps(即文档、示例、主机管理器、管理器)复制到您的“webapps”(不是 wtpwebapps ) 目录。
- 编辑“<您的网络目录>/conf/tomcat-users.xml”并输入如下内容:
- 然后编辑'<your web directory>/conf/server.xml',添加属性:
readonly="true"
进入 <GlobalNamingResources/> 组的 <Resource/> 键。 - 重新启动服务器并尝试使用配置的凭据登录。
<role rolename="manager-gui"/> <role rolename="manager-status"/> <role rolename="manager-jmx"/> <role rolename="manager-script"/> <role rolename="admin-gui"/> <role rolename="admin"/> <user username="admin" password="yourpassword" roles="admin, admin-gui, manager-gui"/>
NOTE: if you change the server configuration, say if you like to compare the default configuration (use tomcat installation directory) and the 'new directory', when switching back to the 'new directory' this 'tomcat-users.xml' will be overwritten by the default file, so SAVE THE CONTENT OF THIS FILE somewhere before doing that, then copy it back. If you only give the the username "admin" role, you will be prompted of help messages. It says: you should not grant the admin-gui, or manager-gui role the 'manager-jmx' and 'manager-script' roles.
注意:如果您更改服务器配置,假设您想比较默认配置(使用 tomcat 安装目录)和“新目录”,当切换回“新目录”时,“tomcat-users.xml”将是被默认文件覆盖,因此在执行此操作之前先在某处保存此文件的内容,然后将其复制回来。如果您只授予用户名“admin”角色,您将收到帮助消息的提示。它说:您不应授予 admin-gui 或 manager-gui 角色“manager-jmx”和“manager-script”角色。
回答by Iyke Perry
Eclipse forgets to copy the default apps (ROOT, examples, etc.) when it creates a Tomcat folder inside the Eclipse workspace. Go to C:\apache-tomcat-7.0.34\webapps, R-click on the ROOT folder and copy it. Then go to your Eclipse workspace, go to the .metadata folder, and search for "wtpwebapps". You should find something like your-eclipse-workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps (or .../tmp1/wtpwebapps if you already had another server registered in Eclipse). Go to the wtpwebapps folder, R-click, and paste ROOT (say "yes" if asked if you want to merge/replace folders/files). Then reload http://localhost/to see the Tomcat welcome page.
Eclipse 在 Eclipse 工作区中创建 Tomcat 文件夹时忘记复制默认应用程序(ROOT、示例等)。转到 C:\apache-tomcat-7.0.34\webapps,右键单击 ROOT 文件夹并复制它。然后转到 Eclipse 工作区,转到 .metadata 文件夹,然后搜索“wtpwebapps”。您应该找到类似 your-eclipse-workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps(或 .../tmp1/wtpwebapps 之类的内容,如果您已经在 Eclipse 中注册了另一台服务器)。转到 wtpwebapps 文件夹,右击并粘贴 ROOT(如果询问您是否要合并/替换文件夹/文件,请说“是”)。然后重新加载http://localhost/以查看 Tomcat 欢迎页面。
回答by Vivek Bansal
- Click on Window > Show view > Server OR right click on the server in "Servers" view, select "Properties".
- OR Open the Overview screen for the server by double clicking it.
- In the Server locations tab , select "Use Tomcat location".
- Save the configurations and restart the Server.
- 单击窗口 > 显示视图 > 服务器或在“服务器”视图中右键单击服务器,选择“属性”。
- 或 通过双击打开服务器的概览屏幕。
- 在服务器位置选项卡中,选择“使用 Tomcat 位置”。
- 保存配置并重启服务器。
This way Eclipse will take full control over Tomcat, this way you'll also be able to access the default Tomcat homepage with the Tomcat Manager when running from inside Eclipse.
这样 Eclipse 将完全控制 Tomcat,这样您还可以在从 Eclipse 内部运行时使用 Tomcat 管理器访问默认的 Tomcat 主页。
回答by user2639722
Another way to fix this would be to go to the properties of the server on eclipse (right click on server -> properties) In general tab you would see location as workspace.metadata. Click on switch location.
解决此问题的另一种方法是转到 eclipse 上的服务器属性(右键单击服务器 -> 属性)在常规选项卡中,您将看到位置为 workspace.metadata。点击切换位置。
回答by user3128838
I had this or a similar problem after installing Tomcat.
安装Tomcat后我遇到了这个或类似的问题。
The other answers didn't quite work, but got me on the right path. I answered this at https://stackoverflow.com/a/20762179/3128838after discovering a YouTube video showing the exact problem I was having.
其他答案不太奏效,但让我走上了正确的道路。在发现 YouTube 视频显示我遇到的确切问题后,我在https://stackoverflow.com/a/20762179/3128838 上回答了这个问题。