Jsp-solves the problem of Automatic File Deletion when Tomcat is restarted after File Upload. jsp-tomcat

Source: Internet
Author: User

Jsp-solves the problem of Automatic File Deletion when Tomcat is restarted after File Upload. jsp-tomcat

Hey, this is the problem I encountered ......

I wrote a method for uploading images. When uploading images, an image is automatically created if this directory is not found. Then start uploading the image. After the upload succeeds, you can find the folder and corresponding file on the server. However, after the project is restarted or the cache is cleared, the images and folders are automatically deleted and disappear.

Let's talk about the solution first, and analyze it later:

1. Clear the/tomcat/webapps/directory and delete all contents in the folder,

2. Modify the/tomcat/conf/web. xml file:

<servlet>    <servlet-name>default</servlet-name>    <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>    <init-param>      <param-name>debug</param-name>      <param-value>0</param-value>    </init-param>    <init-param>      <param-name>listings</param-name>      <param-value>true</param-value>    </init-param>    <load-on-startup>1</load-on-startup>  </servlet

3. Modify the/tomcat/conf/server. xml file:

<Host name = "localhost" appBase = "webapps" unpackWARs = "true" autoDeploy = "true" xmlValidation = "false" xmlNamespaceAware = "false"> <! -- SingleSignOn valve, share authentication between web applications Documentation at:/docs/config/valve.html --> <! -- <Valve className = "org. apache. catalina. authenticator. SingleSignOn"/> --> <! -- Access log processes all example. Documentation at:/docs/config/valve.html --> <! -- <Valve className = "org. apache. catalina. valves. accessLogValve "directory =" logs "prefix =" localhost_access_log. "suffix = ". txt "pattern =" common "resolveHosts =" false "/> --> <! ----> <Context path = "/ser" docBase = "D: \ project \ myProject \ editor \ WebRoot"> </Context> <! -- <Context path = "/mvc" docBase = "D: \ project \ myProject \ your project name \ WebRoot"> </Context> --> </Host>

Analysis:

When re-redeploy, tomcat will synchronize your local files, because there is no corresponding local folder, resulting in file loss. This is only a problem encountered during the development process. In actual application, tomcat will only start up. bat/sh shutdown. bat/sh. In this way, we configure a virtual path for the project, so that tomcat finds the project directly at startup, and the uploaded images will not only be in the/tomcat/webapps/directory, directly in your project, no matter how you restart the project or clear the cache, the uploaded files still exist!

Summary

The above is all the content about jsp-Solving the Problem of Automatic File Deletion when the file is uploaded and then restarted Tomcat. I hope it will be helpful to you. If you are interested, you can refer to other topics on this site. Thank you very much for your support for the help house!

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.