java 从 Restlet 请求中获取 HTTP GET 参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2773626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 22:45:32  来源:igfitidea点击:

Get HTTP GET parameters from Restlet request

javarestrestlet

提问by Holograham

I am trying to figure out how to get the parameters from a Restlet request object.

我想弄清楚如何从 Restlet 请求对象中获取参数。

my request comes in as /customer?userId=1 and I want to grab the parameter to pass to my DAO for the query.

我的请求以 /customer?userId=1 的形式出现,我想获取参数以传递给我的 DAO 以进行查询。

public class CustomerResource extends ServerResource
{
  @Get("xml")
  public Representation toXml() throws ResourceException, Exception
  {
      try
      {
          //get param from request
         //call DAO with parameter
      }
      catch(Exception e)
      {
          throw e;
      }
  }
}

回答by Holograham

I figured it out....

我想到了....

public class CustomerResource extends ServerResource
{
  @Get("xml")
  public Representation toXml() throws ResourceException, Exception
  {
      try
      {
          //get param from request
          getQuery().getValues("userId")
         //call DAO with parameter
      }
      catch(Exception e)
      {
          throw e;
      }
  }
}

回答by Thierry Templier

Please not that there is a shortcut method for that:

请注意,有一个快捷方法:

String paramValue = getQueryValue("userId");

Hope it helps you.

希望对你有帮助。