tomcat端口被占用怎么回事?tomcat端口被占用的解决方法
Tomcat端口号默认使用的是8080端口,电脑打开tomcat端口的时候却提示tomcat端口被占用,Tomcat端口如果被占用的话是启动不了,大家可以在命令窗口里进行设置。接下来小编和大家详解一下tomcat端口被占用的解决方法。
tomcat端口被占用
有时候我们在eclipse中启动项目时,Tomcat服务器会报错,显示8080、8009、8005这几个端口被占用,此时你用debug启动项目时会发现不管用,console控制台什么信息也没有,此时产生这种问题的原因就是端口被占用。解决办法如下
1开始----运行----cmd,或者是window+R组合键,调出命令窗口。
2输入命令:netstat-ano,列出所有端口的情况。在列表中我们观察被占用的端口,比如是49157,首先找到它。
3查看被占用端口对应的PID,输入命令:netstat-aon|findstr49157,回车,记下最后一位数字,即PID,这里是2720。
4继续输入tasklist|findstr2720,回车,查看是哪个进程或者程序占用了2720端口,结果是:svchostexe。
5此时结果已经很明白了,接下来我们可以到控制面板中的服务区查看此进程,手动关掉它。也可以在cmd中通过命令来关闭它,输入:taskkill/f/t/imTencentdlexe。标红的就是占用端口的进程名字。
6重新启动项目,发现问题解决了。
上述教程内容就是tomcat端口被占用的解决方法,遇到相同故障问题时,希望可以解决掉您的困惑。
Tomcat安装时默认的端口设置的是8080,而http协议的默认端口是80,所以测试Tomcat时需要输入的网址为“localhost:8080”,若把Tomcat的端口设置为80,则直接输入“localhost”就能显示Tomcat默认主页,下面我们来分享下,方便需要的朋友
Tomcat安装时默认的端口设置的是8080,而http协议的默认端口是80,所以测试Tomcat时需要输入的网址为“localhost:8080”,若把Tomcat的端口设置为80,则直接输入“localhost”就能显示Tomcat默认主页
JDK,Tomcat(本文以Tomcat7027为例);
方法/步骤
1、成功安装JDK和Tomcat;
2、定位到Tomcat的安装目录:右键单击Tomcat,选择“属性”,单击“打开文件所在位置”;
3、在目录“Tomcat70\conf”下找到“serverxml”文件,用VS或者其他能解译xml文件的工具打开:
4、找到代码port=”8080”,将8080修改为80后,单击“保存”即可完成修改:
5、修改完成后需要重新启动一下服务器:先单击stop停止服务器,再单击start开启服务器:
6、重新开启服务器后打开浏览器,在地址栏中输入”localhost”并按回车键
注意:
用记事本也能打开xml文件,但是显示时未能用颜色区分代码和注释,看起来很乱,不容易找到8080;
网址输入时一般都可以省略”http://”,而且localhost也可以用“127001”代替;
更多相关内容可单击网页右上角我的用户名查看。
Tomcat服务器安装的时候默认的端口设置是8080,通常我一看到端口是8080的网站,我就猜测服务器估计是Tomcat,一般来说网站的端口普遍
是80,apache服务器的默认端口就是80,而80与8080端口有一点区别就是,如果你去访问80端口的网站,那么可以直接输入域名访问,而没必要
带上80,因为80是http协议的默认端口;但是,如果是访问8080端口的网站,那么在输入域名以后还要加上8080才行。就是因为这个繁琐的操作,
所以我每次都会修改下端口,修改方法可以参考下面:
(1)首先找到tomcat的安装路径,找到路径conf文件夹下面的serverxml文件,如下图1所示。
图1:serverxml所在路径
(2)用文本编辑器打开serverxml,修改其中端口,文件中端口有很多,比如8005,8080,8009等等,别的都可以不用管,视情况修改就好,我只修改了8080端口为80,直接查找8080替换成80就OK了,修改后的文件内容如下:
<xml version='10' encoding='utf-8'>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements See the NOTICE file distributed with
this work for additional information regarding copyright ownership
The ASF licenses this file to You under the Apache License, Version 20
(the "License"); you may not use this file except in compliance with
the License You may obtain a copy of the License at
http://wwwapacheorg/licenses/LICENSE-20
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
See the License for the specific language governing permissions and
limitations under the License
-->
<!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level
Documentation at /docs/config/serverhtml
-->
<Server port="8005" shutdown="SHUTDOWN">
<!--APR library loader Documentation at /docs/aprhtml -->
<Listener className="orgapachecatalinacoreAprLifecycleListener" SSLEngine="on" />
<!--Initialize Jasper prior to webapps are loaded Documentation at /docs/jasper-howtohtml -->
<Listener className="orgapachecatalinacoreJasperListener" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="orgapachecatalinacoreJreMemoryLeakPreventionListener" />
<!-- JMX Support for the Tomcat server Documentation at /docs/non-existenthtml -->
<Listener className="orgapachecatalinambeansServerLifecycleListener" />
<Listener className="orgapachecatalinambeansGlobalResourcesLifecycleListener" />
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howtohtml
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="orgapachecatalinaUserDatabase"
description="User database that can be updated and saved"
factory="orgapachecatalinausersMemoryUserDatabaseFactory"
pathname="conf/tomcat-usersxml" />
</GlobalNamingResources>
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level
Documentation at /docs/config/servicehtml
-->
<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned Documentation at :
Java HTTP Connector: /docs/config/httphtml (blocking & non-blocking)
Java AJP Connector: /docs/config/ajphtml
APR (HTTP/AJP) Connector: /docs/aprhtml
Define a non-SSL HTTP/11 Connector on port 8080
-->
<Connector port="80" protocol="HTTP/11"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/11"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define a SSL HTTP/11 Connector on port 8443
This connector uses the JSSE configuration, when using APR, the
connector should be using the OpenSSL style configuration
described in the APR documentation -->
<!--
<Connector port="8443" protocol="HTTP/11" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->
<!-- Define an AJP 13 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/13" redirectPort="8443" />
<!-- An Engine represents the entry point (within Catalina) that processes
every request The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host)
Documentation at /docs/config/enginehtml -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howtohtml (simple how to)
/docs/config/clusterhtml (reference documentation) -->
<!--
<Cluster className="orgapachecatalinahatcpSimpleTcpCluster"/>
-->
<!-- The request dumper valve dumps useful debugging information about
the request and response data received and sent by Tomcat
Documentation at: /docs/config/valvehtml -->
<!--
<Valve className="orgapachecatalinavalvesRequestDumperValve"/>
-->
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase" Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm -->
<Realm className="orgapachecatalinarealmUserDatabaseRealm"
resourceName="UserDatabase"/>
<!-- Define the default virtual host
Note: XML Schema validation will not work with Xerces 22
-->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valvehtml -->
<!--
<Valve className="orgapachecatalinaauthenticatorSingleSignOn" />
-->
<!-- Access log processes all example
Documentation at: /docs/config/valvehtml -->
<!--
<Valve className="orgapachecatalinavalvesAccessLogValve" directory="logs"
prefix="localhost_access_log" suffix="txt" pattern="common" resolveHosts="false"/>
-->
</Host>
</Engine>
</Service>
</Server>
(3)修改serverxml文件以后,重启tomcat服务器,配置修改成功。
Tomcat服务器安装的时候默认的端口设置是8080,通常我一看到端口是8080的网站,我就猜测服务器估计是Tomcat,一般来说网站的端口普遍
是80,apache服务器的默认端口就是80,而80与8080端口有一点区别就是,如果你去访问80端口的网站,那么可以直接输入域名访问,而没必要
带上80,因为80是http协议的默认端口;但是,如果是访问8080端口的网站,那么在输入域名以后还要加上8080才行。就是因为这个繁琐的操作,
所以我每次都会修改下端口,修改方法可以参考下面:
(1)首先找到tomcat的安装路径,找到路径conf文件夹下面的serverxml文件,如下图1所示。
图1:serverxml所在路径
(2)用文本编辑器打开serverxml,修改其中端口,文件中端口有很多,比如8005,8080,8009等等,别的都可以不用管,视情况修改就好,我只修改了8080端口为80,直接查找8080替换成80就OK了,修改后的文件内容如下:
<xml version='10' encoding='utf-8'>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements See the NOTICE file distributed with
this work for additional information regarding copyright ownership
The ASF licenses this file to You under the Apache License, Version 20
(the "License"); you may not use this file except in compliance with
the License You may obtain a copy of the License at
http://wwwapacheorg/licenses/LICENSE-20
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
See the License for the specific language governing permissions and
limitations under the License
-->
<!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level
Documentation at /docs/config/serverhtml
-->
<Server port="8005" shutdown="SHUTDOWN">
<!--APR library loader Documentation at /docs/aprhtml -->
<Listener className="orgapachecatalinacoreAprLifecycleListener" SSLEngine="on" />
<!--Initialize Jasper prior to webapps are loaded Documentation at /docs/jasper-howtohtml -->
<Listener className="orgapachecatalinacoreJasperListener" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="orgapachecatalinacoreJreMemoryLeakPreventionListener" />
<!-- JMX Support for the Tomcat server Documentation at /docs/non-existenthtml -->
<Listener className="orgapachecatalinambeansServerLifecycleListener" />
<Listener className="orgapachecatalinambeansGlobalResourcesLifecycleListener" />
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howtohtml
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="orgapachecatalinaUserDatabase"
description="User database that can be updated and saved"
factory="orgapachecatalinausersMemoryUserDatabaseFactory"
pathname="conf/tomcat-usersxml" />
</GlobalNamingResources>
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level
Documentation at /docs/config/servicehtml
-->
<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned Documentation at :
Java HTTP Connector: /docs/config/httphtml (blocking & non-blocking)
Java AJP Connector: /docs/config/ajphtml
APR (HTTP/AJP) Connector: /docs/aprhtml
Define a non-SSL HTTP/11 Connector on port 8080
-->
<Connector port="80" protocol="HTTP/11"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/11"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define a SSL HTTP/11 Connector on port 8443
This connector uses the JSSE configuration, when using APR, the
connector should be using the OpenSSL style configuration
described in the APR documentation -->
<!--
<Connector port="8443" protocol="HTTP/11" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->
<!-- Define an AJP 13 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/13" redirectPort="8443" />
<!-- An Engine represents the entry point (within Catalina) that processes
every request The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host)
Documentation at /docs/config/enginehtml -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howtohtml (simple how to)
/docs/config/clusterhtml (reference documentation) -->
<!--
<Cluster className="orgapachecatalinahatcpSimpleTcpCluster"/>
-->
<!-- The request dumper valve dumps useful debugging information about
the request and response data received and sent by Tomcat
Documentation at: /docs/config/valvehtml -->
<!--
<Valve className="orgapachecatalinavalvesRequestDumperValve"/>
-->
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase" Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm -->
<Realm className="orgapachecatalinarealmUserDatabaseRealm"
resourceName="UserDatabase"/>
<!-- Define the default virtual host
Note: XML Schema validation will not work with Xerces 22
-->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valvehtml -->
<!--
<Valve className="orgapachecatalinaauthenticatorSingleSignOn" />
-->
<!-- Access log processes all example
Documentation at: /docs/config/valvehtml -->
<!--
<Valve className="orgapachecatalinavalvesAccessLogValve" directory="logs"
prefix="localhost_access_log" suffix="txt" pattern="common" resolveHosts="false"/>
-->
</Host>
</Engine>
</Service>
</Server>
(3)修改serverxml文件以后,重启tomcat服务器,配置修改成功。
tomcat是比较常用的web服务器,那么如何修改tomcat的端口呢?下面我给大家分享一下。
01首先找到tomcat的安装目录,然后我们点击conf文件夹,如下图所示
02接下来进入conf文件夹,找到serverxml文件,端口的配置信息就在这个文件里,如下图所示
03打开serverxml文件,找到如下图所示的代码,修改port的值即可
04最后修改完毕以后我们重启tomcat服务器即可,如下图所示
本实例主要介绍修改Tomcat端口号的方法 以及当端口号发生冲突时如何解决 Connector子元素下的port是设置服务器端口 而connection Timeout则是服务器连接超时 单位为毫秒 ( )使用记事本打开Tomcat安装目录下的conf文件夹下的servlet xml文件 ( )在servlet xml文件中找到以下代码 <connector port= protocol= HTTP/ connectionTimeout= redirectPort= /> ( )将上面代码中的port= 修改为port= 即可将Tomcat的默认端口设置为 在修改端口时 应避免与公用端口冲突 建议采用默认的 端口 不要修改 除非 端口被其他程序所占用 ( )修改成功后 为了使新设置的端口生效 还需要重新启动Tomcat服务器 ( )将Tomcat端口号更改为 后 重新启动的界面如图 所示
lishixinzhi/Article/program/Java/ky/201311/28852
默认端口是:8080。
找到tomcat的安装目录,有个conf文件夹,里面有个serverxml。
<Connector port="8080" protocol="HTTP/11" connectionTimeout="20000" redirectPort="8443" />
把这个8080改成你需要的就可以了。
希望能帮到你
0条评论