###前提・実現したいこと
おはようございます。
今回選択されたリンクに対応するPDFをJAVAで生成しそれをダウンロードさせるというWEBアプリケーションを作成しております。
###発生している問題・エラーメッセージ
PDF生成までは問題なく行えGoogleChrome、Edgeでテストをした所問題なくダウンロードまでの動作を確認できました。
しかしIE11~8(多分それ以前も)ではリンクをクリックしたらダウンロードが開始されずブラウザ上でPDFが開かれてしまいます。
###該当のソースコード
ServletOutputStream op = null; DataInputStream in = null; try { String pathRoot = bundle.getString("path.root"); String pathAttachment = bundle.getString("path.sds"); String filePath = pathRoot + pathAttachment + pdfData.getFileName(); File file = new File(filePath); if (file.exists()) { resp.setContentType("application/octet-stream"); resp.setContentLength((int) file.length()); /*ファイル名をISO_8859_1にエンコード(文字化け対策*/ resp.setHeader("Content-Disposition", "inline; filename=\"" + new String (pdfData.getLogicalName().getBytes("Windows-31J"), "ISO_8859_1") + "\""); /*ファイルの読み込み*/ int bytes = 0; op = resp.getOutputStream(); byte[] bbuf = new byte[1024]; in = new DataInputStream(new FileInputStream(file)); while ((in != null) && ((bytes = in.read(bbuf)) != -1)) { op.write(bbuf, 0, bytes); } op.flush(); } } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(op); }
###試したこと
コンテキストタイプをForce-downloadに変更する。
###補足情報(言語/FW/ツール等のバージョンなど)
開発環境:Eclipse4.3
動作サーバー:Tomcat7
ブラウザ:IE11~8
以上よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/12 00:45