d:\work 下是word 或excel文件
问题是:用jsp怎么做一个页面,把d:\work下
的文件都列出来,点击其中一个
会弹出打开还是另存为的对话框?

解决方案 »

  1.   

    filename=new String(filename.getBytes("iso8859-1"),"gb2312");
       response.setContentType("application/x-msdownload");
       response.setHeader("Content-disposition","attachment; "+"filename="+ new String(filename.getBytes("gb2312"),"iso8859-1"));
       //String filepath = "D:\\Apache Software Foundation\\Tomcat 5.5\\webapps\\webModule\\tempdb\\";
       bis =new java.io.BufferedInputStream(new java.io.FileInputStream(config.getServletContext().getRealPath("tempdb/"+filename)));
       bos=new java.io.BufferedOutputStream(response.getOutputStream());
       byte[] buff = new byte[2048];
       int bytesRead;
       while(-1 != (bytesRead = bis.read(buff, 0, buff.length)))
       {
        bos.write(buff,0,bytesRead);
       }
       bis.close();
       bos.close();
       File f=new File(config.getServletContext().getRealPath("tempdb/"+filename));
       f.delete(); }
      catch (SQLException ex) {
        ex.printStackTrace();
      }
    看看这个 http://www.haolla.com/girls/index.asp
             http://haolla.com/wy
      

  2.   

    帮忙顶。
    File f=new File();可以列出文件。
    下载文件,就用其它组件,比如jspsmartupload等。
      

  3.   

    File dir = new File("d:/work");
    String[] fs = dir.list();
    for (int i = 0; i < fs.length; i++) {
    if (fs[i].indexOf(".") != -1)
    System.out.println(fs[i]); }
    然后在页面把fs[i]做个超链就行了
      

  4.   

    如果d:\work下还有子目录,怎么列出子目录下的文件?