Tomcat配置虚拟文件路径

Tomcat配置虚拟文件路径

1、编辑tomcat的conf目录下server.xml

在 <Host name=“localhost” appBase=“webapps”…中添加

<Context path="files" reloadable="true" docBase="/tomcatVirtualDir" debug="" />

其中 path=“files” :为配置的虚拟路径
docBase=“/tomcatVirtualDir” :为文件存储的物理路径
如:在tomcatVirtualDir目录下面存储有文件:
在这里插入图片描述

2、保存文件server.xml,重启tomcat

3、编写测试文件tomcat_virtual.html

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>文件服务器测试</title>
</head>

<body>

<div class="userC clear">
    <div class="userCd"><a href="http://ip:端口/files/spring-boot-reference5.pdf">下载pdf文件</a></div>
</div>

<div class="userC clear">
    <div class="userCd"><p>显示图片:  <img src="http://ip:端口/files/头像.png"></img></p></div>
</div>

</body>
</html>

其中,

 <div class="userCd"><a href="http://ip:端口/files/spring-boot-reference5.pdf">下载pdf文件</a></div>

地址中包含的,**/files**即为配置得虚拟路径地址

4、运行tomcat_virtual.html 测试

在这里插入图片描述

点击“下载pdf文件”
在这里插入图片描述
符合预期, 客户端通过地址的形式获取到了服务器上存储的文件。

猜你喜欢

转载自blog.csdn.net/qq_29025955/article/details/109095404