我一直在尋找解決方案的幾天。 我的問題是..我必須在tomcat中部署一個項目,並將其作爲默認webapp。我所做的就是複製我的war文件並將其放置在tomcat/webapps文件夾中。啓動tomcat並將端口更改爲默認值。現在我可以訪問我的申請http://localhost/myapp。我想要的是看我的申請http://localhost。我怎樣才能做到這一點?在tomcat中的默認網絡應用程序
回答
您可以將您的webapp重命名爲ROOT(tomcat的默認應用程序),或者您可以使用可以處理域名和重定向(如apache httpserver)的web服務器,並在那裏配置您的站點。
第一種方法不是很優雅,但是快速而有效。
我能夠通過在server.xml文件的Host下添加具有path =「」屬性的「Context」元素來完成它。
<Context path="" docBase="/usr/local/tomcat/mywebapps/myapplication">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
注意:我正在使用Tomcat 7.此外,我必須將我的webapp移動到與默認webapps文件夾不同的位置。我還刪除了由tomcat提供的默認webapps。但是這個解決方案即使不刪除它們也可以工
這裏是我的server.xml的內容以供參考。希望這可以幫助。
<?xml version='1.0' 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 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of
the License at http://www.apache.org/licenses/LICENSE-2.0 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/server.html -->
<Server port="8005" shutdown="SHUTDOWN">
<!-- Security listener. Documentation at /docs/config/listeners.html <Listener
className="org.apache.catalina.security.SecurityListener" /> -->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener"
SSLEngine="on" />
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />
<!-- Prevent memory leaks due to use of particular java/javax APIs -->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<!-- Global JNDI resources Documentation at /docs/jndi-resources-howto.html -->
<GlobalNamingResources>
<!-- Editable user database that can also be used by UserDatabaseRealm
to authenticate users -->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</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/service.html -->
<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/http.html
(blocking & non-blocking) Java AJP Connector: /docs/config/ajp.html APR (HTTP/AJP)
Connector: /docs/apr.html Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000"
redirectPort="443" />
<!-- A "Connector" using the shared thread pool -->
<!-- <Connector executor="tomcatThreadPool" port="80" protocol="HTTP/1.1"
connectionTimeout="20000" redirectPort="443" /> -->
<!-- Define a SSL HTTP/1.1 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="443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150"
scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" /> -->
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="443" />
<!-- 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/engine.html -->
<!-- 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-howto.html
(simple how to) /docs/config/cluster.html (reference documentation) -->
<!-- <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> -->
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- 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="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase" />
</Realm>
<Host name="localhost">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn"
/> -->
<!-- Access log processes all example. Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false" />
<Context path="" docBase="/usr/local/tomcat/mywebapps/myapplication">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
</Host>
</Engine>
</Service>
</Server>
它爲我工作..感謝你很酷:) – sunnychayen 2013-02-22 09:59:24
不會這種方法在webapps下部署兩次應用程序呢?來自[官方Tomcat文檔](http://tomcat.apache.org/tomcat-8.0-doc/config/host.html):「當使用自動部署時,由XML上下文文件定義的docBase應該在appBase之外如果不是這種情況,部署Web應用程序可能會遇到困難,或者應用程序可能會部署兩次。「 – 2017-06-07 13:51:06
在webapps/ROOT下面創建index.html。
<html>
<head>
<meta http-equiv="refresh" content=0;URL="http://localhost/myapp">
</head>
<body>
</body>
</html>
您介意添加一些關於爲什麼您認爲這是問題的最佳解決方案的信息嗎? (而不是服務器端重定向)。我不認爲這是一個答案,在我投票之前我想聽聽你的推理。 – 2013-03-12 12:34:58
這隻適用於瀏覽器的客戶端(即加載和解析HTML)。例如,如果您使用Python'urllib2'或'httplib2'或'requests'庫)。 – 2014-05-01 09:18:25
如上所述,這僅僅是一個網頁,而不是真正的重定向 – AntonPiatek 2015-09-15 13:26:22
- 1. Tomcat沙盒網絡應用程序?
- 2. 在Tomcat中的默認應用
- 3. 在tomcat中更改默認應用程序6
- 4. 在tomcat 7中設置默認應用程序
- 5. 網絡應用程序,tomcat + hibernate + Guice中的內存泄露
- 6. 的Tomcat Web應用程序不能在網絡
- 7. 使我的jasperserver webapp成爲默認的tomcat應用程序
- 8. 在android中默認應用程序?
- 9. 默認頁面上的應用程序 - tomcat/java
- 10. Tomcat 7.0.41上的默認Apex應用程序
- 11. Web2py默認應用程序
- 12. 默認應用程序
- 13. 默認TabBar應用程序
- 14. Umbraco UComment在IIS7應用程序中(非默認網站)
- 15. 簡單的網絡應用程序(Tomcat)性能儀表板
- 16. tomcat 6 - 如何運行2個應用程序作爲默認?
- 17. Chrome網絡應用程序
- 18. Android網絡應用程序
- 19. iphone中的網絡應用程序
- 20. Microsoft網絡中的PHP應用程序
- 21. Tomcat網絡應用程序位置問題
- 22. Tomcat v7.023無法部署JSF2.0網絡應用程序
- 23. 無法打開「Tomcat網絡應用程序管理器」
- 24. Eclipse的Tomcat的默認網址
- 25. 如何解決網絡農場中的網絡應用程序
- 26. 在默認的Cake應用程序中刪除默認的CakePHP鏈接?
- 27. 在Linux中設置默認應用程序/程序優先級
- 28. 網絡應用認證
- 29. 一次性認證的網絡鏈接與Facebook應用程序
- 30. 更改默認應用程序的string.xml
http://stackoverflow.com/questions/715506/tomcat-6-how-to-change-the-root-application/6093662#6093662 – 2012-05-29 09:51:09
http://stackoverflow.com/questions/1363605/ tomcat-base-url-redirection – 2014-03-06 10:51:49