需求: 如何能讓其他的電腦訪問我這臺電腦上的資源 ? stu.xml
拷貝這個文件到webapps/ROOT底下, 在瀏覽器裏面訪問。
http://localhost:8080/stu.xml
在webaps下面新建一個文件夾xml , 然後拷貝文件放置到這個文件夾中
http://localhost:8080/xml/stu.xml
http://localhost:8080 : 對應的是到webapps/root
http://localhost:8080/xml/ : 對應是 webapps/xml
使用IP地址訪問:http://本機ip:8080/xml/stu.xml
配置虛擬路徑 1
使用localhost:8080 打開tomcat首頁, 找到Tomcat 8.5 Documentation,進入Reference,點擊configuration ,找到左邊的context,點擊進入,複製此頁面路徑:
http://localhost:8080/docs/config/context.html
- 在conf/server.xml 找到host元素節點。加入以下內容。
- 在瀏覽器地址欄上輸入: http://localhost:8080/daq/person.xml
配置虛擬路徑2
-
在tomcat/conf/catalina/localhost/ 文件夾下新建一個xml文件,名字可以自己定義。 person.xml
-
在這個文件裏面寫入以下內容
<?xml version='1.0' encoding='utf-8'?>
<Context docBase="F:\XML2"></Context>
- 在瀏覽器上面訪問:
http://localhost:8080/person/xml的名字即可