Rob*_*son 1 setcookie playframework
我是新玩框架(1.2.4),我正在努力设置cookie.我已经阅读了1.2.4 api doc,但找不到出错的地方.cookie没有设置,而是应用程序使用这样的cookie值执行GET请求:index?name=user&value=123&duration=1d并且页面变为空白.render()没有被召唤.我在application.conf中缺少设置吗?以下是我的代码.
public static void setCookie(String name, String value, String duration) {
// Setting cookie
System.out.println(">> Setting Cookie :" + name);
response.setCookie(name, Crypto.sign(value), duration);
}
public static Http.Cookie getCookie(String key) {
// retrieving cookie by key
return Http.Response.current().cookies.get(key);
}
Run Code Online (Sandbox Code Playgroud)
这是我调用setCookie的地方
public static void index() {
// some code.
setCookie("user", "123", "1d");
render();
}
Run Code Online (Sandbox Code Playgroud)
这是因为当你调用setCookiePlay认为你正在调用另一个动作时(因为你的setCookie方法是在一个控制器中,并且是public static void.
您可以将方法设为私有,也可以使用@Util注释标记setCookie方法.
| 归档时间: |
|
| 查看次数: |
1566 次 |
| 最近记录: |