tomcat配置虛擬路徑,供使用者訪問靜態資源

來源:互聯網
上載者:User

標籤:

tomcat配置虛擬路徑,供使用者訪問靜態資源

在實際開發中,後台需要提供給使用者訪問靜態資源,而且該靜態資源不是在tomcat中,即不是在web目錄下,那麼使用者是不能訪問的,這時,需要配置tomcat伺服器的虛擬路徑。可以這樣理解這個虛擬路徑,就是相當於把該路徑映射成一個web工程,這樣這些靜態資源就相當於在web路徑下了,使用者也就可以訪問了。

簡單的配置如下:tomcat安裝目錄/conf/server.xml      在最後面可以看到Host標籤,在該標籤中增加一個Context標籤如下即可。

      <Host name="localhost"  appBase="webapps"            unpackWARs="true" autoDeploy="true"><!-- 增加虛擬路徑,供訪問本地圖片--><Context path="/upload_file" docBase="D:/upload/img" reloadable="false" ></Context>      </Host>

其中,path是映射的web路徑,doBase是本地磁碟的實體路徑。如資源 D:/upload_img/111.jpg,可通過http://lcoalhost:8080/upload_file/111.jpg  訪問。


tomcat配置虛擬路徑,供使用者訪問靜態資源

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.