Stream the way to download attachments
<!--
@author:d Aisy
@date: 2011-12-04
@note: Read the Blob picture display from the database
-
<% @page import= "Com.cwai.dao.DBManager"%>
<%@ page contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%>
<%
Out.clear ();
out = Pagecontext.pushbody ();
Reads the picture contents of a BLOB field and displays it
String XH = Request.getparameter ("XH");
String WJM = Request.getparameter ("WJM");
WJM = Java.net.URLEncoder.encode (WJM, "UTF-8");
try {
Servletoutputstream SOS = null;
String sql = "Select Wjnr wjnr from fj_swyb WHERE XH = '" + xh+ "'";
SYSTEM.OUT.PRINTLN (SQL);
byte[] Blob_array = DBMANAGER.GETBLOB (sql, NULL);
try {
Before modification
Response.setcontenttype ("Multipart/form-data");
After modification
Response.setcontenttype ("Multipart/form-data");
String kzm = wjm.substring (Wjm.lastindexof (".") +1);
if ("PDF". Equals (Kzm.touppercase ())) {
Response.setcontenttype ("Application/pdf");
}
String downfilename = new String (Wjm.getbytes ("GB2312"), "iso8859-1");
Note: Attachment \inline The difference between the two
Response.setheader ("Content-disposition", "attachment;filename=\", "+downfilename+" \ "");
SOS = Response.getoutputstream ();
System.out.println ("Blob_array-lenth:----" + blob_array.length);
Sos.write (Blob_array);
Sos.flush ();
Sos.close ();
} catch (Exception e) {
E.printstacktrace ();
} finally {
if (SOS! = null) sos.close ();
}
Return
} catch (Exception ex) {
Ex.printstacktrace ();
}
Response.senderror (404);
%>
(JSP) A solution that cannot be opened on a mobile-phone (especially an apple-Mobile) PDF file