今天在做记录用户访问时间时,页面报错
An invalid character [32] was present in the Cookie value
主要是通过HttpServletResponse addCookie(Cookie cookie)向客户端写cookie信息;
出现空格非法字符:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");报错,有空格
String currentTime = simpleDateFormat.format(new Date());
Cookie last = new Cookie("last", currentTime);
解决办法
通过HttpServletRequest getCookies()读取cookie。
通过URLEncoder.encode(String s)对URL进行编码。
通过URLDecoder.decode(String s)对URL进行解码。