原因:TOMCAT重启后,会重新部署项目文件(即清零重来)
WINDOWS解决方案:修改TOMCAT的配置文件–apache-tomcat\conf\server.xml
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
....省略....
<!-- 加入下面这句 -->
<Context path="/ptsfile" docBase="C:/com.asmn.pts" debug="0" reloadable="false"/>
</Host>
其中 /ptsfile为网络路径,C:/com.asmn.pts为物理磁盘的路径
修改上传的类:
//文件保存目录路径,用于上传到物理磁盘
String savePath = "C:\\com.asmn.pts\\";
//文件保存目录URL,用于反馈映射的地址
String saveUrl = "/ptsfile/";
以下为补充:
测试的时候,可以把路径写到TOMCAT的webapp(发布目录)下
//文件保存目录路径
String savePath = pageContext.getServletContext().getRealPath("/") + "assets/file/";
//文件保存目录URL
String saveUrl = request.getContextPath() + "/assets/file/";
APP、软件、网站开发可以在下方评论处留言