Tomcat7在前端JS获取不到cookie问题(附上获取cookie/JS)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bestxianfeng163/article/details/83863154

tomcat7中的context.xml加上这个属性就可以了,

如果程序员后端控制cookie.setHttpOnly(false)

​
window.onload=function (){
	 function getSessionId(){  
	     var c_name = 'JSESSIONID';  
	     console.log(document.cookie);
	     if(document.cookie.length>0){  
	    	 console.log("进来了吗");
	    	
	        c_start=document.cookie.indexOf(c_name + "=")  
	        if(c_start!=-1){   
	          c_start=c_start + c_name.length+1   
	          c_end=document.cookie.indexOf(";",c_start)  
	          if(c_end==-1) c_end=document.cookie.length  
	          return unescape(document.cookie.substring(c_start,c_end));  
	        }  
	     }  
	 }  
	 console.log("sessionId=="+getSessionId());
 }

​

猜你喜欢

转载自blog.csdn.net/bestxianfeng163/article/details/83863154