準確地說,我需要從外部目錄中獲取圖片,例如:C:/MWDB
。 我發現這個鏈接:How to config Tomcat to serve images from an external folder outside webapps?,我想跟隨你需要在你的server.xml中添加一個目錄的部分。context
標籤。如何從Tomcat的外部目錄請求內容?
所以基本上基於它說我來了,這應該是這樣的方式:
<Context docBase="C:/MWDB" path="/images" reloadable="true" source="org.eclipse.jst.jee.server:Duck"/>
(要求:www.example.com/images/image.png)用這種方式,而restaring它彈出的服務器我一個錯誤說
在本地主機服務器遇到了問題
然後我這樣做:<Context docBase="C:/MWDB" path="/images"/>
這個我甚至不能訪問我的index.html文件
FULL server.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<Server port="20011" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
<GlobalNamingResources>
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
</GlobalNamingResources>
<Service name="Catalina">
<Connector connectionTimeout="20000" port="20012" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector port="20013" protocol="AJP/1.3" redirectPort="8443"/>
<Engine defaultHost="localhost" name="Catalina">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log" suffix=".txt"/>
<Context docBase="C:/MWDB" path="/images" reloadable="true" source="org.eclipse.jst.jee.server:Duck"/></Host>
</Engine>
</Service>
</Server>
我使用Java 8的Apache Tomcat 9.0