Java web accesses static resources on the server as a virtual path for tomcat

  1. When developing WEB projects, sometimes users need to upload some image files and the like. The traditional method is to upload them to the deployment directory, which will cause a problem. When we want to redeploy the project, we will release a new war package. It is required to delete the previous project folder. At this time, to retain the resource files uploaded by the user, the resource files must be copied, and then copied into the deployment directory after the project is successfully deployed. This is very troublesome. In order to avoid this problem, it is necessary to Make the resource folder a virtual directory 
         2. Note that this configuration path is in: server.xml in the Servers folder
  1. <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">  
  2.    
  3.      <Context docBase="weibo" path="/weibo" reloadable="true" source="org.eclipse.jst.jee.server:weibo"/>  
  4.           <!-- Set the image virtual path [the path is /static_img when accessing] -->  
  5.      <Context path="/static_img" docBase="F:\temp" reloadable="false" />  
  6. </Host>  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324892035&siteId=291194637