Use JSP to upload files

Source: Internet
Author: User
// Process the upload page (for example, result. jsp)

 1 <% @ Page Language = "  Java  " Pageencoding = "  GBK  " Contenttype = "  Text/html; charset = GBK  " %> 2 <% @ Page import = "  Java. util .* " %> 3 <% @ Page import = "  Java. Io .*  " %> 4 <% @ Page import = "  Com. oreilly. servlet. multipart .*  " %> 5 <% @ Page import = "  Com. oreilly. servlet. multipartrequest  " %> 6 <% 7     //  Savetext: Destination path for storing uploaded files  8 String savetext = "  C :\\ 1010  "  ;  9     //  Size of each uploaded file (3 indicates the maximum number of files uploaded each time; 20 indicates the size of each file; 1024*1024 indicates the hexadecimal format)  10     Int Maxsize = 3 * 20 *1024 * 1024  ;  11     //  File Upload: the first parameter is the request method; the second parameter is the storage Destination path; the third parameter is the size of the uploaded file; and the fourth parameter is simplified Chinese.  12 Multipartrequest multi = New Multipartrequest (request, savetext, maxsize, "  Gb2312  "  );  13     //  Print through the enumeration of the Set 14 Enumeration files = multi. getparameternames (); //  Obtain all uploaded files from multi  15     While  (Files. hasmoreelements ())  16   {  17 String files_name = (string) files. nextelement (); //  Obtain all uploaded files files_name cyclically from the enumerated variable files  18 File F = multi. GetFile (files_name ); // Obtain each uploaded file F from all uploaded file files_name.  19       If (F! = Null  )  20   {  21         //  Obtain the file_name name of each uploaded file.  22 String file_name = Multi. getfilesystemname (files_name );  23 String last_name = savetext + "  \\ " + File_name;  24         Out . Print ( "  The uploaded files are:  " + Last_name );  25         Out . Print ( "  <HR>  "  );  26   } 27   }  28 %>

Use JSP to upload files;

 1   <!  Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd"  >  2   <  Html  >  3   <  Head  > 4   <  Meta  HTTP-equiv  = "Content-Type"  Content  = "Text/html; charsets = UTF-8"  >  5   <  Title  > Upload </  Title  >  6  </  Head  >  7   <  Body  >  8   <  Form  Name  = "Uploadform"  Action  = "Upload"  Method  = "Post"  Enctype = "Multipart/form-Data"  >  9       <  Table  >  10           <  Tr  >  11               <  TD  > <  Div  Align  = "Right" > Upload file: </  Div  > </  TD  >  12               <  TD  > <  Input  Type  = "File"  Name  = "Uploadfile"  Size  = "30" > </  TD  >  13           </  Tr  >  14           <  Tr  >  15               <  TD  > <  Input  Type  = "Submit" Name  = "Submit"  Value  = "Upload"  > </  TD  >  16           </  Tr  >  17   18       </  Table  >  19  </  Form  >  20   </  Body  >  21   </  Html  > 

 

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.