简体   繁体   中英

Get HTTP GET parameters from Restlet request

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

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

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;
      }
  }
}

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;
      }
  }
}

Please not that there is a shortcut method for that:

String paramValue = getQueryValue("userId");

Hope it helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM