Java Tomcat 启动但主页无法打开,网址为 http://localhost:8080

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

Tomcat starts but home page cannot open with url http://localhost:8080

javatomcat

提问by Aniket Joshi

I am a newbie in Java, and I am trying to develop a web application. I have Windows 7 32 bit. I have installed Java 7 and set the path and classpath as well. After that I installed Tomcat 7.

我是 Java 新手,正在尝试开发 Web 应用程序。我有 Windows 7 32 位。我已经安装了 Java 7 并设置了路径和类路径。之后我安装了Tomcat 7。

When I try to open tomcat home page using URL localhost:8080, it does not open and Tomcat stops automatically.

当我尝试使用 URL 打开 tomcat 主页时localhost:8080,它不会打开并且 Tomcat 会自动停止。

Please help me.

请帮我。

回答by Fathah Rehman P

Make sure no other application using port 8080 before starting tomcat. If that's not the problem please paste tomcat log.

在启动 tomcat 之前确保没有其他应用程序使用端口 8080。如果这不是问题,请粘贴 tomcat 日志。

If you want to change tomcat's default port, go to tomcat folder and open conffolder, in which you can see server.xml. In that file you can see something like <Connector port=. Change the port value and start tomcat.

如果要更改tomcat的默认端口,进入tomcat文件夹,打开conf文件夹,可以看到server.xml. 在该文件中,您可以看到类似<Connector port=. 更改端口值并启动tomcat。

回答by Saif Asif

For *Unix based systems, you can check the ports used by a particular application by issueing the following command in the terminal

对于基于 *Unix 的系统,您可以通过在终端中发出以下命令来检查特定应用程序使用的端口

[~/.]$ netstat -tuplen

You will get the list of all the ports that are being currently held and used by their respective process ID's

您将获得当前由各自进程 ID 持有和使用的所有端口的列表

回答by Will Keeling

Your issue is not with port 8080, but with port 8005. Port 8005is the shutdown port for Tomcat.

您的问题不在于 port 8080,而在于port 8005。Port8005是 Tomcat 的关闭端口。

Rather than trying to figure out what is using port 8005, it may just be easier to edit TOMCAT_DIR/conf/server.xmland change the shutdown port to 8006

与其试图找出正在使用端口的内容8005,不如编辑TOMCAT_DIR/conf/server.xml关闭端口并将其更改为8006

<Server port="8006" shutdown="SHUTDOWN">

回答by Aniket Joshi

My issue has solved.I was getting log as below.

我的问题已经解决。我得到的日志如下。

SEVERE: StandardServer.await: create[localhost:8005]: java.net.BindException: Cannot assign requested address: JVM_Bind

严重:StandardServer.await:create[localhost:8005]:java.net.BindException:无法分配请求的地址:JVM_Bind

My tomcat server was automatically stopping when I tried to open tomcat homepage with URL.

当我尝试使用 URL 打开 tomcat 主页时,我的 tomcat 服务器自动停止。

So I just made some changes in windows->System32->drivers->etc->host file. keep only 127.0.0.1 localhost and remove all other. your problem will be solved. Thank you guys for your help :D

所以我只是在 windows->System32->drivers->etc->host 文件中做了一些更改。仅保留 127.0.0.1 localhost 并删除所有其他内容。你的问题将得到解决。谢谢大家的帮助:D

回答by robinrjoe

If you started tomcat through eclipse, It can be solved in different ways too.

如果是通过eclipse启动tomcat,也可以通过不同的方式解决。

Method 1:

方法一:

  1. Right click on server --> Properties
  2. click on Switch location and apply.
  1. 右键单击服务器-> 属性
  2. 单击切换位置并应用。

enter image description here

在此处输入图片说明

enter image description hereMethod2:

在此处输入图片说明方法二:

  1. Double click in the server in eclipse.
  2. Change Server location to Use tomcat installation(takes control of tomcat installation).
  1. 在 eclipse 中双击服务器。
  2. 将服务器位置更改为使用 tomcat 安装(控制 tomcat 安装)。

回答by Cristian Chereji

If you have your tomcat started (in linux check with ps -ef | grep java) and you see it opened the port 8080 or the one you configured in server.xml (check with netstat --tcp -na | grep <port number>) but you still cannot access it in your browser check the following:

