第一種:復(fù)制要訪問(wèn)的文件a.txt至tomcat安裝路徑下的webapps/ROOT文件夾下:
? ? ? ? ? ? 訪問(wèn)路徑為:localhost:8080/a.txt
? ? ? ? ? ? 或者在webapps文件夾下新建一個(gè)文件夾(test)灵再,將文件b.txt放在test文件夾下:
? ? ? ? ? ? 訪問(wèn)路徑:localhost:8080/test/b.txt
第二種:在tomcat安裝路徑下的conf/server.xml文件中缔杉,找到host節(jié)點(diǎn)元素,在host節(jié)點(diǎn)內(nèi)定義子節(jié)點(diǎn)Context節(jié)點(diǎn)匣沼,該節(jié)點(diǎn)必須定義doBase(實(shí)際文件所在文件夾路徑:例F:\test)屬性,path(訪問(wèn)虛擬路徑:例/test)屬性郊供,如下
<Context doBase="F:\test" path="/t"></Context>
? ? ? ? ? ? 訪問(wèn)路徑:localhost:8080/t/c.txt? 即可訪問(wèn)到實(shí)際路徑F:\test\c.txt文件
第三種:在tomcat安裝目錄下conf/server.xml文件中找到Engine節(jié)點(diǎn)的name屬性指定的文件夾/defaultHost屬性名稱的文件夾下(conf/Catalina/localhost)新建一個(gè)d.xml文件,文件中除了xml文件所需的頭標(biāo)簽尿招,還必須有Context標(biāo)簽诀豁,必須有doBase屬性窄刘,如下
<?xml version='1.0' encoding='utf-8'?>
<Context doBase="F:\test" ></Context>
? ? ? ? ? ? 訪問(wèn)路徑:localhost:8080/d.txt