(JSP) A solution that cannot be opened on a mobile-phone (especially an apple-Mobile) PDF file

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.