方式一:配置server.xml文件
配置虛擬目錄要在tomcat的conf目錄下的server.xml的<Host>節點添加如下代碼:
<!-- This is the virtual directory -->
<Context path="/web_virtual_directory" docBase="f:\web_virtual_directory" />
其中各參數的含義如下:
http://localhost:8080/web_virtual_directory/
path="/web_virtual_directory":表示web應用的虛擬路徑
docBase="f:\web_virtual_directory":表示該web應用的實際路徑
配置的虛擬目錄中的文件如下:

啟動tomcat,則瀏覽器中輸入http://localhost:8080/web_virtual_directory/hello.html,則tomcat就會到localhost對應的主機的F盤下找到web_virtual_directory這個web應用。最終瀏覽器中的內容如下:

方式二(不用修改server.xml文件,推薦使用此方法)
在$CATALINA_BASE/conf/[enginename]/[hostname]/中添加一個.xml文件,文件名最好跟web應用相同,此文件名將作為Context中的path屬性值,即:

web_test.xml文件中的內容如下:
<Context docBase="F:\web_virtual_directory\web_test" />
此時tomcat服務器會自動檢測到添加的這個xml文件,並部署上相應的web應用,即部署上web_test這個web應用。在瀏覽器中輸入http://localhost:8080/web_test/hello.html,則tomcat會自動找到F:\web_virtual_directory下的名為web_test的web應用,最終顯示如下:

附:context元素的常用屬性
