Tomcat configures the virtual path to detach the uploaded file from the server

Source: Internet
Author: User

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 &quot;%r&quot; %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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.