Posted on 2005-06-29 15:46
morcble的blog 阅读(959)
评论(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();
}
%>