【发布时间】:2013-10-07 12:06:44
【问题描述】:
我已经完成了我的 pdf 视图,但现在我只想动态查看 pdf 文件弹出窗口而不是下载选项和保存选项,所以请在 java 中给出一些示例 我现在使用此代码
File f= new File(file);
if(f.exists()){
ServletOutputStream op= response.getOutputStream();
response.reset();
if(check==1){
response.setContentType("application/pdf");
}else{
response.setContentType(content);
}
// response.setHeader("Content-disposition","attachment; filename=" +fileName);
byte[] buf = new byte[4096];
int length;
DataInputStream in = new DataInputStream(new FileInputStream(f));
while ((in != null) && ((length = in.read(buf)) != -1)){
op.write(buf,0,length);
}
in.close();
op.flush();
op.close();
}
【问题讨论】:
-
我在这里回答了。我的 pdf 在不同的窗口中打开。 stackoverflow.com/questions/19591425/…