posts - 3, comments - 15, trackbacks - 0, articles - 26
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          向客戶端寫入二進制流文件

          Posted on 2005-06-29 15:46 morcble的blog 閱讀(971) 評論(0)  編輯  收藏 所屬分類: Java

          <%@ page contentType="text/html; charset=gb2312"%>
          <%@ include file="/WEB-INF/jsp/includes.jsp" %>
          <%@ include file="/WEB-INF/jsp/header1.jsp" %>
          <%@ page import="java.sql.Blob,java.io.*,org.spring.lh.xiaolv.util.*,org.spring.lh.xiaolv.*,org.spring.lh.*,org.spring.lh.hibernate.*"%>
          <%!
          public static String getStr(String str){
                  try {String temp_p=str;
                      byte[] temp_t=temp_p.getBytes("ISO8859-1");
                      String temp=new String(temp_t);
                      return temp;
                  }
                  catch(Exception e){ }
                  return "";
              }
          %>
          <%
          Lhspring lhSpring=(Lhspring)request.getSession().getAttribute("lhspring");
          System.out.println(lhSpring.getfindc_info("ddd").toString());
          calendar a = lhSpring.loadcalendar(request.getParameter("uuid"));
          System.out.println(a);
          Blob blob = a.getAccessories();  

          String filename = a.getAccessories_name();
          String filename1=getStr(filename);
          String strFileExt = filename.substring(filename.lastIndexOf(".") + 1);
          String mine=request.getSession().getServletContext().getMimeType(filename);
          if(mine==null)
          mine="application/octet-stream";
          response.setContentType(mine);

          response.setHeader(
                   "Content-disposition",
                   "attachment;filename=\""+filename+"\"");
                 
          InputStream is= null;        
          OutputStream os= null;
            try {
                  is = blob.getBinaryStream();
                  ByteArrayOutputStream baos = new ByteArrayOutputStream();
                 
                  os = new BufferedOutputStream(response.getOutputStream());
                  byte[] buffer = new byte[4*1024];
                  int read = 0;
                 
                  while((read = is.read(buffer))!=-1){
                   baos.write(buffer,0,read);
                  }
                  os.write(baos.toByteArray());
            }
            catch(Exception e){
             System.out.println("讀取附件出錯");
            }
            finally{
             
              os.close();
              is.close();  
            }
            

          %>

          主站蜘蛛池模板: 名山县| 运城市| 桦川县| 石城县| 平阳县| 扶余县| 改则县| 大冶市| 天祝| 日喀则市| 巨野县| 晋城| 定南县| 佛冈县| 双鸭山市| 沂水县| 会同县| 当阳市| 黔江区| 昭觉县| 资兴市| 兴山县| 左权县| 英吉沙县| 江达县| 长宁县| 周宁县| 邮箱| 灵川县| 准格尔旗| 资阳市| 长丰县| 军事| 广水市| 旬阳县| 舟山市| 金沙县| 金秀| 阿拉善左旗| 南和县| 塔河县|