- 浏览: 358171 次
文章分类
最新评论
-
string2020:
select * from tab where user_id ...
(转)JPA JPQL -
hety163:
Java 位运算符 -
hiberatejss:
lz,~这个位运算的作用和反码是一样的吗?
Java 位运算符 -
skcmm:
博主,有个问题想请教下。我在/etc/hosts声明一个域名, ...
nginx泛域名解析 -
kid_ren:
写的好
Java 位运算符
目前playframework使用的Mina在设置Cookie Cache时 只设置了Max-age,未设置Expires,这导致Cookie的存活期在所有的IE浏览器里失效,无法实现remember me!
Max-age与Expires区别见下文:
http://mrcoles.com/blog/cookies-max-age-vs-expires/
HTTP Cookies: What's the difference between Max-age and Expires?
Quick Answer:
-
Expires
sets an expiry date for when a cookie gets deleted -
Max-age
sets the time in seconds for when a cookie will be deleted - Internet Explorer (ie6, ie7, and ie8) does not support “max-age” , while (mostly) all browsers support expires
Max-age vs Expires, let’s dive in a little deeper:
The expires
parameter was part of the original cookies
baked up by Netscape. In HTTP version 1.1, expires
was
deprecated and replaced with the easier-to-use max-age
—instead
of having to specify a date, you can just say how long the cookie can
live. By setting either of these, the cookie will persist until its time
runs out, otherwise—if you set neither—the cookie will last until you
close your browser.
Setting a cookie for “foo=bar” to last 5 minutes, using expires
:
var d = new Date(); d.setTime(d.getTime() + 5*60*1000); // in milliseconds document.cookie = 'foo=bar;path=/;expires='+d.toGMTString()+';';
And the same with max-age
:
document.cookie = 'foo=bar;path=/;max-age='+5*60+';';
Unfortunately, none of the current versions of Internet Explorer
support max-age
, so if you want proper cookie persistence
cross-browser, then stick to expires
.
Let’s open this up to some fake Q&A…
Q. What if I set both expires and max-age in a cookie?
A. Every browser that supports max-age
will ignore the expires
regardless of it’s value, and likewise, Internet Explorer will ignore
the max-age
and just use expires
.
Q. What if I set just max-age in a cookie?
A. Every browser—except Internet Explorer—uses it properly. In Internet
Explorer it will be a session cookie (it will be deleted when you close
your browser).
Q. What if I set just expires in a cookie?
A. Every browser uses and persists it properly, just remember to set it
in GMT time as seen in the example above.
Q. Where did you get these facts from?
A. I wrote a cookie
persistence test page
and tested it out on IE6, IE7, IE8, FF2, FF3,
Safari 4, Google Chrome, and Opera 9.6. Let me know if you try it out
on any other browsers or see anything contradictory.
Q. What’s the moral of this story?
A. If you care about your cookies functioning properly for a huge percentage of web users (65.66%)
, don’t
persist your cookies “the right way” according to spec (max-age
),
persist them the way that works (expires
).
评论
/** * 设置cookie * * @param response * @param name * @param value * @param domain (.paojiao.cn) * @param path(/ 或者 null) * @param maxAge */ public static void setCookie(Http.Response response, String name, String value, String domain, String path, Integer maxAge) { //response.setCookie(name, value, domain, path, maxAge); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.SECOND, maxAge); Date date = calendar.getTime(); String expires = (new SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss z", Locale.US)).format(date); expires = expires.replaceAll("CST", "GMT"); if (StringUtils.isEmpty(path)) { path = ""; } String cookie = name + "=" + value + "; domain=" + domain + "; path=" + path + "; expires=" + expires; System.out.println("cookie:" + cookie); response.setHeader("Set-Cookie", cookie); //response.setHeader("Set-Cookie", "email=arden.emily@gmail.com; domain=.tujiao.com; path=/; expires=Tue, 11-Oct-2011 05:48:06 GMT"); }
我写了个手动设置Cookie的方法,解决IE不能设置cookie的Bug.
* 设置cookie
*
* @param response
* @param name
* @param value
* @param domain (.paojiao.cn)
* @param path(/ 或者 null)
* @param maxAge
*/
public static void setCookie(Http.Response response, String name, String value, String domain, String path, Integer maxAge) {
//response.setCookie(name, value, domain, path, maxAge);
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.SECOND, maxAge);
Date date = calendar.getTime();
String expires = (new SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss z", Locale.US)).format(date);
expires = expires.replaceAll("CST", "GMT");
if (StringUtils.isEmpty(path)) {
path = "";
}
String cookie = name + "=" + value + "; domain=" + domain + "; path=" + path + "; expires=" + expires;
System.out.println("cookie:" + cookie);
response.setHeader("Set-Cookie", cookie);
//response.setHeader("Set-Cookie", "email=arden.emily@gmail.com; domain=.tujiao.com; path=/; expires=Tue, 11-Oct-2011 05:48:06 GMT");
}
我写了个手动设置Cookie的方法,解决IE不能设置cookie的Bug.
发表评论
-
转:如何编写UML用例图
2011-04-08 17:01 1916UML用例图是非常有用 ... -
apache配置最大用户数的比较
2011-01-06 15:59 0Apache性能比较测试 8.15 Apache在配置 ... -
(转)JPA JPQL
2010-05-16 23:04 16730JPQL就是一种查询语言,具有与 SQL 相 类似的特 ... -
JQUERY复选框CHECKBOX全选,取消全选
2010-05-11 14:37 1417$("#checkall").click( ... -
XML String和Document的相互转换
2010-05-07 23:29 0在做一般的XML数据交换过程中,我更乐意传递XML字符串,而不 ... -
get the number of online by Play
2010-04-28 14:10 1087It's not an easy problem to sol ... -
(转)Groovy的5种特殊运算符(可直接用于Play!的模板中)
2010-04-09 12:03 2906Spread Operator(展开运算符) 一个集合使 ... -
playframework的Eclipse插件问题
2010-04-08 17:19 3037在使用playclipse 插件的时候,Eclipse的版本 ... -
nginx泛域名解析
2010-04-05 22:11 5187在dns做一条泛指到主机上,利用nginx做二级域名的rewi ... -
使用play!完成iframe无刷新上传文件
2010-03-25 16:32 2226页面代码片段: <form id="uplo ... -
IE与Firefox兼顾加入收藏
2010-03-23 13:39 1222<script type="text/java ... -
submit和button提交表单的区别
2010-03-23 13:31 19316(1) 下边的写法使得表单frm能够自动提交 :下边的这个f ... -
JPA注解说明
2010-03-19 11:20 3024使用注解元数据 基本注解: 例子: @Entity ... -
playframework的Eclipse插件playclipse
2010-03-16 23:00 1427http://github.com/erwan/playcli ... -
playframework的JPA中对id的处理
2010-03-10 16:35 1912package play.db.jpa; import ja ... -
常用 JPA annotation 参考
2010-03-10 16:18 1781Table Table用来定义entity主表的name,ca ... -
(转)Java虚拟机(JVM)参数配置说明
2010-03-05 10:51 1063Java虚拟机(JVM)参数配置说明 在Java、J2EE ... -
获取msn联系人
2009-07-16 14:22 0网上也有不少例子,但是有些朋友遇到所谓911错误导致无法登录, ... -
将wml转换成html的方法
2009-07-10 17:21 0Opera是直接支持wml的,但是有不少bug。 Firef ... -
unicode详解
2009-05-07 17:31 1610引自:http://baike.baidu.com/view/ ...
相关推荐
The Learning Play! Framework 2 has been created for web developers that are building web applications. The core idea is to focus on the ...
play framework api,play! framework api,play api
学习Play!框架的好资料,英文版的,分享一下
对play!的CRUD 进行改造,改代码还会持续重构,并不完善。 1.将create,show,delete,list都改成@Util方法,可以类似 public static void show(String id){ MyCRUD.show(id); } 的方式调用。更通用。 2.增加@...
Unit 1 Lesson 3 Let’s Play!练习题及答案.doc
修复各种BUG缺陷,优化主机运行速度,减少主机发热,优化蓝牙链接,修复倒车影像慢的问题,增加Carplay和Carlife的稳定性,优化GPS信号 mib车机_Preh_866C/877C/682G/866BG_固件0478 适合车机:3Q0035866.C/3Q...
NULL 博文链接:https://nickdine.iteye.com/blog/674389
一个优于RoR的快速开发框架playframework,完全面向对象,基于jvm的REST框架,文档非常少,上手很容易,从名字上可以看出play就是玩,可以当作游戏一样轻松的玩的框架,这是它的API文档,网页格式.
NULL 博文链接:https://modun.iteye.com/blog/1595857
这是本人学习play时自己整理的笔记,是对官方文档的简单汉化,对应的是1.x版本
Play!是一个full-stack(全栈的)Java Web应用框架,包括一个简单的无状态MVC模型,具有Hibernate的对象持续,一个基于Groovy的模板引擎,以及建立一个现代Web应用所需的所有东西。 Play!的关键特性: 1、一个...
japid源码,轻松学习japid,从这里开始,你的人生已经不同
1 能够录像采用DirectX或OpenGL技术的3D游戏,如星际争霸2、魔兽世界、极品飞车、跑跑卡丁车、实况足球在内的主流游戏,还能录制星际争霸、祖玛、QQ游戏等各种2D游戏和经典老游戏! 2 使用Windows Media Player即可...
Play Framework最新教程(12年),play框架教程
您可以在此处检查:PlayBox v2:新的ES主题“ 2Play!系统” v1更新了 PlayBox v2:新的ES主题“ 2Play!Walls” v1更新了 PlayBox v2:新的ES主题“ 2Play!EpicMavro墙v2” PlayBox v2:新的ES主题“ 2Play!...
播放网站 彼得的网站使用Play!
playframework,play! 书中范例代码下载地址: https://github.com/spinscale/play-cookbook 292 pages Publisher: Packt Publishing (September 4, 2011) Language: English ISBN-10: 1849515522 ISBN-13: 978-...
Japid-Play 是一个拥有与Java硬编码相同性能和...模板语法与Play! Web开发框架模板语言相似。 Japid是一个通用的模板引擎,适用于任何Java应用程序来渲染任意Java对象。此外它还提供一个专门用于Play! 框架的适配器。