/**
* 设置search记录到cookie中,操作步骤:
* 检查加入的记录是否已经存在cookie中,如果存在,则更新列表次序;如果不存在,则插入到最前面
*
* @param context
* @param value
*/
private void setSearchHistroy(Map<String, Object> context, String value) {
//分析已有的cookie
String separatorsB = "\\.\\.\\.\\.\\.\\.";
String newCookiev = value;
Cookie[] cookies = request.getCookies();
for (Cookie c : cookies) {
if (c.getName().equals("HISTORY")) {
String cookiev = c.getValue();
String[] values = cookiev.split(separatorsB);
int count = 1;
for (String v : values) {
if (count <= 10) {
if (!value.equals(v)) {
newCookiev = newCookiev + separatorsB + v;
}
}
count++;
}
break;
}
}
Cookie _cookie = new Cookie("HISTORY", newCookiev);
_cookie.setMaxAge(60 * 60 * 24 * 7); // 设置Cookie的存活时间为30分钟
_cookie.setPath("/");
response.addCookie(_cookie); // 写入客户端硬盘
}
Providers.java 文件源码
java
阅读 38
收藏 0
点赞 0
评论 0
项目:github-test
作者:
评论列表
文章目录