Servlet 3.0 support for uploads

Source: Internet
Author: User

Servlet 2.5
To upload
The first requirement for the form
->method = "POST"
->enctype= "Mulitpart/form-data" Default value is "application/x-www-urlencoded"
-><input= "file" name= "filename must be given" >
Requirements for Servlets
Because it's a multi-component
So a series of methods such as Request.getparamter () cannot be used
Need to use Request.getinputstream ();
The parsing of flows requires the use of
Commons-fileupload
Using uploads takes three steps
Create a factory
Creating a parser
The parser is used to parse the request object to get list<fileitem>
==============================================================
Support for Servlet 3.0 uploads
Upload steps
Get part
Request.getpart ("Field name")
getContentType gets the MIME type of the file
GetName gets the name of the form item is not a file name
GetHeader (String header) Gets the value of the specified header
GetSize get the size of the upload file
getInputStream get the contents of the uploaded file
Write (String filename) to save the uploaded file to the specified path

Servlet 3.0 support for uploads

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.