HttpServletRequest - 获取查询字符串参数,无表单数据 [英] HttpServletRequest - Get query string parameters, no form data

查看:21
本文介绍了HttpServletRequest - 获取查询字符串参数,无表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HttpServletRequest中,getParameterMap返回所有查询字符串参数和发布数据参数的 Map.

In HttpServletRequest, getParameterMap returns a Map of all query string parameters and post data parameters.

有没有办法获得只有查询字符串参数的映射?我试图避免使用 getQueryString 并解析出值.

Is there a way to get a Map of ONLY query string parameters? I'm trying to avoid using getQueryString and parsing out the values.

推荐答案

与 cularis 所说的相反,参数映射中可以同时存在两者.

Contrary to what cularis said there can be both in the parameter map.

我看到的最好方法是代理 parameterMap 并为每个参数检索检查 queryString 是否包含&?<parameterName>=".

The best way I see is to proxy the parameterMap and for each parameter retrieval check if queryString contains "&?<parameterName>=".

请注意,正如 Qerub 指出的那样,在进行此检查之前,需要对 parameterName 进行 URL 编码.

Note that parameterName needs to be URL encoded before this check can be made, as Qerub pointed out.

这样可以省去解析的时间,并且仍然只为您提供 URL 参数.

That saves you the parsing and still gives you only URL parameters.

这篇关于HttpServletRequest - 获取查询字符串参数,无表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