如何在java文件中实现写入cookie和用户登陆验证操
1个回答
展开全部
这个不用在后台写的,只在js里面用cookie操作就可以。
//添加cookie
function setCookie(name,value,expires){
var cookieName = encodeURIComponent(name)+"="+encodeURIComponent(value);
if(expires && expires instanceof Date){
cookieName+=";expires="+expires; //cookie有效期
}
document.cookie = cookieName;
}
//得到cookie
function getcookie(name){
var cookieName = encodeURIComponent(name)+"=";
var start = document.cookie.indexOf(cookieName);
var value= null;
if(start>-1){
var end = document.cookie.indexOf(";",start);
if(end == -1){
end = document.cookie.length;
}
value= document.cookie.substring(start+cookieName.length,end);
}
return value;
}
这两个方法可以作为参考 具体一些细节判断什么的还要自己写
//添加cookie
function setCookie(name,value,expires){
var cookieName = encodeURIComponent(name)+"="+encodeURIComponent(value);
if(expires && expires instanceof Date){
cookieName+=";expires="+expires; //cookie有效期
}
document.cookie = cookieName;
}
//得到cookie
function getcookie(name){
var cookieName = encodeURIComponent(name)+"=";
var start = document.cookie.indexOf(cookieName);
var value= null;
if(start>-1){
var end = document.cookie.indexOf(";",start);
if(end == -1){
end = document.cookie.length;
}
value= document.cookie.substring(start+cookieName.length,end);
}
return value;
}
这两个方法可以作为参考 具体一些细节判断什么的还要自己写
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询