//下载公文附件
public ActionForward download(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

DocumentActionForm daf = (DocumentActionForm)form;
//通过id,从数据库中将document对象查询出来
Document document = documentManager.findDocument(daf.getId());

response.reset();//别掉了这句
response.setContentType("application/x-download;charset=GBK");
response.setHeader("Content-Disposition", "attachment;filename=temp.doc");
                //上面两句是http协议所必需的,其中,filename=temp.doc是显示的文件名,若是中文,得通过getBytes进行转码。
//下面就是很基础的io操作了,就不再说了
response.getOutputStream().write(document.getContent());

response.getOutputStream().flush();
response.getOutputStream().close();

//指示struts,不要对返回值进行处理
return null;
}

解决方案 »

  1.   


    response.setContentType("application/类型"); 
    response.setHeader("Content-disposition", "attachment; filename="你的文件名称"); 
    response.flushBuffer(); 
    this.writer = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "编码格式")); 
    this.writer.println("输出下载内容"); 
    .....
    this.writer.close(); 
      

  2.   

    http://blog.csdn.net/xiaomaha/archive/2008/03/29/2227168.aspx
      

  3.   

    response.setContentType("application/x-download;charset=GBK");
    response.setHeader("Content-Disposition", "attachment;filename=temp.doc");
    关键是这个吧~~~~设置http的响应方式
      

  4.   

    good good study, day day up.
      

  5.   

    response.setContentType("application/x-download;charset=GBK"); 
    response.setHeader("Content-Disposition", "attachment;filename=temp.doc"); 
    其实把文件做成连接,就可以提示下载的,不用专门弄个下载程序