吐槽-httpservletrequest不支持getparameter真麻烦!

转自:http://www.hetaoblog.com/%E5%90%90%E6%A7%BD-httpservletrequest%E4%B8%BA%E4%BB%80%E4%B9%88%E5%AF%B9%E8%AF%B7%E6%B1%82body%E9%87%8C%E9%9D%A2%E7%9A%84%E4%B8%9C%E8%A5%BF%E4%B8%8D%E6%94%AF%E6%8C%81getparameter%E5%91%A2/
写servlet程序的时候,通过servletrequest.getparameter来获取内容呢?下面是这个api的说明,
就是说如果form的请求设定了enctype=”multipart/form-data”以后,请求的参数内容放到了请求body里面了,所以要读出来需要自己调用getinputstream或者getreader()的方式来调用,或者是借助于commons-fileupload来调用,这不折腾么?

提供一个bytes[] getParameter(String name)不就好了么?真麻烦!

String 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, use getParameterValues(java.lang.String).

If you use this method with a multivalued parameter, the value returned is equal to the first value in the array returned by getParameterValues.

If the parameter data was sent in the request body, such as occurs with an HTTP POST request, then reading the body directly via getInputStream() or getReader() can interfere with the execution of this method.
发布了10 篇原创文章 · 获赞 0 · 访问量 1229
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览