我在tomcat 6.0.33上部署了一个应用程序,它生成一个带有正斜杠(/)的cookie作为cookie值中的一个字符。现在由于某种原因,只要存在正斜杠,tomcat就会将cookie值括在双引号中。如何在我的cookie值中出现正斜杠时,如何更改tomcat行为以避免使用双引号?
N.B。我不同意BaluC这是一个重复的问题。在我发布这个之前我确实检查了另一个。我在这个问题中特别询问了如何更改tomcat行为以删除引号。这与提问者想知道为什么首先引入双引号的其他问题完全不同。
答案 0 :(得分:2)
I found that the issue is with the Tomcat version. The cookie processor encloses the cookie value in quotes when it encounters forward slash. I upgraded to Tomcat 7 and those quotes are gone. The rules on cookie value are relaxed in Tomcat 7.
I further discovered that even in Tomcat 7, if there is '=' in cookie value, Tomcat encloses the value in double quotes. I overcame this by further upgrading to Tomcat 8 and then changing it's cookie processor to Rfc6265CookieProcessor.
答案 1 :(得分:-2)
你应该使用rawurlencode(),而不是urlencode()来转义路径部分。 urlencode()名称错误,实际上是application / x-www-form-urlencoded数据,例如查询字符串或POST请求的正文,而不是URL的其他部分。