这是我的action里面的代码 
if(userId!=null && !userId.equals("")){
session.setAttribute("userId", userId);
Cookie cook =new Cookie("userId", userId);
cook.setMaxAge(999);
response.addCookie(cook);
}
这是我的js代码:
function getCounterCookie(key){
   
   
    alert(key);
   var cookies = document.cookie;
   alert("cookies=="+cookies);
  var hasreviewTime = cookies.indexOf(key+'=');
alert("hasreviewTime=="+hasreviewTime);
var start = cookies.indexOf(key+"=")+reviewId.length+1;
alert("start=="+start);
    var end = cookies.indexOf(';', start);
    alert("end=="+end);
if(end==-1){end= cookies.length;
alert("end2=="+end);
}
var idStr = cookies.substring(start, end);alert(idStr);

}
各位大哥快快给力的回答吧(小弟已经没分了,还望各位大哥大姐海涵)