Tomcat 服務(wù)器是一個(gè)免費(fèi)的開(kāi)放源代碼的 Web 應(yīng)用服務(wù)器,屬于輕量級(jí)應(yīng)用服務(wù)器,在中小型系統(tǒng)和并發(fā)訪問(wèn)用戶不是很多的場(chǎng)合下被普遍使用,是開(kāi)發(fā)和調(diào)試 JSP 程序的首選。但是有些小伙伴在啟動(dòng)Tomcat時(shí)也會(huì)遇到各種各樣的問(wèn)題,比如Tomcat的startup.bat啟動(dòng)后出現(xiàn)亂碼,端口占用,啟動(dòng)后閃退等問(wèn)題,這里我們來(lái)一一進(jìn)行解決
問(wèn)題一:Tomcat的startup.bat啟動(dòng)后出現(xiàn)亂碼
找到Tomcat文件下的conf目錄,修改logging.properties文件中java.util.logging.ConsoleHandler.encoding對(duì)應(yīng)的值為GBK
重啟Tomcat,你看到的啟動(dòng)頁(yè)面是這樣的話,說(shuō)明亂碼問(wèn)題已經(jīng)解決
問(wèn)題二:一閃而退之端口占用
啟動(dòng)Tomcat出現(xiàn)一閃而退的現(xiàn)象,其實(shí)還是可以看到Tomcat終端輸出的日志,這時(shí)你需要迅速截圖捕獲異常,太南了。
最正確的方法是查看日志,找到Tomcat目錄下的logs目錄中catalina當(dāng)天的日志,我這里找到的是C:\develop\Tomcat\apache-tomcat-8.5.47\logs\catalina.2019-10-17.log
,在日志中可以看到類似這樣的輸出,Address already in use: bind
說(shuō)明是端口占用了
17-Oct-2019 11:14:30.521 嚴(yán)重 [main] org.apache.catalina.core.StandardService.initInternal Failed to initialize connector [Connector[HTTP/1.1-8080]]
org.apache.catalina.LifecycleException: Protocol handler initialization failed
at org.apache.catalina.connector.Connector.initInternal(Connector.java:995)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
at org.apache.catalina.core.StandardService.initInternal(StandardService.java:552)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:848)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
at org.apache.catalina.startup.Catalina.load(Catalina.java:639)
at org.apache.catalina.startup.Catalina.load(Catalina.java:662)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:309)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)
Caused by: java.net.BindException: Address already in use: bind
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:433)
at sun.nio.ch.Net.bind(Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:219)
at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:1118)
at org.apache.tomcat.util.net.AbstractJsseEndpoint.init(AbstractJsseEndpoint.java:224)
at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:581)
at org.apache.coyote.http11.AbstractHttp11Protocol.init(AbstractHttp11Protocol.java:68)
at org.apache.catalina.connector.Connector.initInternal(Connector.java:993)
... 13 more
在Tomcat目錄找到conf目錄中的server.xml配置文件,在Connector標(biāo)簽中修改Tomcat啟動(dòng)端口
<Connector port="9080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
問(wèn)題三:非端口問(wèn)題的一閃而退
啟動(dòng)Tomcat直接一閃而退,在logs目錄的日志里面找不到錯(cuò)誤信息,這個(gè)時(shí)候很大可能是因?yàn)門omcat與JDK版本不對(duì)應(yīng)導(dǎo)致的,有可能你的Tomcat是Tomcat9版,而你的JDK是1.7版本的,Tomcat與JDK版本對(duì)應(yīng)關(guān)系可以參考這篇文章Tomcat與JDK版本對(duì)應(yīng)關(guān)系,Tomcat各版本特性
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。