zoukankan      html  css  js  c++  java
  • 【JSP】如何在jsp中打开pdf文件。


    // java代码
    public ActionForward getSoaPdf(ActionMapping mapping, ActionForm form,

    HttpServletRequest request, HttpServletResponse response) throws IOException {

    String path = request.getParameter("path");
    if (IsPdf(path)) {
    response.setContentType("application/pdf");
    } else {
    response.setContentType("application/vnd.ms-excel");
    }
    ServletOutputStream out = null;
    try {
    out = response.getOutputStream();
    } catch (IOException e) {
    e.printStackTrace();
    }
    //加上下面这句则可以在浏览器外打开,或者保存
    //resp.setHeader("Content-disposition", "attachment;filename=sample.pdf");

    File pdf = null;
    BufferedInputStream buf = null;
    try {
    pdf = new File("G:\Soa_Pdf\" + path);
    response.setContentLength((int) pdf.length());
    FileInputStream input = new FileInputStream(pdf);
    buf = new BufferedInputStream(input);
    int readBytes = 0;
    while ((readBytes = buf.read()) != -1) {
    out.write(readBytes);
    }
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    if (out != null) out.close();
    if (buf != null) buf.close();
    }
    return null;
    }
    // js代码
    function openDetailPdf(path, cnTitle, enTitle) {
    art.dialog.open('operatorquery.do?method=getSoaPdf&path=' + path, {
    title: cnTitle + " " + enTitle,
    1100,
    // height: 450,
    height: 580,
    left: '133px',
    top: '10px',
    fixed: true,
    resize: false,
    padding: '5px 5px',
    });
    }

    显示效果:
  • 相关阅读:
    Moya 浅析
    Swift: Alamofire -> http请求 & ObjectMapper -> 解析JSON
    ReactiveCocoa 用法实例
    RACSignal的Subscription深入
    idea 不能编译生成class文件
    idea 右下角不显示git分支
    SSO单点登录的研究
    JVM内存模型简介
    Spring事务处理
    RabbitMQ
  • 原文地址:https://www.cnblogs.com/CESC4/p/8126232.html
Copyright © 2011-2022 走看看