An invalid character [44] was present in the Cookie value

来源:8-8 使用Cookie实现保存商品浏览记录

Dong_Cool

2016-10-28 11:32

Servlet.service() for servlet [jsp] in context with path [/MartShoping] threw exception [java.lang.IllegalArgumentException: An invalid character [44] was present in the Cookie value] with root cause

java.lang.IllegalArgumentException: An invalid character [44] was present in the Cookie value

at org.apache.tomcat.util.http.Rfc6265CookieProcessor.validateCookieValue(Rfc6265CookieProcessor.java:162)

at org.apache.tomcat.util.http.Rfc6265CookieProcessor.generateHeader(Rfc6265CookieProcessor.java:111)

at org.apache.catalina.connector.Response.generateCookieString(Response.java:989)

at org.apache.catalina.connector.Response.addCookie(Response.java:937)

at org.apache.catalina.connector.ResponseFacade.addCookie(ResponseFacade.java:386)

at org.apache.jsp.detail_jsp._jspService(detail_jsp.java:220)

at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)

at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)

at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)

at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)

at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)

at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410)

at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Unknown Source)


写回答 关注

9回答

  • pardon110
    2018-03-03 09:35:19

    其实是不能直接使用逗号这种特殊符号(对cookie 0版本标准而言,新版本cookie 1没问题)作为cookie的内容。而新版本的Cookie(参见RFC 2109)目前还不被Javax.servlet.http.Cookie包所支持。

    补充一下Cookie Version 0中,某些特殊的字符,例如:空格,方括号,圆括号,等于号(=),逗号,双引号,斜杠,问号,@符号,冒号,分号都不能作为Cookie的内容。

  • pardon110
    2018-03-03 09:23:13

    赞一个

  • 阿西莫夫
    2018-02-11 22:26:19

    一样的情况

  • 淋某人
    2017-06-24 08:46:52

    为什么不能使用","作为分隔符?有点神奇

  • Jarly杰
    2017-04-05 15:54:19

    list+=request.getParameter("id")+"#";
    //如果浏览记录超过1000条,清零.
    String[] arr = list.split("#");
    if(arr!=null&&arr.length>0)
    {
       if(arr.length>=1000)
       {
           list="";
       }
    }
    Cookie cookie = new Cookie("ListViewCookie",list);
    response.addCookie(cookie);

    将逗号,换成#,记得itemdao的方法也是

    他的

    赞赞赞

    2017-07-19 14:34:40

    共 3 条回复 >

  • qq_哥风度翩翩_0
    2017-01-25 20:41:36

    这个是无效字符的意思,你看一下你的value中有没有像“,”之类的东西,有的话删了试试,如果可以那就是这个符号的问题,专门注册了一个账号给你回复!!!

  • 糖醋肉3984350
    2016-11-23 18:03:45

    我也是。。怎么解决啊。换成1.7还是不行

    慕九州052...

    遇到一样的情况求解决?

    2017-01-24 22:43:28

    共 1 条回复 >

  • qq_背景_0
    2016-11-15 13:59:00

    这是JDK版本的问题,我的也是这个问题,所以我把jdk1.8换成1.7了,已经解决。

    慕数据969...

    遇到一样的情况

    2016-11-17 18:49:47

    共 1 条回复 >

  • Dong_Cool
    2016-10-28 11:32:52

    怎么解决?

JAVA遇见HTML——JSP篇

Java Web入门级教程JSP,带你轻松的学习JSP基础知识

248278 学习 · 3071 问题

查看课程

相似问题