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 下载文件。

这是使用 Servlet 下载文件的摘录。

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 回答