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',
    });
    }

    显示效果:
  • 相关阅读:
    linux格式化新硬盘并挂载,设置开机自动挂载
    各大名企的笔试面试题
    web2.0 Color
    选调生面试题
    网站流量概要分析
    css下拉菜单演示
    子查询
    技巧
    CMM与软件生命周期
    学习方法之PHP
  • 原文地址:https://www.cnblogs.com/CESC4/p/8126232.html
Copyright © 2011-2022 走看看