夢幻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 軒轅 閱讀(280) 評論(0)  編輯  收藏 所屬分類: java

          主站蜘蛛池模板: 桐梓县| 宁武县| 博野县| 崇信县| 开江县| 乳山市| 衡水市| 霍邱县| 南安市| 湖南省| 甘谷县| 赤城县| 全南县| 东山县| 六安市| 桐乡市| 乌拉特后旗| 龙门县| 江阴市| 富川| 从化市| 宜都市| 大名县| 海口市| 鄂伦春自治旗| 民乐县| 濉溪县| 清新县| 淮南市| 桃源县| 和政县| 卫辉市| 安岳县| 大港区| 望江县| 新郑市| 鹤山市| 全州县| 色达县| 略阳县| 壶关县|