Introduction: The project avatar Upload, upload images to the server. If you use the directory under Tomcat as the path to upload pictures, the picture will disappear every time you restart the server
Problem: Using the D:\upload path of the server physical disk to store the file, the access request path is not mapped to the desired request.
WORKAROUND: You can use Tomcat's configuration file to map a request to a physical path to complete the echo of the picture.
What to do: use the tomcat virtual path
1. Modify the Tomcat configuration file
window环境
首先找到tomcat目录下conf目录下的server.xml文件
在server.xml文件中找到<Host></Host>
<context path=
"/demo/file"
docbase=
" D:\demo\File\file "
></CONTEXT>
例如:
<valve classname= "Org.apache.catalina.valves.AccessLogValve" directory= "Logs"
prefix= "Localhost_access_log" suffix= ". txt"
pattern= "%h%l%u%t "%r" %s%b "/>
<!--The following two articles are primarily Tomcat forwarding picture requests to the corresponding computer physical disk location--
<context path= "/dajean/uploadpng/" docbase= "D:\setup\dajean\uploadpng\" ></Context>
</Host>
tomcat in the request is generally http:
//localhost:8080/demo/file/abc.jpg
after the reboot is configured, the request will automatically jump to the physical path D:\demo\File\file to find. will access the D:\demo\File\file\abc.jpg of this machine
effectively resolves the separation of the storage path from the Tomcat path.
Tomcat configures the virtual path to detach the uploaded file from the server