You smiled and talked to me of nothing and I felt that for this I had been waiting long.

          The trees come up to my window like the yearning voice of the dumb earth.

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            19 Posts :: 10 Stories :: 25 Comments :: 0 Trackbacks
          最近在項目開發中,處理文件下載時,出現中文文件名亂碼的現象。以下是解決方法的小記。
          1.Action配置:
           1 <action name="downloadFile"
           2             class="com.xxx.xxx.web.action.common.LoadFileAsInputStreamAction"
           3             method="downloadFile">
           4             <result name="success" type="stream">
           5                 <param name="contentType">
           6                     application/octet-stream;charset=UTF-8
           7                 </param>
           8                 <param name="inputName">inputStream</param>
           9                 <param name="bufferSize">100000</param>
          10                 <param name="contentDisposition">
          11                     attachment;fileName="${fileName}"
          12                 </param>
          13             </result>
          14         </action>
          2.對fileName進行轉碼:
           1     private String convertUnicode(String name) {
           2         String filename = null;
           3         try { // 支持IE和FireFox
           4             filename = new String(name.getBytes("GBK"), "ISO-8859-1");
           5         } catch (UnsupportedEncodingException e) {
           6             // e.printStackTrace();
           7             LOG.error(" ### Convert FileName Error!");
           8         }
           9         return filename;
          10     }
          3.修改TOMCAT server.xml:
          增加URIEncoding="UTF-8"參數設置.
          版權聲明:轉載時請以超鏈接形式標明文章原始出處和作者信息及本聲明

          posted on 2008-06-11 09:37 鉤子 閱讀(2473) 評論(3)  編輯  收藏 所屬分類: opensources 、工作筆記

          Feedback

          # re: webwork-下載文件出現中文名稱亂碼的解決方法 2008-06-11 17:01 隔葉黃鶯
          我需要一種不用通過
          filename = new String(name.getBytes("GBK"), "ISO-8859-1");

          解決中文亂碼的辦法  回復  更多評論
            

          # re: webwork-下載文件出現中文名稱亂碼的解決方法 2008-06-11 18:40 鉤子
          @隔葉黃鶯
          嗯,我也不喜歡再做次轉換,但是目前還沒有找到更好的方法??障聛矸治鱿耊W的代碼看看,期望能找到更好的解決方案。  回復  更多評論
            

          # re: webwork-下載文件出現中文名稱亂碼的解決方法 2008-08-11 13:49 鉤子
          另,關于filename最好是用form post的形式提交,否則如果是在url后面帶參數的形式的話,會出現ie6下某些字體無法正確解析的現象。
          這里小注下。  回復  更多評論
            

          主站蜘蛛池模板: 永安市| 即墨市| 上饶市| 色达县| 通州市| 岳普湖县| 新郑市| 隆安县| 南宁市| 望奎县| 乐清市| 高安市| 衢州市| 汽车| 格尔木市| 永兴县| 东方市| 凤阳县| 涞源县| 那曲县| 广饶县| 鹿泉市| 苍溪县| 宁安市| 莫力| 阿拉善盟| 易门县| 海兴县| 长乐市| 桂平市| 浑源县| 来安县| 金堂县| 哈巴河县| 望奎县| 余干县| 招远市| 柘城县| 新津县| 平乐县| 许昌县|