Files uploaded to the WebApps directory are automatically deleted when the file is uploaded.

Source: Internet
Author: User

1: Why does the file uploaded to the WebApps directory automatically be deleted when the file is uploaded?

the WebApps folder under the Tomcat directory is the deployment directory, when you redeploy the service, upload File is not in the scope of the deployment file, that is, there are no uploaded files in the development tool, so the uploaded files are not available.

2: Workaround

To set the file upload path to the WebApps directory, you can create a folder in the Tomcat directory, such as: Upload

3: Simple Implementation

HTML file:

<!DOCTYPE HTML><HTML><Head><MetaCharSet= "UTF-8"><title>Insert Title here</title></Head><Body><formAction=".. /jsp/smartupload.jsp "Method= "POST"enctype= "Multipart/form-data"><inputtype= "File"name= "File"/>    <inputtype= "Submit"value= "Submit"/></form></Body></HTML>

JSP file:

<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="UTF-8"%><%@ Page Import="com.jspsmart.upload.*" %><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body><%Smartupload Smart=Newsmartupload ();    Smart.initialize (PageContext);    Smart.upload (); //upload files to the project directory and automatically disappear after redeployment//Smart.save (Request.getsession (). Getservletcontext (). Getrealpath ("/")+"/upload"); //The file is uploaded to the upload folder in the Tomcat directory through an absolute path, and will not disappear after redeployment Smart.save ("D:\\software\\learningsoftware\\tomcat\\apache-tomcat-7.0.72\\upload");%></Body></HTML>

Files uploaded to the WebApps directory are automatically deleted when the file is uploaded.

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.