2010-03-01 3 views
0

여기까지 내가 무엇을 얻었는지 알 수있는 몇 가지 코드가 있습니다. 이런 식으로 Word 문서를 잘 출력 할 수 있습니다. 또한 브라우저의 URL을 통해 이미지에 액세스 할 수 있지만 Word 문서 src가 서블릿과 충돌하지 않는 것으로 나타납니다 (일부 로그에 따르면).JAVA의 SSL을 통해 이미지가 포함 된 Word 문서 생성

ExportServlet.java `

response.setContentType("application/ms-word"); 

    String imageUrl = request.getScheme() + "://" + request.getServerName() + 
         ":" + request.getServerPort() + request.getContextPath() + 
         "/ExportImage"; 

    PrintWriter out = response.getWriter(); 

     out.println("<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'> 
    <head> 
      <title>Exported Documents</title> 

      <!--[if gte mso 9]> 
      <xml> 
      <w:WordDocument> 
      <w:View>Print</w:View> 
      <w:Zoom>100</w:Zoom> 
      <w:DoNotOptimizeForBrowser/> 
      <w:BreakWrappedTables/> 
      </w:WordDocument> 
      </xml> 
      <![endif]--> 
    </head> 
    <body> 
    <img src=\"" + imageUrl + "\"> 
    </body> 
</html>") 
    out.flush(); 

`

ExportImage.java

 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)) >= 0) { 
      out.write(buf, 0, count); 
     } 
     in.close(); 
     out.flush(); 
     out.close(); 
+0

Word를 사용하여 해당 URL을 이미지로 사용하여 파일을 만들려고 했습니까? – extraneon

+0

Java로 생성 한 이미지 URL이 정확히 예상 한 것임을 확인했다고 가정합니다. 그 외에도 여러 가지 가능한 오류 지점이 있습니다. 클라이언트가 실제로 이미지를 요청하고 있습니까? (예 : 올바르게 구성된 문서) 또는 클라이언트가 요청하지만 서블릿에 요청이 표시되지 않습니까? (URL 형식 또는 일부 보안 설정이지만 가능성이 낮음). –

+0

브라우저를 통해 서블릿에 직접 접속할 수 있습니다. Word 자체에 문제가 있습니다. 어떤 이유로 Word는 https를 통해 요청할 수 없습니다. 나는 엑스트라 네온이 처음부터 문서를 말하고 구성한 바를 수행했으며 Word는 그렇게 할 수 없다는 것을 보여주었습니다. 적어도 내가 찾을 수있는 것은 아닙니다. – Joseph

답변

0

다른 적절한 방법은 화상이 이미 내장하여 (서버에 완전히 문서를 생성하는 것) 그리고 분리 된 https 반입을 할 의사를 얻으려고하는 대신 요청자에게 스트림을 보냅니 까? 그렇다면 DocmosisJODReports은 이미지가있는 문서 형식의 문서를 생성 할 수 있습니다.

관련 문제