使用tomcat時,若某個cookie的值中含有等號,則從request.getCookies()再getValue()後會丟失等號以後的內容,例如:若cookie爲ninfo=id=123&name=zhangshan;ntime=20150731,則從request.getCookies()取得名爲ninfo的cookie值爲「id",而不是指望的「id=123&name=zhangshan」。 apache
而一樣的代碼在jetty中就可正常取得。 tomcat
對於這個問題,https://issues.apache.org/bugzilla/show_bug.cgi?id=44679這個連接裏面有討論. cookie
核心內容爲: app
org.apache.tomcat.util.http.ServerCookie. ALLOW_EQUALS_IN_VALUE system property was introduced in Tomcat 6.0.24.
Starting with Tomcat 6.0.18 and in Tomcat 7.x any cookie containing a 「=」 will be truncated. Where you would expect your cookie to hold all values, e.g. 「value1=myname&value2=password」 you will only be able to retrieve the 「value1=」. this
This is because Tomcat now adheres to the cookie spec more tightly than previous versions. If you are in control of the cookie you might be able to change it and work around this. If not, then you can can change the settings within the catalina.properties file by appending the following two settings: spa
org.apache.tomcat.util.http.ServerCookie.ALLOW_EQUALS_IN_VALUE=true org.apache.tomcat.util.http.ServerCookie.ALLOW_HTTP_SEPARATORS_IN_V0=true
在tomcat的catalina.sh里加入一行 code
CATALINA_OPTS="$CATALINA_OPTS -Dorg.apache.tomcat.util.http.ServerCookie.ALLOW_EQUALS_IN_VALUE=true -Dorg.apache.tomcat.util.http.ServerCookie.ALLOW_HTTP_SEPARATORS_IN_V0=true" blog
參考: get
http://bingoohuang.iteye.com/blog/1401461 it
http://thenitai.com/2013/05/02/tomcat-truncating-cookies-with-values/