Use commons-fileupload to upload files and commonsfileupload

Source: Internet
Author: User

Use commons-fileupload to upload files and commonsfileupload

I. Analysis of File Upload principles

1. Prerequisites for File Upload

A. The form method must be post.

B. The form's enctype attribute must be of the multipart/form-data type.

Default Value of enctype: application/x-www-form-urlencoded

Purpose: Inform the server of the MIME type of the Request body

Application/x-www-form-urlencoded: username = abc & password = 123

ServletRequest. getParameter (String name); this method is used to read this type of data.

      

Multipart/form-data:

      

2. Use the commons-fileupload component to upload files

A. Copy jar package: commons-fileupload.jar commons-io.jar

B. Implementation Principle

      

3. garbled Problem

A. garbled characters in common fields

FileItem. getString (String charset); the encoding must be consistent with that of the client.

B. garbled Chinese file names uploaded

Request. setCharacterEncoding ("UTF-8"); encoding must be consistent with the client

4. Specific implementation

          

The front-end upload. jsp code is as follows <% @ page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %> <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"> 

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.