我想在弹出窗口中在浏览器中显示PDF文件

时间:2016-07-04 06:44:48

标签: java jsp pdf

我想在存储在服务器上的浏览器中显示pdf,我试过这个但是全屏显示pdf。请帮我 的java:

    response.setContentType("APPLICATION/OCTET-STREAM");
    // use inline for view the content in browser, helpful for
    // pdf file
    response.setContentType("application/pdf");
    response.setHeader("Content-Disposition","inline; filename=\"" + filename + "\"");
    FileInputStream fileInputStream = new FileInputStream(filepath+filename);

    int i=0;
while ((i = fileInputStream.read()) != -1) {
        out.write(i);
    }

    fileInputStream.close();
    out.close();    
    }
    catch (Exception e) {       
    }   
}

JSP:

<input type="submit" value="View PDF" name="submitbutton" class="btn btn-danger btn-sm" />

1 个答案:

答案 0 :(得分:0)

如果PDF是文件系统上的文件,则可以使用Desktop.open()的默认PDF查看器打开它。