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

    显示效果:
  • 相关阅读:
    python 遍历文件夹 文件
    Docker使用常见问题
    Docker基础技术:DeviceMapper
    更改Docker默认的images存储位置
    NAT方式,宿主机无法ping通虚拟机
    centos7使用问题总结
    VMWare虚拟机提供的桥接、nat和主机模式的区别
    css之'>'
    eclipse安装插件:
    腾讯后台开发面试总结,原创,吐血推荐!!
  • 原文地址:https://www.cnblogs.com/CESC4/p/8126232.html
Copyright © 2020-2023  润新知