【问题标题】:RESTEasy - Getting entire query stringRESTEasy - 获取整个查询字符串
【发布时间】:2012-09-21 13:32:55
【问题描述】:

我想在 GET 方法中获取整个查询字符串。例如,如果 uri 是

host:port/app?param1=123&param2=xyz&param3=4

我想获得“param1=123&param2=xyz&param3=4”部分。有可能吗?

谢谢。

【问题讨论】:

    标签: rest web-services get resteasy


    【解决方案1】:

    你可以得到HttpServletRequest,在那里你会找到一切。例如,在您的资源中:

    public class MyResource {
      @Context
      private HttpServletRequest request;
      @GET
      public void get() {
        this.request.getQueryString();
      }
    }
    

    【讨论】:

      【解决方案2】:

      真的老了……但是:

      您应该映射@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
      ...
      

      【讨论】:

        猜你喜欢
        • 2014-10-18
        • 1970-01-01
        • 1970-01-01
        • 2010-11-01
        • 1970-01-01
        • 2016-12-08
        • 1970-01-01
        • 2011-02-21
        • 1970-01-01
        相关资源
        最近更新 更多