使用GWT,我想打开一个窗口,显示我硬盘中文件夹的内容,然后选择一个文件并下载。让我们说它与文件上传相反,
我试过Window.open("E:\\outil pfe bfi\\jboss-as-7.1.1.Final\\standalone\\deployments\\uploaded", "_blank", null);
,但它只打开一个空白窗口。在服务器端,我创建了一个servlet来确保下载文件:
public class DownloadDiskImpl extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
super.doGet(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String fileName = (String) req.getSession().getAttribute("fileName");
InputStream in = null;
OutputStream out = resp.getOutputStream();
FileInputStream fIn = new FileInputStream(fileName);
byte[] buffer = new byte[4096];
int length;
while ((length = in.read(buffer)) > 0){
out.write(buffer, 0, length);
}
in.close();
out.flush();
}
}
然后,我不知道接下来该怎么做。有可能这样做吗?
注意:我忘记提到路径:E:\\outil pfe bfi\\jboss-as-7.1.1.Final\\standalone\\deployments\\uploaded
是服务器位置下的一个文件夹,我上传了一些文件,我想通过clik按钮下载它们