最好有源码。

解决方案 »

  1.   

    BufferedOutputStream bos = null;
                boolean downFlag = true;
                File file = new File(storeFilePath);
                String filename = file.getName();
                StringBuffer sb = new StringBuffer(50);
                sb.append("attachment;  filename=");
                sb.append(filename);
                if (filename != null) {
                  try {
                    httpServletResponse.setContentType(
                            "application/x-msdownload;charset=GB2312");
                            httpServletResponse.setHeader("Content-Disposition",
                            new String(sb.toString()
                            .getBytes(), "ISO8859-1"));
                        //String  tmp  =  "c:/"  +  filename;
                    FileInputStream fis = new FileInputStream(storeFilePath);
                    bos = new BufferedOutputStream(httpServletResponse.getOutputStream());
                    byte[] buffer = new byte[2048];
                    while (fis.read(buffer) != -1) {
                      bos.write(buffer);
                    }                bos.write(buffer, 0, buffer.length);                fis.close();
                    bos.close();
                  }
                  catch (IOException e1) { //点了“取消”按钮
                    downFlag = false;
                  }
                      //下载成功,更新下载次数!
                      //rs.close();
                  if (downFlag == true) {
                    stmt = conn.prepareStatement(updateDownTimesSql);
                    stmt.setInt(1, downLoadTimes + 1);
                    stmt.execute();              }
                }
      

  2.   

    可以尝试这样:
        用filter对下载文件的目录进行过滤,然后考虑看能不能分析出文件名,最后就是数据库操作!