0

i want view pdf file just view dynamically in pop up window using java.while i clicking that file link open a pdf file pop up window its don't allow down load option please help me give some example in java.i need need java code with using action to jsp

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();
}
4

1 回答 1

0

要打开本地文件,您需要在 URL 中使用文件方案

由于您的路径是 Windows 路径 E:/files/IT/cat1/cat1Notification.pdf,因此链接的 href 需要在您的 jsp 的 <%=path%> 变量之前添加 file:///,以便浏览器知道它需要在用户机器上打开一个本地文件。

所以你的链接应该是这样的

">单击此处在您的浏览器中将解析为 file:///E:/​​files/IT/cat1/cat1Notification.pdf

如果没有文件方案,浏览器会假定您的链接是相对于网页的,并尝试通过向您的 webapp 发出请求来解析链接。

于 2013-10-07T04:39:15.667 回答