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.