下载时如何在不保存或另存为选项的情况下以视图格式获取 pdf 文件。任何人都可以帮助我解决这种情况并提供示例代码。这是我的下载和保存格式的代码。
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();
}