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

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

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

    葉落知秋

    一葉落而知天下秋

    統計

    留言簿(1)

    Java相關

    閱讀排行榜

    評論排行榜

    下載服務的Servlet


     發表時間: 2007年11月07日 



    java 代碼
    1. import java.io.File;   
    2. import java.io.FileInputStream;   
    3. import java.io.IOException;   
    4. import java.io.OutputStream;   
    5.   
    6. import javax.servlet.ServletException;   
    7. import javax.servlet.http.HttpServlet;   
    8. import javax.servlet.http.HttpServletRequest;   
    9. import javax.servlet.http.HttpServletResponse;   
    10.   
    11. import org.apache.log4j.Logger;   
    12.   
    13.   
    14.   
    15. public class DownloadRscFileServlet extends HttpServlet {   
    16.     private Logger log = Logger.getLogger(this.getClass());   
    17.        
    18.     /**  
    19.      * Constructor of the object.  
    20.      */  
    21.     public DownloadRscFileServlet() {   
    22.         super();   
    23.     }   
    24.   
    25.     /**  
    26.      * Destruction of the servlet. <br>  
    27.      */  
    28.     public void destroy() {   
    29.         super.destroy(); // Just puts "destroy" string in log   
    30.         // Put your code here   
    31.     }   
    32.   
    33.     /**  
    34.      * The doGet method of the servlet. <br>  
    35.      *   
    36.      * This method is called when a form has its tag value method equals to get.  
    37.      *   
    38.      * @param request the request send by the client to the server  
    39.      * @param response the response send by the server to the client  
    40.      * @throws ServletException if an error occurred  
    41.      * @throws IOException if an error occurred  
    42.      */  
    43.     public void doGet(HttpServletRequest request, HttpServletResponse response)   
    44.             throws ServletException, IOException {   
    45.         String rscFileName = request.getParameter("rscFileName");   
    46.     
    47.         if(rscFileName == null || rscFileName.equals("")){   
    48.             log.debug(   
    49.                 "Invaild request:can not get type from request!");   
    50.             return;   
    51.         }   
    52.         String path = "d:/upload";   
    53.         //String rscFileName = SMPConfig.getValue("");   
    54.         File rscFile = new File(path+"/"  + rscFileName);   
    55.         if(!rscFile.exists()){   
    56.             log.debug(   
    57.                 "In DownloadRscFileServlet..... RscFile does not exist! RscFileName:" +   
    58.                 rscFileName + " FileName:" + rscFile.getAbsolutePath());   
    59.             response.getWriter().println(rscFileName + " does not exist!");   
    60.             return;   
    61.         }   
    62.         response.setHeader("Content-disposition","attachment; filename=" + rscFile.getName());   
    63.         response.setContentType("application/x-msdownload");   
    64.         OutputStream out = response.getOutputStream();   
    65.         FileInputStream in = new FileInputStream(rscFile);   
    66.         int i = -1;   
    67.         while((i = in.read()) != -1){   
    68.             out.write(i);   
    69.         }   
    70.         in.close();   
    71.         out.close();           
    72.            
    73.     }   
    74.        
    75.     /**  
    76.      * The doGet method of the servlet. <br>  
    77.      *   
    78.      * This method is called when a form has its tag value method equals to get.  
    79.      *   
    80.      * @param request the request send by the client to the server  
    81.      * @param response the response send by the server to the client  
    82.      * @throws ServletException if an error occurred  
    83.      * @throws IOException if an error occurred  
    84.      */  
    85.     public void doPost(HttpServletRequest request, HttpServletResponse response)   
    86.             throws ServletException, IOException {   
    87.         doGet(request,response);   
    88.     }       
    89. }  

    posted on 2007-11-07 17:22 飛雪連天 閱讀(141) 評論(0)  編輯  收藏


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


    網站導航:
     
    主站蜘蛛池模板: 国产亚洲漂亮白嫩美女在线| 亚洲欧洲日产国码www| 自拍偷自拍亚洲精品播放| 2021免费日韩视频网| 亚洲高清无在码在线无弹窗| 免费网站看av片| 亚洲A∨无码一区二区三区| 韩国免费A级毛片久久| 国产亚洲综合成人91精品| 东北美女野外bbwbbw免费 | 国产成人综合亚洲一区| 国产午夜影视大全免费观看| 免费人成网站永久| 伊人久久大香线蕉亚洲五月天| 香蕉免费看一区二区三区| 亚洲爆乳精品无码一区二区三区| 十八禁在线观看视频播放免费| 亚洲AV无码专区国产乱码4SE| 免费的全黄一级录像带| 亚洲色欲www综合网| 成年男女免费视频网站| 免费一级特黄特色大片| 亚洲人成人一区二区三区| 最近2019年免费中文字幕高清| 亚洲国产成人久久三区| 国产成人免费片在线视频观看| 免费夜色污私人影院网站电影| 国产日产亚洲系列| 久久久久久精品成人免费图片| 亚洲AV日韩综合一区尤物| 亚洲精品黄色视频在线观看免费资源 | 亚洲高清在线视频| 国产啪精品视频网免费| 免费精品视频在线| 香蕉蕉亚亚洲aav综合| 精品国产麻豆免费网站| 最好免费观看高清在线| 亚洲欧美综合精品成人导航| 亚洲熟女少妇一区二区| 毛片在线免费视频| 一级片在线免费看|