1

GWT-EXTでは、以下のようにサーブレットを利用したファイルダウンロード機能を利用しています。

サーブレット マッピングを次のように定義しました。

<servlet id="FileDownloadServlet">
        <servlet-name>FileDownloadServlet</servlet-name>
        <display-name>File Download Servlet</display-name>
        <servlet-class>
            com.xxx.XTFFileDownloadServlet
        </servlet-class>        
</servlet>
<servlet-mapping id="FileDownloadServletMapping">
        <servlet-name>FileDownloadServlet</servlet-name>
        <url-pattern>/filedownload</url-pattern>
</servlet-mapping>

次のようにサーブレットを定義しました。ファイルパスとファイル名はデータベースから受け取ります。そして、PDFファイル/バイナリデータをサーブレット出力ストリームに書き込んでいます。

     String filePath = "FILEPATHFROMDB";
    String fileName = "FILENAMEFROMDB"
            File file = new File(filePath, fileName);

            response.setContentType("application/pdf");
            response.setHeader("Content-disposition", "attachment; filename=\"" + "GUIDE.pdf" + "\"");

            out = response.getOutputStream();
            fileInputStream = new FileInputStream(file);
            byte[] buff = new byte[(int) file.length()];
            fileInputStream.read(buff);

            out.write(buff);

クライアント側では、次のコードを使用して filedownload イベントをトリガーしました。

    Window.open(GWT.getHostPageBaseURL()+"filedownload", "_self", "");

現在、UI で次の例外が発生しています。

    The webpage cannot be found 
     HTTP 404 

そしてGWTコンソールではそれは言っています。

    [TRACE] The development shell servlet received a request for 'filedownload' in module 'com.abc.def.ghi.hhhhh.Module' 
[WARN] Resource not found: filedownload

助けてください。

4

0 に答える 0