解決策が見つかりました。
ボタン(MSD)をサーブレットへのパスをパラメータとして「ビュー」を渡すJavaScript関数を呼び出し、HTMLでは、ブートストラップ3.3.5
を使用し、ファイルの拡張子:
<button class="btn-doc-sm btn-default" type="button"
onclick="view('<% out.print(MSD?p=c:/upload/documents/document.docx&action=view)); %>', '<% out.print(ext); %>')" id="view">
<span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span>View
</button>
。 js関数はパスの値をpathDocによって識別されるモーダルに設定し、 'view'モーダルを開きます。
function view(path, ext) {
var booleanValue;
if (path !== null) {
$("#pathDoc").attr("src", path);
$("#view").modal('show');
booleanValue = true;
}
if (booleanValue !== true) {
$("#error").modal('show');
}
}
モーダル:
<div class="modal fade" id="view" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<!-- Header -->
<div id="confirmacao-label1">
<a href="#close" title="Close" data-dismiss="modal" class="closeModal">X</a>
</div>
<!-- End header -->
<div class="modal-body">
<div class="embed-responsive embed-responsive-4by3" id="modal-embed">
<iframe class="embed-responsive-item" id="pathDoc" nome="pathDoc" src=""></iframe>
</div>
</div>
</div>
</div>
</div>
「変数のパスは」「本当のパス」パラメータとしてアクションを渡してサーブレットを呼び出すためのリンクです。サーブレットはファイルとともに出力を開きます。
switch(action){
case "view":
try {
File file = new File(filePath);
String name = file.getName();
int fileSize = (int) file.length();
response.setContentType(action);
response.setContentLength(fileSize);
response.setHeader("Content-Disposition", "inline; filename=\"" + name + "\"");
output = response.getOutputStream();
Files.copy(file.toPath(), output);
break;
} catch (Exception ex) {
System.out.println(ex.getMessage());
} finally {
output.close();
}
break;
したがって、Modalが呼び出されると、ファイルを開くサーブレットへのリンクがsrcに設定されます。サーブレットを検索し、出力時にファイルを開きます。
基本的に、Googleドライブのようにブラウザのモーダルウィンドウでファイルをプレビューしたいのですか?どのようなファイルですか? – pleft
はい。 PDF、docx、xlsxなどが可能です。 –
さて、私はモーダルダイアログ内のiframeへの応答を解決することができると考えています。 – pleft