0

使用 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是我上传一些文件的服务器位置下的文件夹,我想通过单击按钮下载它们

4

0 回答 0