为什么UriInfo.getQueryParameters()解码'+'? [英] Why doesn't UriInfo.getQueryParameters() decode '+'?

查看:662
本文介绍了为什么UriInfo.getQueryParameters()解码'+'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以解决这个问题,但是如果使用带注释的查询参数,与将参数拉出参数映射(应该根据javadoc解码)相比,行为是不同的,这似乎很奇怪。这是一个错误,还是一个怪癖?

I know I can work around this, but it seems very strange that the behaviour is different if you use an annotated query parameter, compared with pulling the parameter out of the parameter map (which should be decoded according to the javadoc). Is this a bug, or just a quirk?

@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public Response getAssets(@Context UriInfo info, @QueryParam("q") String searchQuery) {

    // The request URI is http://myhost.com/appRoot?q=foo+bar%20baz
    // At this point seachQuery="foo bar baz"
    // The + has been decoded (along with any % encoded characters)

    // Here searchQuery2="foo+bar baz", the '+' has not been decoded
    // but the %20 has been
    MultivaluedMap<String, String> params = info.getQueryParameters();
    String searchQuery2 = params.get("q").get(0);


推荐答案

根据Javadocs的 UrlInfo.getQueryParameters 仅参数名称和值中的转义八位字节序列被解码。

According to the Javadocs for UrlInfo.getQueryParameters only "sequences of escaped octets in parameter names and values are decoded".

另一方面, QueryParam Javadocs声称值 URL已解码,除非使用禁用此功能编码注释。

On the other hand, QueryParam Javadocs states that "Values are URL decoded unless this is disabled using the Encoded annotation".

因此,回答您的问题,它看起来像一个规范决定。

So, answering your question, it looks like a specification decision.

无论如何,也许你应该提出 JAX-RS邮件列表

Anyway, maybe you should bring up that discussion on JAX-RS mailing lists.

这篇关于为什么UriInfo.getQueryParameters()解码'+'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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