使用serlvet提供下載

          例子如下:
           pulic class CodeReturn extends HttpServlet{

              public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException , ServletException {
              response.setContentType("application/jar");
              ServletContext ctx=getServletContext();
              InputStream is=ctx.getResourceAsStream("/bookCode.jar") ;// Returns the resource located at
          the named path as an InputStream object.

              int read=0;
              byte[] bytes=new byte[1024];    
              OutputStream os=response.getOuputStream();// Returns a ServletOutputStream suitable for writing binary data in the response,Provides an output stream for sending binary data to the client. A ServletOutputStream object is normally retrieved via the ServletResponse.getOutputStream() method. 
           while((read=is.read(bytes)!=-1){
              os.write(bytes,0,read);
          }
              os.flush();
              os.close();
          }
          }

          posted on 2007-11-01 16:57 劉錚 閱讀(307) 評論(0)  編輯  收藏 所屬分類: JSP and Servlet

          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導航

          統計

          留言簿(1)

          文章分類(141)

          文章檔案(147)

          搜索

          最新評論

          主站蜘蛛池模板: 化德县| 兴山县| 武邑县| 崇礼县| 和硕县| 曲周县| 陆川县| 香河县| 壶关县| 乌兰察布市| 会理县| 新河县| 磐石市| 星子县| 台中市| 治多县| 西宁市| 江阴市| 晋宁县| 栖霞市| 金秀| 上虞市| 府谷县| 托克托县| 鹤壁市| 宜川县| 安新县| 原阳县| 古蔺县| 大同县| 桐庐县| 湘乡市| 分宜县| 马鞍山市| 象州县| 攀枝花市| 巴东县| 于都县| 温州市| 花莲县| 三都|