隨筆-11  評論-0  文章-2  trackbacks-0
          1. public void DownloadFileManager(String filename, String url)   
          2.             throws IOException {   
          3.         HttpServletResponse response = Struts2Utils.getResponse();   
          4.         HttpServletRequest request = Struts2Utils.getRequest();   
          5.         InputStream is = null;   
          6.         OutputStream os = null;   
          7.         try {   
          8.              String agent = (String)request.getHeader("USER-AGENT");     
          9.               if(agent != null && agent.indexOf("MSIE") == -1) {     
          10.               String enableFileName = "=?UTF-8?B?" + (new String (Base64.encodeBase64(filename.getBytes("UTF-8")))) + "?=";     
          11.               response.setHeader("Content-Disposition""attachment; filename=" + enableFileName);     
          12.               }else {     
          13.                // IE     
          14.              String enableFileName = new String(filename.getBytes("GBK"), "ISO-8859-1");     
          15.                response.setHeader("Content-Disposition""attachment; filename=" + enableFileName);     
          16.               }    
          17.   
          18.     /*       response.setHeader("Content-Disposition", "attachment;filename="  
          19.                     + new String(filename.getBytes("gbk"), "iso-8859-1")); */  
          20.             
          21.             
          22.             response.setContentType("application/x-msdownload");   
          23.             is = new FileInputStream(url);   
          24.             os = response.getOutputStream();   
          25.             byte[] buffer = new byte[21940];   
          26.             int length = 0;   
          27.             while ((length = is.read(buffer)) > 0) {   
          28.                 os.write(buffer, 0, length);   
          29.             }   
          30.   
          31.         } catch (Exception e) {   
          32.             e.printStackTrace();   
          33.         } finally {   
          34.             if (os != null) {   
          35.                 os.close();   
          36.             }   
          37.             if (is != null) {   
          38.                 is.close();   
          39.             }   
          40.         }   
          41.   
          42.     }
          posted on 2012-07-07 00:40 閱讀(861) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 正阳县| 康平县| 横峰县| 紫金县| 友谊县| 高台县| 随州市| 峡江县| 伽师县| 鸡泽县| 合肥市| 贡嘎县| 周口市| 永兴县| 伊川县| 安宁市| 长海县| 邢台县| 衡阳市| 黄山市| 白银市| 寻甸| 扎赉特旗| 定西市| 仁化县| 淮南市| 西昌市| 兰考县| 武功县| 商城县| 贺兰县| 伊春市| 丹江口市| 周口市| 横峰县| 广州市| 佳木斯市| 沽源县| 区。| 遂川县| 甘德县|