本文共 2341 字,大约阅读时间需要 7 分钟。
近日使用Tomcat调试的时候,使用response写入一个Cookie,发现Cookie的值带上了双引号,百思不得其解,查找源码发现Tomcat在写入Cookie值有"/" 的时候,为避免错误,Tomcat做了以下处理:
org.apache.tomcat.util.http.ServerCookie
查询Tomcat文档,解释如下:
org.apache.catalina. STRICT_SERVLET_COMPLIANCE
If this is true
the following actions will occur:
Response.getWriter()
if no character encoding has been specified will result in subsequent calls to Response.getCharacterEncoding()
returningISO-8859-1
and the Content-Type
response header will include a charset=ISO-8859-1
component. (SRV.15.2.22.1)false
, any v0 cookie with invalid character will be switched to a v1 cookie and the value will be quoted. ServletContext.getResource
/ getResourceAsStream
calls must start with a "/".If set to false
, code like getResource("myfolder/myresource.txt")
will work.
If this is true
the default value will be changed for:
org.apache.catalina.connector.Request. ALLOW_EMPTY_QUERY_STRING
propertywebXmlValidation
attribute of any element.webXmlNamespaceAware
attribute of any element.tldValidation
attribute of any element.
If not specified, the default value of false
will be used.
解决办法:
在catalina.properties里边增加一行:
org.apache.catalina.STRICT_SERVLET_COMPLIANCE=true
或者自行修改源码
影响版本:暂时确认有Tomcat 6、7
转载地址:http://jvasa.baihongyu.com/