我是靠谱客的博主 开心小馒头,最近开发中收集的这篇文章主要介绍java获取uriinfo,为什么UriInfo.getQueryParameters()解码'+'?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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 params = info.getQueryParameters();

String searchQuery2 = params.get("q").get(0);

解决方案

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

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.

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

最后

以上就是开心小馒头为你收集整理的java获取uriinfo,为什么UriInfo.getQueryParameters()解码'+'?的全部内容,希望文章能够帮你解决java获取uriinfo,为什么UriInfo.getQueryParameters()解码'+'?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(65)

评论列表共有 0 条评论

立即
投稿
返回
顶部