java代码在页面实现展示pdf文件

public void findPdf() throws IOException{
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/pdf");
FileInputStream in = new FileInputStream(new File(“c:/测试.pdf”));
OutputStream out = response.getOutputStream();
byte[] b = new byte[512];
while ((in.read(b))!=-1) {
out.write(b);
}
out.flush();
in.close();
out.close();

}


经过测试,火狐和谷歌可以展示,会在整个页面显示,会将页面替换成整个pdf的视图页面

所以用function方法开个一个新的窗口

 function finPdf(){
window.open(url, "_blank","top=200,left=200,height=600,width=800,status=yes,toolbar=1,
menubar=no,location=no,scrollbars=yes");


你可能感兴趣的:(java)