title: Java applet get document cookies?
body: <p>And for the life of me I can't figure out why I can't access the document's cookies for the applet's origin. Same page, same IP address. When I actually make the connection via Java, I see the cookies being sent (in wireshark), so I know they're there.</p>
  
  <p>Does anyone have any alternate ways to try to access the document cookies from Java? I've scoured around the internet, and can't seem to find anything that might work besides the <code>getRequestProperty()</code> method! </p>
  
  <p>I have the following applet code:</p>
  
  <pre><code>import java.applet.*;
  import java.net.*;
  import java.util.*;
  import java.io.*;
  import netscape.javascript.*;
  
  public class test extends Applet {
      public void init() {
      try {
          URL url = new URL("http://10.0.0.5/java/test.html");            
          String inputLine;
          URLConnection conn = url.openConnection();
  
          System.out.print("Cookies:\n");
          String m = conn.getRequestProperty("Cookie");
          // Returns null :-/
          System.out.println(m);
  
          // Read page content =&gt; works fine... (sends cookie)
          //BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
          //while ((inputLine = in.readLine()) != null) 
          //    System.out.println(inputLine);
          //in.close();        
      } catch (Exception e) { 
          System.out.println("Error :(");
          System.out.println(e.getMessage());
      }
      String alert = "alert(document.cookie);";
      JSObject win = (JSObject) JSObject.getWindow(this);
      win.eval(alert);
      }
  }
  </code></pre>
  
  <p>Also is there any way to get the <code>JSObject</code> window to my <code>URLConnection</code>? Otherwise it sets me in the context of the current applet window...</p>