如果您启动了 tomcat(在 linux 中检查ps -ef | grep java),并且您看到它打开了端口 8080 或您在 server.xml 中配置的端口(检查netstat --tcp -na | grep <port number>),但您仍然无法在浏览器中访问它,请检查以下内容:

  1. It may start but with a delay of 3-5 minutes. Check the logs/catalina.out. You should see something like this when the server started completely.
    INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 38442 ms
    If you don't have this INFO line your server startup is not complete yet. The problem may occur due to the SecureRandomclass responsible to provide random Session IDs and which can cause big delays during startup. Check more details and the solution here.
  2. Check your firewall (on linux iptables -L -n): You can try to reset your firewall completely iptables -Fif you are not into an exposed environment. However, pay attention, that leaves you without protection therefore it can be dangerous.
  3. Check your selinux(if you are on linux).
  1. 它可能会启动,但会延迟 3-5 分钟。检查logs/catalina.out. 当服务器完全启动时,您应该会看到类似的内容。
    INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 38442 ms
    如果您没有此 INFO 行,您的服务器启动还没有完成。该问题可能是由于SecureRandom负责提供随机会话 ID的类而发生的,这可能会导致启动过程中出现很大的延迟。在此处查看更多详细信息和解决方案。
  2. 检查您的防火墙(在 linux 上iptables -L -n):iptables -F如果您没有进入暴露的环境,您可以尝试完全重置您的防火墙。但是,请注意,这会使您没有保护,因此可能很危险。
  3. 检查您的selinux(如果您使用的是 linux)。

These are some of the most forgotten and not obvious issues in having your Apache Tomcat up and running.

这些是在启动和运行 Apache Tomcat 过程中最容易被遗忘且不明显的一些问题。

回答by Yogesh Sanchihar

For windows user, type netstat -anin command prompt to see ports that are listening, this may come handy.

对于 Windows 用户,netstat -an在命令提示符中键入以查看正在侦听的端口,这可能会派上用场。

回答by Uday Sravan K

For mac users

对于 Mac 用户

First Try : go to activity monitor -> search for java and kill the instance then restart the server and try.

首先尝试:转到活动监视器-> 搜索 java 并终止实例,然后重新启动服务器并尝试。

Second Try: Check log file for any errors under tomcat logs folder.

第二次尝试:检查 tomcat 日志文件夹下的日志文件是否有任何错误。

Use below command to check tomcat logs in terminal

使用以下命令在终端中检查 tomcat 日志

tail -f {tomcatpath}/logs/catalina.out

Third Try: Check if node or other apps using the same port. Use below command to check which app listening to a specific port. You will see list of apps with pid in second column.

第三次尝试:检查节点或其他应用程序是否使用相同的端口。使用以下命令检查哪个应用程序侦听特定端口。您将在第二列中看到带有 pid 的应用程序列表。

lsof -i :8080 | grep LISTEN

Kill the process using below command

使用以下命令终止进程

sudo kill -9 pid

回答by ArifMustafa

I am using Eclipse Java EE IDE for Web Developers. Version: Oxygen.1a Release (4.7.1a) in Windows 8.1 x64with Apache Tomcat 8.5.24(for testing purpose).

我使用Eclipse Java EE IDE for Web Developers. Version: Oxygen.1a Release (4.7.1a) in Windows 8.1 x64Apache Tomcat 8.5.24(用于测试目的)。

Port Name & Numbers for my Tomcat Server are :

我的 Tomcat 服务器的端口名称和编号是:

Tomcat admin port   :   8005
HTTP/1.1            :   8081 (my Tomcat Listening Port Number)
AJP/1.3             :   8009

Peoples, for those the Tomcat were running good earlier, and sometimessudden after stopping tomcat serverexplicitly by pressing the below shown image button or may be other reasons.

人们,对于那些 Tomcat 运行良好的人,通过按下下面显示的图像按钮或其他原因,sometimesstopping tomcat server明确显示后突然运行。

Stopping Tomcat Server through Eclipse Standard Toolbar button explicitly

通过 Eclipse 标准工具栏按钮显式停止 Tomcat 服务器

Eitherthey continuously failed to start/restartthe tomcat with below said error:

