【发布时间】:2012-09-21 13:32:55
【问题描述】:
我想在 GET 方法中获取整个查询字符串。例如,如果 uri 是
host:port/app?param1=123¶m2=xyz¶m3=4
我想获得“param1=123¶m2=xyz¶m3=4”部分。有可能吗?
谢谢。
【问题讨论】:
标签: rest web-services get resteasy
我想在 GET 方法中获取整个查询字符串。例如,如果 uri 是
host:port/app?param1=123¶m2=xyz¶m3=4
我想获得“param1=123¶m2=xyz¶m3=4”部分。有可能吗?
谢谢。
【问题讨论】:
标签: rest web-services get resteasy
你可以得到HttpServletRequest,在那里你会找到一切。例如,在您的资源中:
public class MyResource {
@Context
private HttpServletRequest request;
@GET
public void get() {
this.request.getQueryString();
}
}
【讨论】:
真的老了……但是:
您应该映射@Context 并获取查询部分,如下所示: .getRequestUri().getQuery()
@POST
@Path("/{path}")
public Response transform(@PathParam String path, @Context UriInfo uriInfo, String inputData) {
...
String query = uriInfo.getRequestUri().getQuery();
System.out.println(query); // null if no query parameter is supplied
...
【讨论】: