Home > Web Front-end > HTML Tutorial > Introduction to the role and application examples of the Enctype attribute of the Form form tag_HTML/Xhtml_Web page production

Introduction to the role and application examples of the Enctype attribute of the Form form tag_HTML/Xhtml_Web page production

WBOY
Release: 2016-05-16 16:37:42
Original
1663 people have browsed it

Enctype: Specifies the encoding type used by the browser when sending data back to the server. Used for uploading images in forms.

There are three encoding types:

application/x-www-form-urlencoded: Encode all characters before sending (default). This is a standard encoding format.
multipart/form-data: Does not encode characters. This value must be used when using a form that contains a file upload control.
text/plain: Form data is encoded as plain text without any controls or formatting characters.

Example:

Copy code
The code is as follows:

< ;form action="${pageContext.request.contextPath}/imageUpload_saveOrUpdate.action" method="post" enctype="multipart/form-data">









enctype=" in the form multipart/form-data" means setting the MIME encoding of the form. By default, this encoding format is application/x-www-form-urlencoded, which cannot be used for file upload; only when multipart/form-data is used, file data can be transferred completely.

enctype="multipart/form-data" is to upload binary data.

If you want to obtain the value of the corresponding form field through the Request object on the server side, you should set the enctype attribute to the application/x-www-form-urlencoded value (that is, the default value, the setting does not need to be displayed).

Why do you need to set enctype="multipart/form-data" when uploading files:

Because: after setting enctype to the multipart/form-data value, the characters are not encoded, and the data is in binary form Transmitted to the server. At this time, if you use request, you cannot directly obtain the value of the corresponding form. Instead, you should use the stream object to decode the binary data transmitted to the server to read the data.

If you want to upload files, you must set the encotype to multipart/form-data.
Related labels:
source:php.cn
Previous article:Solution to the problem of transferring values ​​between html pages_HTML/Xhtml_Web page production Next article:The solution to defining the minimum height of span has no effect_HTML/Xhtml_Web page production
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template