我試圖通過如何獲得會話中的密鑰值?
Http.Context.current().session().put("my-fancy-key", "some-interesting-value");
我到play.mvc.Http.Request唯一通道從cookie請求頭我以前存儲在播放錄音的值直接從挖我能夠去play.mvc.Http.Cookie ......但是從那裏我絆倒了。
此代碼段不起作用...提示?
注意:我完全開放使用不在Play框架中的對象。我看到Netty具有cookie r/w函數,並且正在研究這些......可能是直接在javax中的東西?
String playSessionCookieName = Configuration.root().getString("session.cookieName", "PLAY_SESSION");
Http.Cookie playSessionCookie = r.cookie(playSessionCookieName);
if (playSessionCookie != null) {
// FIXME: What to do here to get my value?
Logger.debug("Found the cookie! Serialized value: " + playSessionCookie.value());
try {
ObjectInputStream objIn = new ObjectInputStream(new ByteArrayInputStream(playSessionCookie.value().getBytes()));
Http.Session session = (Http.Session) objIn.readObject();
// Here's the goal
Logger.debug("Found my value: " + session.get("my-fancy-key"));
} catch (Exception e) {
Logger.warn("Couldn't deserialize the value.", e);
}
}
感謝您的幫助。我試圖避免做字符串解析(希望將某些東西烘焙到API中),但它運行良好。 – joewyrembelski
關於「......不知道爲什麼你不使用簡單的會話(關鍵)...」,答案是:「因爲你沒有清楚地閱讀問題或者其他任何評論題。」 – joewyrembelski