如何在 Java servlet 中获取 ASP.NET 创建的 cookie?
这是我在 ASP.NET 中的 Cookie
emid=11&eud=11&euid=33zU4Yq/p3k=&euseremail=F/zVoXtd4NoAd7yj6Z47gxFVaMCMYha/La6IzlC+xQo=&euserid=33zU4Yq/p3k=&emdn=testing
但是当我尝试在 Servlet 中调用它时,它只打印:emid [仅打印第一个等于 (=) 符号之前的起始字符串]
我在 Servlet 中使用以下代码来打印 cookie..
Cookie cookie = null;
Cookie[] cookies = null;
cookies = request.getCookies();
if( cookies != null ){
out.println("<h2> Found Cookies Name and Value</h2>");
for (int I = 0; I < cookies.length; I++){
cookie = cookies[I];
out.print("Name : " + cookie.getName( ) + ", ");
out.print("Value: " + cookie.getValue( )+" \n");
}
}else{
out.println(
"<h2>No cookies founds</h2>");
}
我的代码有什么问题吗?
最佳答案
等于字符是 cookie 值中的保留字符。解决此问题的符合规范的方法是用双引号将 cookie 值引起来。然而,有些浏览器不能很好地处理这个问题。如果您使用的是 Tomcat,则可以设置系统属性 -Dorg.apache.tomcat.util.http.ServerCookie.ALLOW_EQUALS_IN_VALUE=true
以允许 cookie 值相等。
关于java - 如何在Java servlet中获取asp.net创建的cookie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10562162/