servlet的getParameterMap

一直以为getParameterMap只是获取url后面的queryString,但是今天看到公司接口代码里,一个服务写着方法是POST的服务方法,结果方法里却写上getParameterMap,就在想,这尼玛不是跟GET没区别吗。

突然觉得这个代码是不是有点low逼。
后来一想,已经跑了这么久,而且一直在用的接口服务应该不会这么low吧。
于是去看了,getParameterMap的JAVA DOC,如下:



Map< String, String[]> javax. servlet. ServletRequest.getParameterMap()

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.

Returns:

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:

String javax. servlet. ServletRequest.getParameter( String name)

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.

Parameters:
name a String specifying the name of the parameter
Returns:
a String representing the single value of the parameter
See Also:
getParameterValues
 发现还能跟 getInputStream  或者getReader相互干扰的。估计是一个getParameter操作读取了,另一个getInputStream  或者getReader的操作就取不到数据了。可以测试一下。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值