2

我有一段时间在restlet中设置一个cookie,这是我到目前为止所拥有的::

public class CookieTestResource extends ServerResource {

    @Post
    public Representation post(Representation representation){
        CookieSetting cS = new CookieSetting(
                1, 
                "cookieName", 
                "cookieValue"
                );
        Series<CookieSetting> cookies = new Series<CookieSetting>(); //<--PROBLEM
        cookies.add(cS);
        this.setCookieSettings(cookies);
        // SEND RESPONSE
        setStatus(Status.SUCCESS_OK);
        return new StringRepresentation("");
    }
}

我现在遇到的问题是我无法实例化“org.restlet.util.Series”类型的类,也找不到任何可以实例化的子类。这似乎是一个愚蠢的问题。但我不知道该怎么做。此外,我似乎经常用 Restlets 遇到这种问题。通常我无法从 API 中弄清楚如何使用这个工具,当我搜索示例时,我找不到。我应该以其他方式引用有关 Restlets 的文档吗?

4

1 回答 1

7

这是答案:

(我在 'this.getResponse().getCookieSettings().add(cS) 中遗漏了 'getResponse()';)

public class CookieTestResource extends ServerResource {

    @Post
    public Representation post(Representation representation){

        CookieSetting cS = new CookieSetting(0, "cookieName", "cookieValue");
        this.getResponse().getCookieSettings().add(cS);

        // SEND RESPONSE
        setStatus(Status.SUCCESS_OK);
        return new StringRepresentation("");
    }
}
于 2010-10-20T17:38:32.247 回答