赞
踩
一直以为getParameterMap只是获取url后面的queryString,但是今天看到公司接口代码里,一个服务写着方法是POST的服务方法,结果方法里却写上getParameterMap,就在想,这尼玛不是跟GET没区别吗。
突然觉得这个代码是不是有点low逼。
后来一想,已经跑了这么久,而且一直在用的接口服务应该不会这么low吧。
于是去看了,getParameterMap的JAVA DOC,如下:
Returns a java.util.Map of the parameters of this request.
Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string orposted form data.
an immutable java.util.Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array.
果然parameters还可以包含在posted form data里的。
再看了request.getParameter的JAVA DOC:
Returns the value of a request parameter as a String
, or null
if the parameter does not exist. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.
You should only use this method when you are sure the parameter has only one value. If the parameter might have more than one value, usegetParameterValues
.
If you use this method with a multivalued parameter, the value returned is equal to the first value in the array returned bygetParameterValues
.
If the parameter data was sent in the request body, such as occurs with an HTTP POST request, then reading the body directly viagetInputStream
or getReader
can interfere with the execution of this method.
String
specifying the name of the parameter
String
representing the single value of the parameter
getInputStream
或者getReader相互干扰的。估计是一个getParameter操作读取了,另一个getInputStream
或者getReader的操作就取不到数据了。可以测试一下。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。