Seems to support a minimum of 3.0 javaweb projects;
Front page code:
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "GBK">5 <title>Test upload</title>6 </Head>7 <Body>8 <formAction= "/fileup/uptest"enctype= "Multipart/form-data"9 Method= "POST">Ten One <inputtype= "File"name= "File01"> <inputtype= "Submit" A value= "Up"> - - </form> the </Body> - </HTML>
Background:
1 Importjava.io.IOException;2 3 Importjavax.servlet.ServletException;4 ImportJavax.servlet.annotation.MultipartConfig;5 ImportJavax.servlet.http.HttpServlet;6 Importjavax.servlet.http.HttpServletRequest;7 ImportJavax.servlet.http.HttpServletResponse;8 ImportJavax.servlet.http.Part;9 Ten@MultipartConfig//must be set One Public classUptestextendsHttpServlet { A - Private Static Final LongSerialversionuid = 1L; - the protected voidDoPost (httpservletrequest request, httpservletresponse response) - throwsservletexception, IOException { -Part part = Request.getpart ("file01");//the Neme property value of the file in the HTML form. -String Header = Part.getheader ("Content-disposition"); + intLastIndexOf = Header.lastindexof ("=");//Get file name -Header =header.substring (LastIndexOf, Header.length ()); +Header = header.substring (2, Header.length ()-1); APart.write ("f:/" + header);//Save File at - } - -}
The simplest implementation uploads a file without using a frame. Upload file size can be set in the parameters of the annotations;
Simple implementation of Javaweb not using frames to upload files