action :
public class LoadBlobFileAction
    extends Action {
  public ActionForward execute(ActionMapping mapping, ActionForm actionForm,
                               HttpServletRequest request,
                               HttpServletResponse response) {
    String ID = request.getParameter("affixid");
    String name = request.getParameter("affixname");
    System.out.println(name);
    ProviderDAO dao = new ProviderDAO();
    FileInputStream fi = dao.downLoadFile(ID, name);
    StringBuffer buffer = new StringBuffer();
    try {      ServletOutputStream out = response.getOutputStream();
      response.setDateHeader("Expires", 0);
      response.setContentType("application/zip; charset=GBK");
//      name = new String(name.getBytes(), "8859_1");
      response.setHeader("Content-disposition", "attachment; filename=" + name);
      byte[] buff = new byte[4096];
      int bytesRead;
      while ( (bytesRead = fi.read(buff, 0, buff.length)) != -1) {
        out.write(buff, 0, bytesRead);
      }    }
    catch (IOException e) {
      e.printStackTrace();
    }
    return null;  }
}

解决方案 »

  1.   

    其中
    FileInputStream fi = dao.downLoadFile(ID, name);
    是获得数据库中的BLOB字段
    这个没问题!
      

  2.   

    别的问题还没看出来,只看到你的ServletOutputStream 没有关
      

  3.   

    下面是我以前写过的一部分  File file = new File(fileName);
                int filesize = (int) file.length();
                response.setContentLength(filesize);
                ServletOutputStream os = response.getOutputStream();
                FileInputStream in = new FileInputStream(fileName);            byte[] data = new byte[bufferSize];
                int temp = -1;
                while ( (temp = in.read(data)) != -1) {
                    os.write(data, 0, temp);
                    os.flush();
                }
                os.close();
                response.flushBuffer();
      

  4.   

    out.write之后最好还是out.flush()的好