隨筆-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)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 伽师县| 即墨市| 苏州市| 黄龙县| 桂林市| 三河市| 兴宁市| 灌云县| 泸定县| 正镶白旗| 六安市| 水富县| 昭觉县| 武隆县| 辰溪县| 奉新县| 丰县| 朝阳区| 伊宁市| 上思县| 绥化市| 通河县| 新竹市| 尼玛县| 九江市| 新竹县| 丹阳市| 磐石市| 台中县| 珲春市| 洛隆县| 北宁市| 临泽县| 广饶县| 徐闻县| 吉木乃县| 高唐县| 宾阳县| 革吉县| 都匀市| 家居|