1 这是一个HTTP/HTTPS请求
2 请求方法是POST(querystring无论是否POST都将被设置到parameter中)
3 请求的类型(Content-Type头)是application/x-www-form-urlencoded
application/x-www-form-urlencoded
这是 默认的编码类型,使用该类型时,会将表单数据中 非字母数字的字符转换成转义字符,如"%HH",然后组合成这种形式 key1=value1&key2=value2
;所以后端在取数据后, 要进行解码。
注意:
-
若表单中有文件,则只留文件名;
multipart/form-data
该类型用于 高效传输文件、非ASCII数据和二进制数据,将表单数据逐项地分成不同的部分,用指定的分割符分割每一部分。每一部分都拥有 Content-Disposition
头部,指定了该表单项的键名和一些其他信息;并且每一部分都有可选的 Content-Type
,不特殊指定就为 text/plain
。下面给出一个采用 multipart/form-data
编码类型的例子:
Content-Type: multipart/form-data; boundary=AaB03x
--AaB03x
Content-Disposition: form-data; name="submit-name"
Larry
--AaB03x
Content-Disposition: form-data; name="files"; filename="file1.txt"
Content-Type: text/plain
... contents of file1.txt ...
--AaB03x--
4 Servlet调用了getParameter系列方法
如果上述条件没有同时满足,则相关的表单数据不会被设置进request的parameter集合中,相关的数据可以通过request.getInputStream()来访问。反之,如果上述条件均满足,相关的表单数据将不能再通过request.getInputStream()来读取。
Servlet Specifiaction 3.0:
3.1.1 When Parameters Are Available
The following are the conditions that mustbe met before post form data will be
populated to the parameter set:
1. The request is an HTTP or HTTPS request.
2. The HTTP method is POST.
3. The content type is application/x-www-form-urlencoded.
4. The servlet has made an initial call of any of the getParameterfamily of methods
on the request object.
If the conditions are not met and the post form data is not included in the parameter
set, the post data must still be available to the servlet via the request object’s input
stream. If the conditions are met, post form data will no longer be available for
reading directly from the request object’s input stream.
response.getOutputStream和getWriter,它们往往也是一对矛盾体