Introduction to problems encountered: upload avatars in the project, upload pictures to the server. If you use the directory under tomcat as the path to upload pictures, the pictures will disappear every time you restart the server
Encountered a problem: the D:\upload path of the server's physical disk is used to store files, and the access request path will not be mapped to the desired request.
Solution: You can use the tomcat configuration file to map a request to the physical path to complete the image echo.
Specific operation: Use the Tomcat virtual path
1. Modify the configuration file of tomcat
window环境
首先找到tomcat目录下conf目录下的server.xml文件
在server.xml文件中找到<Host></Host>
然后在其中加上这
<Context path=
"/demo/file"
docBase=
"D:\demo\File\file"
></Context>
例如:
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<!-- 下面两条主要是tomcat转发图片请求到相应的电脑物理磁盘位置 -->
<Context path="/dajean/uploadpng/" docBase="D:\setup\dajean\uploadpng\"></Context>
</Host>
tomcat在的请求一般为http:
//localhost:8080/demo/file/abc.jpg
</div>
</div>
Introduction to problems encountered: upload avatars in the project, upload pictures to the server. If you use the directory under tomcat as the path to upload pictures, the pictures will disappear every time you restart the server
Encountered a problem: the D:\upload path of the server's physical disk is used to store files, and the access request path will not be mapped to the desired request.
Solution: You can use the tomcat configuration file to map a request to the physical path to complete the image echo.
Specific operation: Use the Tomcat virtual path
1. Modify the configuration file of tomcat
window环境
首先找到tomcat目录下conf目录下的server.xml文件
在server.xml文件中找到<Host></Host>
然后在其中加上这
<Context path=
"/demo/file"
docBase=
"D:\demo\File\file"
></Context>
例如:
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<!-- 下面两条主要是tomcat转发图片请求到相应的电脑物理磁盘位置 -->
<Context path="/dajean/uploadpng/" docBase="D:\setup\dajean\uploadpng\"></Context>
</Host>
tomcat在的请求一般为http:
//localhost:8080/demo/file/abc.jpg
</div>
</div>