1

我试图提取 url 查询参数但没有成功。

例如,AboutWebServices/merchantofferings?lat=5?long=7?cat=9

使用 Tomcat 服务器,我尝试了 Restlets 的各种命令:

@Override
public synchronized Restlet createInboundRoot() {

     Router router = new Router(getContext());

    Extractor extractor = new Extractor(getContext());
    extractor.extractFromQuery("lat", "lat", true); 
    extractor.extractFromQuery("long", "long", false);
    extractor.extractFromQuery("cat", "cat", false);

    ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext(),    
      ChallengeScheme.HTTP_BASIC, 
            "AnywhereAbout");
    guard.setVerifier(new UserVerifer());

    guard.setNext(extractor);
    extractor.setNext(router);

   //     router.attach("/merchantofferings", extractor);
    router.attach("/merchantofferings", MerchantOfferings.class);

    router.attach("/merchantofferings/{id}", MerchantOfferings.class);


    router.attach("/merchantprofile", MerchantProfile.class);

    router.attach("/merchantprofile/{id}", MerchantProfile.class);

    return guard;
   }

路由适用于此方法,但属性为空。

 //@Get("json+?lat?long?cat")
 @Get("json")
 public String representGet() {

Context context = getContext();

String lat = (String) context.getAttributes().get("lat");
String lon = (String) context.getAttributes().get("long");
String cat = (String) context.getAttributes().get("cat");

    return "hello, world: " + this.getRequest().toString();
 }

我也一直在阅读新的 Restlet in Action。很棒的书,但是虽然它说您可以在注释中指定查询参数,但它没有解释如何使用它们,即没有示例。有人知道吗?在任何情况下,@Get("json+?lat?long?cat") 的变体也不起作用。

4

0 回答 0