Either他们不断失败start/restart的 tomcat 出现以下错误:

Server Tomcat vX.Y Server at localhost failed to start.

服务器 本地主机上的 Tomcat vX.Y 服务器无法启动。

orsometimes the Tomcat Server is startedbut instead of showing Tomcat Homepagein web browser, it is throwing client exception HTTP Status 404 – Not Found.in preferred web browser.

or有时,Tomcat Server is started但不是Tomcat Homepage在 Web 浏览器中显示,而是HTTP Status 404 – Not Found.在首选 Web 浏览器中引发客户端异常。

possibly, there are many reasons i.e. wrong Host namedefined, Wrong Tomcat Server Locationsdefined in eclipse, project JDK/JREversion mismatch with Tomcat JRE dependent version, maven project version mismatch due to maven.compiler.sourceand maven.compiler.targetversion not defined under properties tag, mismatch version of project facet Dynamic Web Module to 2.5/3.0, Sometimes Tomcat Server is running on Windows Services level, previous stopped Tomcat port number were still listening and the processing pidwere not killed in Tomcat defined timespan Timeouts Stop (in seconds): 15(by default)in eclipse and pidstill running, failed to start in defined Start (in seconds): XX, etc.

可能的话,有很多的原因,即错误的Host name定义,Tomcat的错误Server Locations在Eclipse中,项目定义JDK/JRE与版本不匹配Tomcat JRE dependent version,Maven项目版本不匹配,由于maven.compiler.sourcemaven.compiler.target下属性标签没有定义的版本,项目方面的动态Web模块的错配版本2.5 / 3.0,有时Tomcat的服务器正在 Windows 服务级别上运行,之前停止的 Tomcat 端口号仍在侦听,并且在 Eclipseprocessing pid中的 Tomcat 定义的时间跨度Timeouts Stop (in seconds): 15(by default)中未被杀死并且pid仍在运行,无法在定义中启动Start (in seconds): XX,等等。

Here I will give the resolution on, how to check and kill the running existing Tomcat port number's processing pid(beware, you must be aware with after effects).

在这里我将给出解决方案,如何检查并杀死正在运行的现有Tomcat端口号processing pid(注意,您必须注意后遗症)。

In Windows, open you command prompt, and follow steps(my tomcat HTTP port is 8081):

在 Windows 中,打开命令提示符,然后按照步骤操作(我的 tomcat HTTP 端口是 8081):

netstat -ano | findstr :8081
TCP    0.0.0.0:8081           0.0.0.0:0              LISTENING       2284
TCP    [::]:8081              [::]:0                 LISTENING       2284

if any listening is being there, above command will list details of port listening along with processing pidat last of the line(here pid is 2284).

如果有任何监听,上面的命令将列出端口监听的详细信息以及processing pid行的最后一个(这里的 pid 是 2284)。

now kill the running pid like:

现在杀死正在运行的pid,如:

taskkill /PID 2284 /F
SUCCESS: The process with PID 2284 has been terminated.

also illustrated the above two steps like following:

还说明了上述两个步骤,如下所示:

Killing running PID

杀死正在运行的PID

Now, after resolving above illustrated reason, start the Tomcat Server.

现在,在解决上述原因后,启动Tomcat Server.

回答by onlyme

I had the same issue. My tomcat was started but I was getting HTTP 404 page not found.However, in my situation, I installed tree instances of tomcat. Each instance contains conf, temp, work, webapps and logs folders. Unless I forgot, to copy the global web.xml under conf folder of each tomcat.

我遇到过同样的问题。我的 tomcat 已启动,但未找到 HTTP 404 页面。但是,在我的情况下,我安装了 tomcat 的树实例。每个实例都包含 conf、temp、work、webapps 和 logs 文件夹。除非我忘了,把全局的web.xml 复制到每个tomcat 的conf 文件夹下。

    e.g: /opt/tomcat/mytomcatInstance/conf/web.xml 

The web.xml Deployment Descriptor file describes how to deploy a web application in a servlet container.

web.xml 部署描述符文件描述了如何在 servlet 容器中部署 Web 应用程序。

So even if my tomcat was up, my web apps could not be deployed properly.

因此,即使我的 tomcat 已启动,我的网络应用程序也无法正确部署。