linuxcai 发表于 2013-04-18 20:26

java txt导出的问题

web工程,页面通过ajax请求调用action中的writeToTxt() ,控制台也没有抛异常,为什么不弹出下载框呢?

    public void writeToTxt()
    {
      HttpServletResponse response = ServletActionContext.getResponse();
      
      response.setContentType("application/octet-stream;charset=UTF-8");
      response.addHeader("Content-Disposition", "attachment;filename=aaa.txt");
      
      ServletOutputStream os = null;
      BufferedOutputStream bos = null;
      StringBuffer sb = new StringBuffer();
      String enter = "\r\n";
      
      try
      {
            os = response.getOutputStream();
            bos = new BufferedOutputStream(os);
            
            sb.append("abc");
            
            bos.write(sb.toString().getBytes("UTF-8"));
            bos.flush();
            bos.close();
            
      }
      catch (Exception e)
      {
            e.printStackTrace();
      }
    }
页: [1]
查看完整版本: java txt导出的问题