ファイルのダウンロードを実装する必要があります。サーバー側のファイルの URL を直接ダウンロードする必要はありません。ファイルを開いて応答のストリームに書き込むサーブレットを作成しました。 、応答応答) 応答を受信すると呼び出されます。必要な操作は、ストリーム内のファイルをクライアント コンピューターにダウンロードすることです。
これに関して私を助けることができますか?
試しましたWindow.open(ServletUrl, "_parent", "location=no")
か?
そして、「application/exe」への応答でContentTypeを設定してみてください
これにより、ユーザーは保存または実行するように求められます。
サーブレット コード:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String filename = URLDecoder.decode(request.getPathInfo(), "UTF-8");
File file = new File("/path/to/files", filename);
response.setContentType("application/x-download");
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
response.setHeader("Content-Length", file.length());
BufferedInputStream input = null;
BufferedOutputStream output = null;
try {
input = new BufferedInputStream(new FileInputStream(file));
output = new BufferedOutputStream(response.getOutputStream());
byte[] buffer = new byte[8192];
for (int length = 0; (length = input.read(buffer)) > 0;) {
output.write(buffer, 0, length);
}
} finally {
if (output != null) try { output.close(); } catch (IOException ignore) {}
if (input != null) try { input.close(); } catch (IOException ignore) {}
}
}
_blank、_parent、_top、_self のいずれかを使用できます
GWT RPCとデータURIだけを使用して、サーブレットなしでこれを行うことができます。
Window.open
を渡すファイル保存ダイアログを開くために使用します。データURIの使用法を理解するには、このリファレンスを参照してください。