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

本文详细解析在Servlet程序中,当使用multipart/form-data作为请求编码时,如何通过getInputstream或getReader方法从请求body中读取参数,并讨论了使用getBytes[]getParameter方法的局限性及替代方案,如借助commons-fileupload库。
部署运行你感兴趣的模型镜像
转自: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.

您可能感兴趣的与本文相关的镜像

HunyuanVideo-Foley

HunyuanVideo-Foley

语音合成

HunyuanVideo-Foley是由腾讯混元2025年8月28日宣布开源端到端视频音效生成模型,用户只需输入视频和文字,就能为视频匹配电影级音效

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值