java.net.URI仅针对查询字符串进行解析 [英] java.net.URI resolve against only query string

查看:41
本文介绍了java.net.URI仅针对查询字符串进行解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JDK构建URI.java.net.URI .
我想附加到一个绝对URI对象,一个查询(在String中).例如:

I'm trying to build URI's using the JDK java.net.URI.
I want to append to an absolute URI object, a query (in String). In example:

URI base = new URI("http://example.com/something/more/long");
String queryString = "query=http://local:282/rand&action=aaaa";
URI query = new URI(null, null, null, queryString, null);
URI result = base.resolve(query);

理论(或我的想法)是解决方法应该返回:

Theory (or what I think) is that resolve should return:

http://example.com/something/more/long?query=http://local:282/rand&action=aaaa

但是我得到的是:

 http://example.com/something/more/?query=http://local:282/rand&action=aaaa

为什么 #resolve()吃掉"最后一条路了吗?如果新的URI( query )的构建方式为:

Why #resolve() "eats" the last path? If the new URI (query) is built as:

URI query = new URI(null, null, base.getPath(), queryString, null);

效果很好.

推荐答案

我想回应一下自己.Javadoc确实可以正确解释.为 URI#resolve()在3.b节中说:

I'd like to respond myself. Javadoc really explains correctly. As URI#resolve() says, in section 3.b.:

否则,给定URI的路径是相对的,因此新URI的路径通过将给定URI的路径与此URI.这是通过串联除最后一个段以外的所有段来完成的此URI的路径(如果有的话)以及给定URI的路径,然后通过调用normalize方法对结果进行归一化.

Otherwise the given URI's path is relative, and so the new URI's path is computed by resolving the path of the given URI against the path of this URI. This is done by concatenating all but the last segment of this URI's path, if any, with the given URI's path and then normalizing the result as if by invoking the normalize method.

所以....我没有正确阅读.我应该删除此回复吗?还是让它自己回应?

So.... I didn't read correctly. Should I delete this response? Or let it responsed by myself?

这篇关于java.net.URI仅针对查询字符串进行解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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