title: Generating a Word doc with an image embedded into it over SSL in JAVA
body: <p>Here is some code snippet to give you an idea of what I got so far. I can output the Word document fine this way. I can also access the image via the URL in the browser, but the Word documents src does not appear to be hitting the servlet(according to some logs I have).</p>
  
  <p>ExportServlet.java
  ` </p>
  
  <pre><code>    response.setContentType("application/ms-word");
  
      String imageUrl = request.getScheme() + "://" + request.getServerName() +
                        ":" + request.getServerPort() + request.getContextPath() +
                        "/ExportImage";
  
      PrintWriter out = response.getWriter();
  
          out.println("&lt;html xmlns:o='urn:schemas-microsoft-com:office:office'
      xmlns:w='urn:schemas-microsoft-com:office:word'
      xmlns:v='urn:schemas-microsoft-com:vml'
      xmlns='http://www.w3.org/TR/REC-html40'&gt;
      &lt;head&gt;
              &lt;title&gt;Exported Documents&lt;/title&gt;
  
              &lt;!--[if gte mso 9]&gt;
             &lt;xml&gt;
             &lt;w:WordDocument&gt;
             &lt;w:View&gt;Print&lt;/w:View&gt;
             &lt;w:Zoom&gt;100&lt;/w:Zoom&gt;
             &lt;w:DoNotOptimizeForBrowser/&gt;
             &lt;w:BreakWrappedTables/&gt;
             &lt;/w:WordDocument&gt;
             &lt;/xml&gt;
             &lt;![endif]--&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;img src=\"" + imageUrl + "\"&gt;
      &lt;/body&gt;
  &lt;/html&gt;")
      out.flush();
  </code></pre>
  
  <p>`</p>
  
  <p>ExportImage.java</p>
  
  <pre><code>      Logger.log("getting Image");
        ServletContext servletContext = getServletContext();
          String filename = servletContext.getRealPath("myImage.gif");
          response.setContentType(
                  servletContext.getMimeType(filename));
          File file = new File(filename);
          response.setContentLength((int)file.length());
  
          FileInputStream in = new FileInputStream(file);
          OutputStream out = response.getOutputStream();
  
          // Copy the contents of the file to the output stream
          byte[] buf = new byte[1024];
          int count = 0;
          while ((count = in.read(buf)) &gt;= 0) {
              out.write(buf, 0, count);
          }
          in.close();
          out.flush();
          out.close();
  </code></pre>