環境
- Eclipse ジュノ サービス リリース 1
- GWT 2.5
- GWT 開発者プラグインを使用した Google Chrome
- 「アプリケーションの実行」を Google Web アプリケーションとして使用して、Jetty サーバーで GWT を実行する
次のコードを使用して、gwt を使用して 2 つの Cookie を設定しようとしています。
if(result.getStatus() == ServerResponse.SUCCESS) {
System.out.println("I will now set cookies: " + result.getMessage() + " and " + Integer.toString(result.getValue().getId()));
Cookies.setCookie("opsession", result.getMessage(), new Date(System.currentTimeMillis() + ClientUser.SESSION_EXPIRY_TIME_IN_MINUTES));
Cookies.setCookie("opuser", Integer.toString(result.getValue().getId()), new Date(System.currentTimeMillis() + ClientUser.SESSION_EXPIRY_TIME_IN_MINUTES));
System.out.println("Cookie set: session: " + Cookies.getCookie("opsession"));
main.checkLoginAndRedirect();
System.out.println("Redirected.");
} else if(result.getStatus() == ServerResponse.FAILURE){
new MessageBox(result.getShortTitle(), result.getMessage()).show();
}
うまくいかないようです。println はデバッグ用にあり、出力は次のとおりです。
I will now set cookies: 1er1qmaly9ker and 1
Cookie set: session: null
nullnull
Redirected.
ClientUser.SESSION_EXPIRY_TIME_IN_MINUTES
(以前は int でした) 20 を返す long です。
アップデート
使用する
if(Cookies.getCookie("opsession") == null) {
System.out.println("opsession: cookie not found at all.");
}
Cookie がまったく配置されておらず、「null」文字列値がないことを確認しました。
私も
ClientUser.SESSION_EXPIRY_TIME_IN_MINUTES
ロングに変えました。
アップデート
Fiddler は、Cookie データが送信されたことを確認します。
Response sent 30 bytes of Cookie data: Set-Cookie: JSESSIONID=4kr11hs48gvq;Path=/
ただし、より長いバージョンの setCookie を使用する場合のみ:
Cookies.setCookie("opuser", Integer.toString(result.getValue().getId()), new Date(System.currentTimeMillis() + ClientUser.SESSION_EXPIRY_TIME_IN_MINUTES), null, "/", false);
バリアントを使用するとString, String, long
、フィドラーは Cookie データを認識しません。