近日使用Tomcat调试的时候,使用response写入一个Cookie,发现Cookie的值带上了双引号,百思不得其解,查找源码发现Tomcat在写入Cookie值有"/" 的时候,为避免错误,Tomcat做了以下处理:
org.apache.tomcat.util.http.ServerCookie
private static void maybeQuote (StringBuffer buf, String value) {
if (value==null || value.length()==0) {
buf.append("\"\"");
} else if (CookieSupport.alreadyQuoted(value)) {
buf.append('"');
buf.append(escapeDoubleQuotes(value,1,value.length()-1));
buf.append('"');
} else if (CookieSupport.isHttpToken(value) &&
!CookieSupport.ALLOW_HTTP_SEPARATORS_IN_V0 ||
CookieSupport.isV0Token(value) &&
CookieSupport.ALLOW_HTTP_SEPARATORS_IN_V0) {
buf.append('"');
buf.append(escapeDoubleQuotes(value,0,value.length()));
buf.append('"');
} else {
buf.append(value);
}
}
查询Tomcat文档,解释如下:
org.apache.catalina. STRICT_SERVLET_COMPLIANCE
If this is true
the following actions will occur:
- any wrapped request or response object passed to an application dispatcher will be checked to ensure that it has wrapped the original request or response. (SRV.8.2 / SRV.14.2.5.1)
- a call to
Response.getWriter()
if no character encoding has been specified will result in subsequent calls toResponse.getCharacterEncoding()
returningISO-8859-1
and theContent-Type
response header will include acharset=ISO-8859-1
component. (SRV.15.2.22.1) - every request that is associated with a session will cause the session's last accessed time to be updated regardless of whether or not the request explicitly accesses the session. (SRV.7.6)
-
cookies will be parsed strictly, by default v0 cookies will not work with any invalid characters.
If set tofalse
, any v0 cookie with invalid character will be switched to a v1 cookie and the value will be quoted. -
the path in
ServletContext.getResource
/getResourceAsStream
calls must start with a "/".
If set tofalse
, code likegetResource("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
property- The
webXmlValidation
attribute of any Context element. - The
webXmlNamespaceAware
attribute of any Context element. - The
tldValidation
attribute of any Context element.
If not specified, the default value of false
will be used.
解决办法:
在catalina.properties里边增加一行:
org.apache.catalina.STRICT_SERVLET_COMPLIANCE=true
或者自行修改源码
影响版本:暂时确认有Tomcat 6、7
相关推荐
tomcat修改jsessionid在cookie中的名称
tomcat启动不了问题处理 解决tomcat启动不了问题
tomcat中server配置文件的结构,以及处理一个http请求的全过程
tomcat出现OutOfMemoreError的处理方法
tomcat最新客户端tomcat最新客户端tomcat最新客户端tomcat最新客户端tomcat最新客户端tomcat最新客户端tomcat最新客户端tomcat最新客户端tomcat最新客户端tomcat最新客户端tomcat最新客户端tomcat最新客户端tomcat...
内含tomcat7 tomcat8 tomcat9免安装版本;供需要的人下载。
基于tomcat服务器的跨域处理, 包含cors-filter-1.7.jar,Java -property-utils-1.9.jar 配置跨域 <!--跨域--> <groupId>com.thetransactioncompany</groupId> <artifactId>Java-property-utils <version>...
包含tomcat7,tomcat8,tomcat9,解压、在eclipse配置好即可。
tomcat 5.0tomcat 5.0tomcat 5.0tomcat 5.0tomcat 5.0tomcat 5.0tomcat 5.0tomcat 5.0tomcat 5.0tomcat 5.0tomcat 5.0tomcat 5.0tomcat 5.0tomcat 5.0tomcat 5.0tomcat 5.0
Tomcat请求处理UML序列图 序列图 UML序列图 请求处理UML序列图
Tomcat Tomcat Tomcat Tomcat
虽然Tomcat也可以作web服务器,但其处理静态html的速度比不上Apache,且其作为web服务器的功能远不如Apache,因此把Apache和Tomcat集成起来,将html和Jsp的功能部分进行明确分工,让Tomcat只处理Jsp部分,其他的由...
3-6Tomcat处理源码实现与异步Servlet源码实现(1).mp4
tomcat已经启动Soket异常处理,看后不用再遇到类似问题重启电脑了。
tomcat8.0版本下载tomcat8.0版本下载tomcat8.0版本下载tomcat8.0版本下载tomcat8.0版本下载tomcat8.0版本下载tomcat8.0版本下载tomcat8.0版本下载tomcat8.0版本下载tomcat8.0版本下载tomcat8.0版本下载tomcat8.0版本...
tomcat 系列tomcat 系列tomcat 系列
tomcat日志乱码处理方法总结。自己研究,可解决任何tomcat乱码问题
这是我实战的笔记,全程直播。 #### Tomcat和Openssl构建HTTPS双向认证 ###### ...二、tomcat实现双向认证 1、创建服务器信任的CA证书库 2、配置Tomcat支持HTTPS双向认证(服务器将认证客户端证书)
tomcat内存溢出处理方法适用于java,开发工具myeclipse或eclipse
tomcat 6.0.35