0

There is a Tomcat web server, say WS1, on which I have all my servlets and HTML pages. A client of WS1 uploads a file on WS1. That file is then read, encrypted and stored on WS1 in some other folder.

What I have to do is send/transfer this encrypted file on some other machine, say machine A. Suppose client searches for the file he has stored, that file should be downloaded to WS1 from the machine A. WS1 will perform decryption and that decrypted file should be sent on the client.

I have completed upto the encryption part but got stuck with the file transfer. How can I achieve this?

4

1 に答える 1

1

ここで。「ファイルはマシン A から WS1 にダウンロードする必要があります」または b.「ファイルは Web サーバーからマシン A にダウンロードする必要があります」。

これは実際には、質問のタイトルと質問の本文と矛盾しています。

「b.」の場合 あなたが望むものです(おそらくそうあるべきです)、t

次に、Web サーバー WS1 からファイルをダウンロードするコードを記述する必要があります。

以下は、サーブレットを使用してファイルをダウンロードするための抜粋です。

String value = "attachment;filename=\"" + URLEncoder.encode(filename, "UTF-8") +'"';
response.setHeader("Content-Disposition", value);

OutputStream out = response.getOutputStream();
FileInputStream in = new FileInputStream(my_file);
byte[] buffer = new byte[4096];
int length;
while ((length = in.read(buffer)) > 0){
     // logic to decrypt the file
    out.write(buffer, 0, length);
}
in.close();
out.flush();

もちろん、適切な例外を処理する必要があります。

于 2012-04-24T10:58:46.147 に答える