title: Get cookies set by Java in Javascript
body: <p>I am trying to set cookies using java as shown <a href="https://docs.oracle.com/javase/tutorial/deployment/doingMoreWithRIA/accessingCookies.html" rel="nofollow">here</a>.</p>
  
  <p>I want to use this cookie in javascript (due to some constraints need to use it like this only). But I am not able to see any cookies set (for that I am using <a href="https://addons.mozilla.org/en-us/firefox/addon/web-developer/" rel="nofollow">web developer addon firefox</a>). </p>
  
  <p>Is there a way to do this? Is this kind of cookie usage even possible?</p>
  
  <p>Java code:</p>
  
  <pre><code>try {
              // instantiate CookieManager
              CookieManager manager = new CookieManager();
              CookieHandler.setDefault(manager);
              CookieStore cookieJar =  manager.getCookieStore();
  
              // create cookie
              HttpCookie cookie = new HttpCookie("UserName", str);
  
              // add cookie to CookieStore for a
              // particular URL
              URL url = new URL("http://host.example.com");
              cookieJar.add(url.toURI(), cookie);
              System.out.println("Added cookie using cookie handler");
          } catch(Exception e) {
              System.out.println("Unable to set cookie using CookieHandler");
              e.printStackTrace();
          }
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>function Cookie(cname){
      alert("in getcookie function");
      var name = cname + "=";
      var ca = document.cookie.split(';');
  
      for(var i=0; i&lt;ca.length; i++) {
          var c = ca[i];
          while (c.charAt(0)==' ') c = c.substring(1);
          if (c.indexOf(name) == 0) 
              document.getElementById("result").innerHTML=c.substring(name.length,c.length);
      }
      console.log(document.cookie);
      //document.getElementById("result").innerHTML="somewhere something went wrong!";
  }
  &lt;/script&gt;
  
  &lt;div id="result"&gt;
      &lt;p onclick="Cookie('JSESSIONID')"&gt;Click me&lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The console.log did not show any output.</p>