怎么回事?

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

javc

2016-12-22 23:39

ype Exception report

message An exception occurred processing JSP page /details.jsp at line 65

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

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /details.jsp at line 65

62:      
63:     Cookie cookies=new Cookie("Listcookie",list);
64:    cookies.setMaxAge(10);
65:     response.addCookie(cookies);
66:    
67:      %>
68:      <%=list %>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:584)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:481)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

java.lang.IllegalArgumentException: An invalid character [44] 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)
org.apache.jsp.details_jsp._jspService(details_jsp.java:197)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
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.6 logs.

Apache Tomcat/8.5.6


写回答 关注

5回答

  • Firmiana_
    2016-12-26 12:09:12
    已采纳

    花了很久才找到问题,

    问题源头出在这一行:list += request.getParameter("id") + ",";

    在网上找答案说是tomcat的版本问题,我的理解是:

    在tomcat7.0版本以前,cookie的value当中允许出现",";

    但是之后就不支持了,所以,value里面不能放","这个符号,我猜空格应该也是不允许的,否则就会报错。

    所以可以试试用字母当作分隔符。


    qq__35...

    为啥我用字母也不行,用#也不行,用分好还是不行

    2017-01-18 17:19:44

    共 2 条回复 >

  • qq_幸福客_0
    2017-02-20 14:40:54

    所以最好还是用urlencode转一下码

  • 岚京
    2017-02-08 15:39:09

    是的,谢谢

  • liqianpro
    2017-01-11 12:22:13

    用”;“居然解决了!

  • 风雨兼程No_1
    2016-12-27 15:51:49

    正是这个问题,非常感谢

JAVA遇见HTML——JSP篇

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

248277 学习 · 3071 问题

查看课程

相似问题