2010-05-05 349 views
13

我想弄清楚如何從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; 
     } 
    } 
} 

回答

29

我想通了....

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

6

請不存在該快捷方式的方法:

String paramValue = getQueryValue("userId"); 

希望它可以幫助你。