An invalid character [32] was present in the Cookie value 错误

今天在做cookie部分的demo的时候出现了一个错误Servlet部分的代码如下

 Date data=new Date();
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String Last = format.format(data);
// System.out.println(Last); Cookie cookie =new Cookie("Lastname",Last);
cookie.setMaxAge(60*10*500);
response.addCookie(cookie);
//获得用户携带的cookie
String last=null;
Cookie[] cookies = request.getCookies();
if(cookies!=null){
for(Cookie coo:cookies){
if("Lastname".equals(coo.getName())){
last = coo.getValue(); }
}
} response.setContentType("text/html;charset=utf-8");
if(last==null){ response.getWriter().write("您是第一次访问");
}else{
response.getWriter().write("你上次访问的时间为"+last);
}

再访问该Servlet的时候页面就为500,并报异常An invalid character [32] was present in the Cookie value,

An invalid character [32] was present in the Cookie value 错误

后来发现32对应的编码是空格,后来发现

SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");代码中产生了空格,后改为
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd-hh:mm:ss");就可正常访问了
An invalid character [32] was present in the Cookie value 错误
 
上一篇:Linux 中Ctrl + s 的作用


下一篇:Prometheus监控elasticsearch集群(以elasticsearch-6.4.2版本为例)