从Restlet请求获取HTTP GET参数

从Restlet请求获取HTTP GET参数

问题描述:

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

我的请求以/ 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; 
     } 
    } 
} 

我想通了....

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

我也很难弄清楚。 – 2010-06-09 03:37:10

+0

它的2014年,我仍然觉得很难弄清楚:)谢谢你的解决方案! – Srikanta 2014-10-03 10:04:03

+1

2016 !!!谢谢! – Shadoninja 2016-04-13 19:25:23

请不存在该快捷方式的方法:

String paramValue = getQueryValue("userId"); 

希望它可以帮助你。