我有一点时间在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("");
    }
}
Run Code Online (Sandbox Code Playgroud)
我现在遇到的问题是我无法实例化一个类型为"org.restlet.util.Series"的类,我找不到任何可以实例化的子类.这似乎是一个愚蠢的问题.但我不知道该怎么做.另外,我似乎经常使用Restlet来解决这个问题.通常我无法弄清楚如何使用API中的这个工具,当我搜索示例时,我找不到.还有其他方法我应该引用Restlets的文档吗?
这是答案:
(我错过了'this.getResponse()中的'getResponse()'.getCookieSettings().add(cS);)
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("");
    }
}
Run Code Online (Sandbox Code Playgroud)