posts - 14,  comments - 37,  trackbacks - 0
          File file = new File(servlet.getServletContext().getRealPath("/"
                                                   
          + File.separator 
                                                   
          + attachment.getStorePath()) ;

                              response.setContentType(
          "application/force-download") ;
                              response.setHeader(
          "Content-Disposition""attachment;filename=\""+new String(attachment.getAttachName().getBytes("gb2312"), "ISO8859-1")+"\"") ;//瀏覽器不管這些編碼,人家直接用iso8859-1給你顯示,所以,這里必須手工轉換編碼才可以,這個地方可以參考:http://tiandl88.blogchina.com/5367140.html  不知道是不是原創地址
                              
          //write to output stream
                              InputStream in = new FileInputStream(file) ;
                              ServletOutputStream out 
          = response.getOutputStream() ;
                              
          int byteLength = 0 ; 
                              
          byte[] buffer = new byte[8192] ;
                              
          while((byteLength = in.read(buffer, 08192)) != -1){
                                  out.write(buffer, 
          0, byteLength) ;
                              }

                              out.flush() ;
                              out.close() ;
                              in.close() ;
                          } 
          catch (Exception e) {
                              ActionErrors errors 
          = new ActionErrors() ;
                              errors.add(
          "downloadError"new ActionError("lx.error.UploadError.FileNotExists")) ;
                              saveErrors(request, errors) ;
                              ret 
          = mapping.findForward("error") ;
                          }

          可以參考的連接有
          http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2183&lngWId=2
          http://www.webdeveloper.com/forum/archive/index.php/t-78425.html
          posted on 2007-07-10 10:22 冰封的愛 閱讀(561) 評論(0)  編輯  收藏 所屬分類: J2EE
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿(3)

          隨筆檔案

          文章分類

          文章檔案

          相冊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 云龙县| 北辰区| 嘉善县| 清水县| 怀柔区| 类乌齐县| 喀喇| 通化县| 临朐县| 岢岚县| 洛阳市| 连南| 岚皋县| 长治市| 锡林浩特市| 黔西县| 左贡县| 内江市| 沂水县| 颍上县| 福清市| 平安县| 凌云县| 锦州市| 彰化市| 田阳县| 霍州市| 嘉禾县| 乡宁县| 南开区| 汕头市| 观塘区| 济阳县| 雅安市| 太原市| 抚松县| 西平县| 北海市| 新兴县| 建水县| 柳州市|