开发者

How to get cookies in Java?

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();
            }
        }       
    }
}
开发者_开发知识库


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).

Fiddler is a Web Debugging Proxy which logs all HTTP(S) traffic between your computer and [other machines]. Fiddler allows you to inspect traffic, set breakpoints, and "fiddle" [or just inspect] with incoming or outgoing data.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