Java 如何在 tomcat 8 中将 Cookie Processor 更改为 LegacyCookieProcessor
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38696081/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change Cookie Processor to LegacyCookieProcessor in tomcat 8
提问by Sachin Sharma
My code is working on tomcat 8 version 8.0.33 but on 8.5.4 i get : An invalid domain [.mydomain] was specified for this cookie.
我的代码在 tomcat 8 版本 8.0.33 上运行,但在 8.5.4 上我得到:为此 cookie 指定了无效域 [.mydomain]。
I have found that Rfc6265CookieProcessor is introduced in tomcat 8 latest versions.
我发现在 tomcat 8 最新版本中引入了 Rfc6265CookieProcessor。
It says on official doc that this can be reverted to LegacyCookieProcessor in context.xml but i don't know how.
它在官方文档上说这可以在 context.xml 中恢复为 LegacyCookieProcessor,但我不知道如何。
Please let me know how to do this.
请让我知道如何做到这一点。
Thanks
谢谢
采纳答案by linzkl
You can try in context.xml
您可以在 context.xml 中尝试
<CookieProcessor className="org.apache.tomcat.util.http.LegacyCookieProcessor" />
reference: https://tomcat.apache.org/tomcat-8.0-doc/config/cookie-processor.html
参考:https: //tomcat.apache.org/tomcat-8.0-doc/config/cookie-processor.html
回答by smos
Enabling the LegacyCookieProcessorwhich is used in previous versions of Tomcat has solved the problem in my application. As linzkl mentioned this is explained in Apache's website https://tomcat.apache.org/tomcat-8.0-doc/config/cookie-processor.html.
启用旧版Tomcat 中使用的LegacyCookieProcessor解决了我的应用程序中的问题。正如 linzkl 所提到的,Apache 的网站https://tomcat.apache.org/tomcat-8.0-doc/config/cookie-processor.html对此进行了解释。
The reason is that the new version of Tomcat does not understand the . (dot) in front of the domain name of the Cookie being used.
原因是新版本的Tomcat不理解. (点)在正在使用的 Cookie 的域名前面。
Also, make sure to check this postwhen you are using Internet Explorer. Apparently, it's very likely to break.
另外,请确保在使用 Internet Explorer 时查看此帖子。显然,它很可能会破裂。
You can find context.xml in the following path.
您可以在以下路径中找到 context.xml。
tomcat8/conf/context.xml
tomcat8/conf/context.xml
<?xml version="1.0" encoding="UTF-8”?>
<!-- The contents of this file will be loaded for each web application —>
<Context>
<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!-- <Manager pathname="" /> -->
<CookieProcessor className="org.apache.tomcat.util.http.LegacyCookieProcessor"/>
</Context>
回答by Atul
The problem is still with Tomcat9. Same process need to follow for Tomcat 9 to set the class.
问题仍然出在Tomcat9上。Tomcat 9 需要遵循相同的过程来设置类。
Add the class in context.xml file.
在 context.xml 文件中添加类。
If you are using eclipse to run the application, need to set in the context.xml file in the server folder. Refer the below screenshot for more reference.
如果使用eclipse运行应用程序,需要在server文件夹下的context.xml文件中进行设置。请参阅以下屏幕截图以获取更多参考。
Hope this helps someone.
希望这可以帮助某人。
回答by IamVickyAV
Case 1:You are using Standalone Tomcat& have accessto change files in tomcat server
案例1:您正在使用独立的Tomcat和访问,以改变文件的Tomcat服务器
Please follow answerby @linzkl
请按照@linzkl 的回答
Case 2:You are using Standalone Tomcatbut you don't have accessto change files in tomcat server
案例 2:您使用的是Standalone Tomcat,但您无权更改 tomcat 服务器中的文件
Create a new file called context.xml under src/main/webapp/META-INFfolder in your application & paste the content given below
在您的应用程序的src/main/webapp/META-INF文件夹下创建一个名为 context.xml 的新文件并粘贴下面给出的内容
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<CookieProcessor className="org.apache.tomcat.util.http.LegacyCookieProcessor" />
</Context>
When you deploy your application in Standalone Tomcat, the context.xml file you placed under META-INF folder will override the context.xml file given in tomcat/conf/context.xml
当您在独立 Tomcat 中部署应用程序时,您放置在 META-INF 文件夹下的 context.xml 文件将覆盖在 tomcat/conf/context.xml 中给出的 context.xml 文件
Note: If you are following this solution, you have to do it for every single application because META-INF/context.xmlis application specific
注意:如果您遵循此解决方案,则必须为每个应用程序执行此操作,因为META-INF/context.xml是特定于应用程序的
Case 3:You are using Embedded Tomcat
案例 3:您使用的是嵌入式 Tomcat
Create a new bean for WebServerFactoryCustomizer
为 WebServerFactoryCustomizer 创建一个新的 bean
@Bean
WebServerFactoryCustomizer<TomcatServletWebServerFactory> cookieProcessorCustomizer() {
return new WebServerFactoryCustomizer<TomcatServletWebServerFactory>() {
@Override
void customize(TomcatServletWebServerFactory tomcatServletWebServerFactory) {
tomcatServletWebServerFactory.addContextCustomizers(new TomcatContextCustomizer() {
@Override
public void customize(Context context) {
context.setCookieProcessor(new LegacyCookieProcessor());
}
});
}
};
}