使用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 劉錚 閱讀(313) 評論(0)  編輯  收藏 所屬分類: JSP and Servlet

          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導(dǎo)航

          統(tǒng)計

          留言簿(1)

          文章分類(141)

          文章檔案(147)

          搜索

          最新評論

          主站蜘蛛池模板: 黔东| 青川县| 台江县| 来宾市| 安岳县| 肥西县| 内乡县| 南部县| 邢台县| 驻马店市| 白银市| 乐清市| 滨海县| 都昌县| 宜兴市| 广德县| 巨野县| 栖霞市| 阿拉善右旗| 莱阳市| 兴和县| 五家渠市| 岑巩县| 抚顺县| 吴堡县| 安阳市| 库尔勒市| 宝兴县| 淳安县| 呈贡县| 盖州市| 浦北县| 滦平县| 河南省| 陆川县| 正宁县| 苗栗市| 崇礼县| 北宁市| 牙克石市| 武义县|