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

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


    網站導航:
     
    主站蜘蛛池模板: 亚洲日本一线产区和二线产区对比| 亚洲精品无码专区| 一级成人毛片免费观看| 最好免费观看韩国+日本 | 亚洲国产成人久久一区久久| 又粗又硬又黄又爽的免费视频| 亚洲综合色一区二区三区| 免费在线看v网址| 久久精品国产亚洲精品| 日韩大片在线永久免费观看网站 | 日本免费的一级v一片| 亚洲av中文无码字幕色不卡| 精品少妇人妻AV免费久久洗澡| 亚洲精品无码少妇30P| 午夜高清免费在线观看| 老色鬼久久亚洲AV综合| 亚洲AV无码成人精品区狼人影院| 日本免费污片中国特一级| 亚洲AV无码国产丝袜在线观看| 日产久久强奸免费的看| 亚洲精品无码成人AAA片| 色欲国产麻豆一精品一AV一免费 | 美女被免费视频网站a国产| 免费一级毛片在线播放放视频| 怡红院亚洲怡红院首页| 亚洲狠狠婷婷综合久久| 亚洲麻豆精品国偷自产在线91| 成年女人A毛片免费视频| 亚洲天堂视频在线观看| 成人片黄网站A毛片免费| 特级毛片aaaa级毛片免费| 亚洲国产另类久久久精品黑人| 1a级毛片免费观看| 精品亚洲国产成人av| 女人18毛片水真多免费看| 香蕉97碰碰视频免费| 无码久久精品国产亚洲Av影片| 免费看黄的成人APP| 亚洲成人黄色网址| 免费v片视频在线观看视频| 99精品在线免费观看|