是否已弃用javax.servlet.http.HttpUtils.parseQueryString? [英] Alternative to deprecated javax.servlet.http.HttpUtils.parseQueryString?

查看:836
本文介绍了是否已弃用javax.servlet.http.HttpUtils.parseQueryString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望解析一个URL以获取Java中的查询字符串参数的集合。为了清楚起见,我需要解析给定的URL(或URL对象的字符串值),而不是来自servlet请求的URL。

I am looking to parse a URL to obtain a collection of the querystring parameters in Java. To be clear, I need to parse a given URL(or string value of a URL object), not the URL from a servlet request.

看起来好像 javax.servlet.http.HttpUtils.parseQueryString 方法是明显的选择,但是它已被弃用。

It looks as if the javax.servlet.http.HttpUtils.parseQueryString method would be the obvious choice, but it has been deprecated.

是否有一种我缺少的替代方法,或者它是否已被弃用而没有等效的替换/增强功能?

Is there an alternative method that I am missing, or has it just been deprecated without an equivalent replacement/enhanced function?

推荐答案

嗯,正如你所提到的,URL并非来自servlet请求,正确的答案是,取决于 strong>。

Well, as you mention that the URL does not come from a servlet request, the right answer is, as usual, it depends.

网址查询部分的问题在于没有关于如何处理参数重复的明确说明。

The problem with query part of an url is that there is no clear specification about how to handle parameters duplication.

例如,考虑一个这样的网址:

For example, consider an url like this one:

http://www.example.com?param1=value1&param2=value2&param1=value3

您对param1的值有什么期望?第一个值,最后一个,一个数组?问题在于,根据规范,所有这些答案都是有效的,服务器供应商可以自由支持其中一个或另一个。有些人使用param1 []符号表示必须将其视为一个数组,但同样,这不是一个统一的解决方案。

What do you expect as a value for param1? the first value, the last one, an array? The issue is that, according to the specs, all these answers are valid and server vendor are free to support one of these or another. Some use the param1[] notation to indicate that it has to be treated as an array, but again, this is not a unified solution.

所以最佳的解决方案是知道您的目标如何处理参数,并使用自制的实用程序类模仿行为。

So the "best" solution is to know how your destination handle parameters, and mimic the behaviour with a self-made utility class.

这篇关于是否已弃用javax.servlet.http.HttpUtils.parseQueryString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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