jsp执行报错

java.lang.IllegalArgumentException: An invalid character [44] was present in the Cookie value
org.apache.tomcat.util.http.Rfc6265CookieProcessor.validateCookieValue(Rfc6265CookieProcessor.java:182)
org.apache.tomcat.util.http.Rfc6265CookieProcessor.generateHeader(Rfc6265CookieProcessor.java:115)
org.apache.catalina.connector.Response.generateCookieString(Response.java:976)
org.apache.catalina.connector.Response.addCookie(Response.java:928)
org.apache.catalina.connector.ResponseFacade.addCookie(ResponseFacade.java:385)
org.apache.jsp.details_jsp._jspService(details_jsp.java:194)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

问题:包含无效字符。
原因:

其实是不能直接使用逗号这种特殊符号(对cookie 0版本标准而言,新版本cookie 1没问题)作为cookie的内容。而新版本的Cookie(参见RFC 2109)目前还不被Javax.servlet.http.Cookie包所支持。
补充一下Cookie Version 0中,某些特殊的字符,例如:空格,方括号,圆括号,等于号(=),逗号,双引号,斜杠,问号,@符号,冒号,分号都不能作为Cookie的内容。

解决方法:将,分割改成#分割
.jsp文件中

list += request.getParameter("id") + "#";
String[] arr = list.split("#");

对应的.java文件中也需要修改

String[] arr = list.split("#");

参考资料:

https://www.imooc.com/qadetail/177191

你可能感兴趣的:(jsp执行报错)