Javaweb Development solutions for uploading file loss issues such as IDE redeployment or restart projects for Eclipse __javaee

Source: Internet
Author: User
Tags tomcat server

In the development project, sometimes need to use the upload function, such as Avatar upload, and its files will be saved to the server. But I found that in the process of using eclipse as a project, every time I redeploy a project, the original uploaded file is lost.

The reason for this is that eclipse will copy the project we put in the workspace workspace to the server (such as Tomcat's WebApps directory) after each project is modified. Because the previously uploaded files are in the previous deployed project, the newly deployed project will cover the original project directly. The original uploaded files are gone.


Solution One:

Create a separate folder for resource files under the WebApps of the Tomcat server (XXX)

Upload files to this folder in the project.

To request a file, you can use http://localhost:8081/xxx/xxxxx.jpg directly


Solution Two:

Configure an empty project in the form of a virtual path. When it comes to uploading, write the file directly to the project where the virtual path is configured, and the final file is saved to the physical disk of the virtual path.

On If it's a tomcat server, configure it in Tomcat's server.xml. However, in the actual operation of the process, found that Server.xml will also be rewritten. Because there is one in the Eclipse workspace

Called the servers project, which has a file called Server.xml, which overwrites the Tomcat server when deploying the project. So, we can migrate the following configuration to

Under eclipse under the Servers project.

The following screenshot is located:


Configure under Host

 


Request http://www.***.com/objimags/filename. jpg, automatically to the D://objimgs//upload directory to find the relevant documents

Reference: http://bbs.csdn.net/topics/391868478

Related Article

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.