title: Can servlet change cookie of another domain
body: <p>I need to change cookies value of another domain, I know that we can not do it using javascript. Is it possible using servlet ?</p>
  
  <p>I am trying like this but no success? were am I going wrong?
  I have two web application namly Cookies1 and Cookies2 deployed in one tomcat in localhost</p>
  
  <p><strong>Servlet of cookie1 application</strong> </p>
  
  <pre><code>protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          response.setContentType("text/html");
          PrintWriter pw = response.getWriter();
  
  //      String Html = "&lt;HTML&gt;&lt;BODY&gt;HI&lt;/body&gt;&lt;/html&gt;";
  //      pw.write(Html);
  
          Cookie cookie  =  new Cookie("__utmz", "Arvind");
          cookie.setDomain("http://localhost:8080/Cookie2");
          cookie.setPath("/");
  
          response.addCookie(cookie);
  
          //response.getWriter().write(Html);
      }
  </code></pre>
  
  <p><strong>Servlet of cookie1 application</strong> </p>
  
  <pre><code>protected void doGet(HttpServletRequest request,
              HttpServletResponse response) throws ServletException, IOException {
          System.out.println("CookieSetDm.doGet()");
          Cookie[] cookies = request.getCookies();
          if (cookies != null) {
              for (int i = 0; i &lt; cookies.length; i++) {
                  System.out.println(cookies[i].getName() + " &lt;&gt; "+ cookies[i].getValue());
              }
          }
      }
  </code></pre>