Tomcat8服务器在Cookie中添加当前系统时间报错

错误信息:
HTTP Status 500 - An invalid character [32] was present in the Cookie value
type Exception report

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

description The server encountered an internal error that prevented it from fulfilling this request.

exception

java.lang.IllegalArgumentException: An invalid character [32] was present in the Cookie value
org.apache.tomcat.util.http.Rfc6265CookieProcessor.validateCookieValue(Rfc6265CookieProcessor.java:162)
org.apache.tomcat.util.http.Rfc6265CookieProcessor.generateHeader(Rfc6265CookieProcessor.java:111)
org.apache.catalina.connector.Response.generateCookieString(Response.java:989)
org.apache.catalina.connector.Response.addCookie(Response.java:937)
org.apache.catalina.connector.ResponseFacade.addCookie(ResponseFacade.java:386)
CookieDemo.doGet(CookieDemo.java:26)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/8.5.11 logs.

Apache Tomcat/8.5.11



部分Java代码为:

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
                Cookie lastCookie = new Cookie("lastCookie",df.format(new Date()));
                lastCookie.setMaxAge(3000);
                resp.addCookie(lastCookie);


解决方法:

将SimpleDateFormat df = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);代码中的空格替换为其他连接符(dd跟hh中间有空格

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值