<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Thinking

    快樂編程,開心生活
    posts - 21, comments - 27, trackbacks - 0, articles - -5
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    文件下載中的漢字編碼問題

    Posted on 2007-02-07 14:32 lixw 閱讀(250) 評論(0)  編輯  收藏
    ?1 public ? void ?doDownLoad(HttpServletRequest?request,?HttpServletResponse?response,?
    ?2 ????????????String?absolutePath)? {
    ?3 ????????
    ?4 ???????? // 設置響應頭信息
    ?5 ????????response.setContentType( " application/octet-stream;charset=UTF-8 " );?
    ?6 ????????log.debug( " GET:? " ? + ?absolutePath);
    ?7 ????????
    ?8 ????????String?str? = ?FilePathParseUtil.getFileNameByPath(absolutePath);
    ?9 ???????? // 調用自定義的編碼函數,解決不同瀏覽器上對漢字編碼的處理
    10 ????????str? = ? this .encodeFileName(request,?str) == null ? str: this .encodeFileName(request,?str);
    11 ???????? // 設置response頭信息,從而顯示正確的文件名,并彈出另存對話框
    12 ????????response.setHeader( " Content-Disposition " ,? " attachment;?filename= " ?
    13 ???????????????? + ?str);
    14 ????????OutputStream?out? = ? null ;
    15 ???????? try {
    16 ???????????? // 從response得到輸出流,從而向客戶端寫出文件
    17 ????????????out? = ?response.getOutputStream();
    18 ????????}
    catch (IOException?e) {
    19 ????????????log.error( " output?stream?is?null " );
    20 ????????????e.printStackTrace();
    21 ????????}

    22 ???????? this .doDownLoad(out,?absolutePath);
    23 ????}

    24 ????
    25 ???? /**
    26 ?????*?根據不同瀏覽器對文件名進行編碼
    27 ?????*? @param ?request?客戶端請求
    28 ?????*? @param ?fileName?文件名
    29 ?????*? @return ?編碼后的文件名
    30 ????? */

    31 ???? public ?String?encodeFileName(HttpServletRequest?request,?String?fileName) {???
    32 ????????String?agent? = ?request.getHeader( " USER-AGENT " );
    33 ???????? try {
    34 ???????????? if ?( null ? != ?agent? && ? - 1 ? != ?agent.indexOf( " MSIE " ))? {???
    35 ???????????????? return ?URLEncoder.encode(fileName,? " UTF-8 " );???
    36 ????????????}
    else ? if ?( null ? != ?agent? && ? - 1 ? != ?agent.indexOf( " Mozilla " ))? {???
    37 ???????????????? return ? " =?UTF-8?B? " +
    38 ???????????????????????? new ?String(
    39 ????????????????????????????????Base64.encodeBase64(
    40 ????????????????????????????????????fileName.getBytes( " UTF-8 " )
    41 ????????????????????????????????)
    42 ????????????????????????)? + ? " ?= " ;???
    43 ????????????}
    ? else ? {???
    44 ???????????????? return ?fileName;???
    45 ????????????}

    46 ????????}
    catch (UnsupportedEncodingException?e) {
    47 ???????????? return ? null ;
    48 ????????}

    49 ????}
    ??

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


    網站導航:
     
    主站蜘蛛池模板: 水蜜桃亚洲一二三四在线| 亚洲国产成人久久三区| 在线亚洲午夜理论AV大片| 综合自拍亚洲综合图不卡区| 亚洲日产乱码一二三区别| 一级视频免费观看| 91精品成人免费国产片| 又大又粗又爽a级毛片免费看| 亚洲AV日韩AV永久无码久久| 国产午夜不卡AV免费| 免费在线一级毛片| 午夜成人无码福利免费视频| 国产精品无码免费播放| 亚洲国产成人久久综合一 | 亚洲AⅤ视频一区二区三区 | 久久久久亚洲AV片无码下载蜜桃| 亚洲综合小说另类图片动图| 久久免费国产精品一区二区| 国产一区二区视频免费| 亚洲性色高清完整版在线观看| 中文字幕在线观看免费| 国产高清免费的视频| 亚洲区视频在线观看| 女人张开腿等男人桶免费视频| 亚洲综合一区二区国产精品| 最新黄色免费网站| 亚洲人成电影福利在线播放| 蜜臀98精品国产免费观看| 亚洲熟妇无码av另类vr影视| 高清在线亚洲精品国产二区| 中文字幕手机在线免费看电影| 综合自拍亚洲综合图不卡区| 成人免费视频软件网站| 亚洲精品456人成在线| 182tv免费观看在线视频| 久久亚洲国产最新网站| 亚洲高清国产拍精品青青草原| 欧美亚洲国产SUV| 四虎永久成人免费| 性xxxxx大片免费视频| 亚洲日本一区二区|