夢幻e家人

          java咖啡
          隨筆 - 15, 文章 - 0, 評論 - 11, 引用 - 0
          數據加載中……

          jsp頁面下載程序

          <%@page contentType="text/html;charset=GBK"%>
          <%@ page import="java.io.*" %>
          <%@ page import="java.net.*" %>
          <%@ page import="java.lang.*" %>
          <%
              
          // 檢查用戶權限:
              
          // 
          String userid = (String) request.getParameter("userid");
          System.out.println(
          "userid======"+userid);
          String sortid 
          = (String) request.getParameter("sortid");
          System.out.println(
          "sortid======"+sortid);
          String workspaceid 
          = (String) request.getParameter("workspaceid");
          System.out.println(
          "workspaceid======"+workspaceid);
          String id 
          = (String) request.getParameter("id");
          System.out.println(
          "id======"+id);
          String name 
          = (String) request.getParameter("name");
          System.out.println(
          "name======"+name);

              name
          =response.encodeURL(new String(name.getBytes(),"GBK"));
              System.out.println(
          "name======"+name);
          String path 
          =  "d:/" + request.getContextPath()+"//" + userid + "//"   + workspaceid  + "//" + sortid + "//" + id + name ;

          //消除輸出流錯誤的代碼
              out.clear();
              out = pageContext.pushBody();

              
          //File file = new File("d:\\1.txt");
              File file = new File(path);
             
          try 
                  

                      name
          =response.encodeURL(new String(name.getBytes(),"iso-8859-1"));
                      response.reset(); 
                      response.setContentType(
          "APPLICATION/OCTET-STREAM"); 
                      response.setHeader(
          "Content-Disposition""attachment; filename=" + name); 
                      ServletOutputStream output 
          = response.getOutputStream(); 
                      FileInputStream inStream 
          = new FileInputStream(file); 
                      
                      
          //循環取出流中的數據 
                      byte[] b = new byte[1024]; 
                      
          int len; 
                      
          while((len=inStream.read(b , 0 , b.length)) >0{
                          output.write(b,
          0,len);                 
                      }

                      output.close(); 
                      inStream.close(); 
                  }
           catch(Exception e) {}
          %>

          posted on 2007-08-01 15:22 軒轅 閱讀(276) 評論(0)  編輯  收藏 所屬分類: java

          主站蜘蛛池模板: 肃北| 临夏县| 崇明县| 邳州市| 新河县| 潍坊市| 枣庄市| 鄂州市| 西充县| 江川县| 神木县| 南充市| 进贤县| 克山县| 五峰| 开远市| 防城港市| 怀集县| 黄骅市| 迭部县| 高密市| 澳门| 皮山县| 临潭县| 舞钢市| 延安市| 九寨沟县| 昌黎县| 汝南县| 子洲县| 丹凤县| 岚皋县| 泾川县| 西和县| 巴马| 同德县| 宝兴县| 天全县| 枝江市| 高邮市| 股票|