<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 ????}
    ??

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


    網站導航:
     
    主站蜘蛛池模板: 成人免费无码视频在线网站| 日本亚洲免费无线码| 亚洲精品视频免费观看| 天天天欲色欲色WWW免费| 亚洲人成网站看在线播放| 亚洲乱码无人区卡1卡2卡3| 在线播放免费播放av片| 亚洲人成色777777精品| 免费无码成人AV片在线在线播放| 成人亚洲国产va天堂| 国产免费资源高清小视频在线观看| 亚洲国产精品无码第一区二区三区 | 国产又长又粗又爽免费视频| 亚洲精品无码永久在线观看你懂的| 久久精品无码免费不卡| 国产成人免费爽爽爽视频| 中文有码亚洲制服av片| 国产精品四虎在线观看免费| 狠狠热精品免费观看| 免费观看的毛片大全| 亚洲AV综合色区无码一二三区| 内射无码专区久久亚洲| 亚洲一级视频在线观看| 国产黄在线播放免费观看| 国产AV无码专区亚洲Av| av无码免费一区二区三区| 亚洲高清乱码午夜电影网| 亚洲国产午夜福利在线播放| 暖暖免费日本在线中文| 亚洲中文字幕伊人久久无码| 久久99毛片免费观看不卡| 久久精品国产精品亚洲艾草网美妙| 在线观看免费视频网站色| 亚洲精品不卡视频| 18国产精品白浆在线观看免费| 亚洲av日韩综合一区久热| 四虎影视永久免费视频观看| 国产无遮挡无码视频免费软件 | 91成人免费观看网站| 午夜亚洲乱码伦小说区69堂| 久久久久亚洲AV无码专区首|