【发布时间】:2015-07-01 16:20:24
【问题描述】:
我知道我可以解决这个问题,但是与将参数拉出参数映射(应根据 javadoc 解码)相比,如果使用带注释的查询参数,行为会有所不同,这似乎很奇怪。这是一个错误,还是只是一个怪癖?
@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);
【问题讨论】:
-
据我所知查询字符串是
application/x-www-form-urlencoded。如果您必须发送参数,那么您必须像appRoot?q=foo%bar一样发送它 -
我的理解(这个question 意味着您可以使用 %20 或 + 对查询字符串中的空格进行编码。所以在我的应用程序中,我需要能够处理两者都有。
-
如果必须在查询参数中传递一个空格,有没有办法使用 UriInfo 对其进行解码?
标签: java jakarta-ee jax-rs apache-wink