如何在ASP中正确读取Tomcat带有引号值的cookie?
我们有一个站点,将 Tomcat 下的 Java Web 应用程序与 ASP 页面集成,包括以传统 ASP 键/值格式共享 cookie 中的信息:
Cookie: foo=a=b&c=d; ...
从 Tomcat 5.5.26 开始,cookie 处理已略有更改,其效果是我们的 cookie 值现在用引号括起来,以前不是这样的:
Cookie: foo="a=b&c=d"; ...
但是,我们有 ASP 代码也读取此 cookie,并且期望其中的值可解析,因此:
Response.Write("["+Request.Cookies("foo")("c")+"]");
现在无法返回预期结果:
[d"]
我已阅读关于使用:
javax.servlet.http.Cookie#setVersion(int)
来修改此行为,但这似乎不是这里所需要的。我知道引用的值更“正确”,但是尝试告诉 ASP...我是否错过了让 ASP(或 Tomcat)发挥良好作用的技巧?一如既往的TIA。
We have a site which integrates Java web apps under Tomcat with ASP pages, including sharing information in cookies in the traditional ASP key/value format:
Cookie: foo=a=b&c=d; ...
As of Tomcat 5.5.26, cookie handling has been altered slightly, with the effect that our cookie value is now enclosed in quotes, which wasn't the case before:
Cookie: foo="a=b&c=d"; ...
However, we have ASP code that also reads this cookie, and which expects the values in it to be parseable thus:
Response.Write("["+Request.Cookies("foo")("c")+"]");
This now fails to return the expected result:
[d"]
I have read about the use of:
javax.servlet.http.Cookie#setVersion(int)
to modify this behaviour but it doesn't seem to be what is needed here. I am aware that the quoted value is more "correct", but try telling ASP that... Is there any trick I have missed about getting ASP (or Tomcat) to play nice? TIA as always.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
引用的 cookies 对应 cookie 版本 > 1 或 2
非引用的 cookie 对于 cookie 版本 0 有效
如果您查看 tomcats bugzilla 上非常有趣的讨论:https://issues.apache.org/bugzilla/show_bug.cgi?id=44679 似乎有多种方法可以调整 tomcats cookie 行为。
如果您可以控制 tomcat 设置 cookie,那么这将是切换到非带引号 cookie 的方法:
此 cookie 将不带引号保存,但也会限制您使用较小的字符集和附加规则,例如没有任何前导/尾随空间。
Quoted cookies correnspond to cookie version > 1 or 2
Non-quoted cookies are valid for cookie version 0
If you have a look at the very interesting discussion over at tomcats bugzilla: https://issues.apache.org/bugzilla/show_bug.cgi?id=44679 there seem to be multiple ways to tune tomcats cookie behaviour.
If you have control about tomcat setting the cookies then this would be the way to switch to non quoted cookies:
This cookie will be be saved unquoted but will also restrict you to a smaller char-set and additional rules like not having any leading/trailing spaces.