Interaction between Applet, Cookie e ASP.net doesn't works in Firefox
Hi!
I have an Applet that gets the username through a cookie set by asp.net page (the page that contains the applet).
Java Code to get the cookie
------------------------------
private void getUserNameFromCookie() { try { // get the cookies that are applicable for this applet's parent web page URL docBaseUrl = this.getDocumentBase(); CookieHandler cookieHandler = CookieHandler.getDefault(); java.util.Map<String, List<String>> headers = cookieHandler.get(docBaseUrl.toURI(), new HashMap<String, List<String>>()); if (headers.isEmpty()) { System.out.println("No cookies found!"); } else { getUserNameFromHeader(headers); } } catch (Exception e) { System.out.println("Unable to get cookie using CookieHandler"); e.printStackTrace(); } } private void getUserNameFromHeader(java.util.Map<String, List<String>> headers) { for (String key : headers.keySet()) { for (String value : headers.get(key)) { if (key.equals("Cookie") && value.startsWith("userName")) { userName = value.split("=")[1]; } } } }
Yes, cookies are enabled.
It's weird this works in IE and don't in Firefox....
Java console shows this information after applet's loading (and a lot of other things)
network: Connecting http://localhost:55000/page.aspx with cookie "__utma_a2a=6852338610.1305743161.1274186235.1274560427.1274878003.51; userName=testuser@mail.com"
Apparently there are two cookies in this page (I don't know where the first cookie come from).
Considering that are two cookies in page, am I getting it in the right way in Java?
In Firefox
network: Connecting http://localhost:55000/page.aspx with cookie "__utma_a2a=6852338610.1305743161.1274186235.1274560427.1274878003.51; userName=testuser@mail.com"
Maybe I'm getting the wrong index in Java...
How should script the Java code to get the value in userName field, both in IE and Firefox?
Thanks in advance!
try read cookies with JSObject:
http://www.codessentials.com/codingtips/39-javatips/63-cookiesfromapplet.html