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

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

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

    葉落知秋

    一葉落而知天下秋

    統(tǒng)計(jì)

    留言簿(1)

    Java相關(guān)

    閱讀排行榜

    評(píng)論排行榜

    下載服務(wù)的Servlet


     發(fā)表時(shí)間: 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) 評(píng)論(0)  編輯  收藏


    只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲一级黄色视频| 亚洲人成无码网WWW| 亚洲精品无码专区在线播放| caoporn成人免费公开| 男女做羞羞的事视频免费观看无遮挡| 四虎影视在线永久免费看黄| 亚洲永久中文字幕在线| 91在线视频免费观看| 国产一区二区三区无码免费| 日韩av无码免费播放| 亚洲大尺度无码专区尤物| 无码毛片一区二区三区视频免费播放 | 韩国日本好看电影免费看| 亚洲精品美女在线观看| 国产色爽女小说免费看| 亚洲aⅴ天堂av天堂无码麻豆| 人禽杂交18禁网站免费| 国产精品高清视亚洲精品| 114级毛片免费观看| 久久精品亚洲中文字幕无码麻豆| 国产一级一毛免费黄片| 亚洲大成色www永久网站| 午夜男人一级毛片免费| 久久综合亚洲色hezyo| 中文字幕亚洲精品资源网| 国产91免费在线观看| 亚洲日本va一区二区三区| 亚洲av永久无码精品秋霞电影影院 | 一级毛片免费视频网站| 亚洲国产成人爱av在线播放| 免费精品国自产拍在线播放| www.亚洲精品| 色www永久免费| 午夜在线免费视频| 亚洲日韩av无码中文| 亚洲精品午夜久久久伊人| 国产亚洲一区二区在线观看| 99xxoo视频在线永久免费观看| 99人中文字幕亚洲区| 亚洲精品无码不卡在线播放HE | 无码乱人伦一区二区亚洲一|