Java中如何获取cookies?
我正在实现一个从 ASP 到 Java 程序的项目。在Java类中,我想要的是获取ASP程序设置的cookie。
这可能吗?
如果是这样,我手头有这段代码,但它不起作用......
class AfficheMonCookie extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
String Valeur = "";
Cookie[] cookies = request.getCookies();
for(int i=0; i < cookies.length; i++) {
Cookie MonCookie = cookies[i];
if (MonCookie.getName().equals("FXA")) {
Valeur = cookies[i].getValue();
}
}
}
}
I'm implementing a project from ASP that cross to a Java program. In a Java class, what I want is to get the cookies that is set by the ASP program.
Is that possible?
If so, I have this code at hand but its not working....
class AfficheMonCookie extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
String Valeur = "";
Cookie[] cookies = request.getCookies();
for(int i=0; i < cookies.length; i++) {
Cookie MonCookie = cookies[i];
if (MonCookie.getName().equals("FXA")) {
Valeur = cookies[i].getValue();
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用诸如 fiddler 之类的网络监控工具来检查 ASP 站点设置的 cookie (
Set- Cookie
响应标头)并查看 Cookie 是否进入 Servlet HTTP 请求(Cookie
请求标头)。请记住,cookie来自客户端(例如网络浏览器),并且仅发送给匹配的域和路径 - 它们可能从未被发送到Java 服务器。
快乐编码。
Use a network monitor tool like fiddler to inspect the cookies set by the ASP site (
Set-Cookie
response header) and to see if the cookies make it to the Servlet HTTP request (Cookie
request header).Remember that the cookies come from the client (e.g. web-browser) and are only sent for matching domains and paths -- it may be possible they were/are never sent to the Java server at all.
Happy coding.