0

我有一个要求,用户将在页面中看到文件列表,该列表是目录中的列表。从那里他们将选择多个文件,然后单击查看按钮。然后我们需要从 Drive 中读取相应的文件,并需要打开所有用户选择的所有文件。我需要使用 Struts2/servlet 来实现它。

4

2 回答 2

0

从我的用户立场来看,用户会看到位于服务器上的目录的内容,对吧?

此外,您会显示文件列表以及用户用来选择文件然后单击查看按钮的一些选择方法(复选框?)。

如果我是正确的,您可以使用 javascript 打开一个新的选项卡/窗口或对话框(例如 jQuery 对话框),它从服务器读取文件或其内容。只需遍历列表中选定的条目,并将它们一一传递给打开选项卡/窗口/对话框的 JavaScript 函数。

于 2013-07-24T14:30:27.443 回答
0

It is not clear if you do want to

  1. open each file in the client's browser, or
  2. download each file to the client's file system, or
  3. download an archive containing all the files to the client's file system;

In 1. or 2. you need to create multiple requests, targeting multiple windows, using target="_blank", or by AJAX, etc .

By manipulating HttpResponse Header objects, you can instruct the browser when to open or download a file: Content-Disposition: inline; will try to open it inside the browser, while Content-Disposition: attachment; will perform the default operation (open with default desktop application, download, or ask if none of the previous was marked as default by the user)

Keep in mind that you may encounter several possible problems by opening or downloading multiple files at once; it could overload/crash the client, overload/crash the server, cause problem of bandwidth etc; what if the user choose 100 files ? You would open 100 tab, or 100 windows, or ask 100 times where to save each file, etc...

If you want to create a dynamic ZIP instead, you can find a kick-off example on how to do it in Struts2 here, (using an Action like a Servlet, and returning NONE); My files were from database, yours are from file system, but the code is the same.

于 2013-07-24T15:28:49.057 回答