(JSP)關於手機端(尤其是蘋果手機)pdf文件無法打開的解決方案


流的方式下載附件

<!--
@author :daisy
@date : 2011-12-04
@note : 從數據庫中讀取BLOB圖片顯示
-->
<%@page import="com.cwai.dao.DBManager"%>
<%@ page contentType=" text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
  out.clear();
  out = pageContext.pushBody();
  //讀取blob字段的圖片內容,將其顯示
  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 {

      //修改前
      //response.setContentType("multipart/form-data");
      //修改后
      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");

      //注意:attachment \inline 兩者的區別
      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);
%>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM