生活随笔
收集整理的這篇文章主要介紹了
在浏览器中直接打开PDF
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
如何在瀏覽器中直接打開pdf/doc/excel文件
我在文件下載的部分 需要在具體文件名上加超鏈接 到可以直接在瀏覽器打開
另外下載時候 能不能也默認直接打開在瀏覽器 而不是顯示對話框
?
請做個類似功能的JE友給個幫助 謝謝先
在struts2 + spring + hibernate中
問題補充:
引用
response.setHeader("Content-Disposition", "inline"+ "; filename=/"" + encodedShowName+"/"");?
這個我試過 會跳出對話框放你選擇 是否打開或者保持
我想要的是直接打開在瀏覽器
謝謝
問題補充:
我是這么寫的
Xml代碼 ?
< action ? name = "downloadKnowledge" ? class = "knowledgeAction" ? method = "downloadKnowledge" > ?? ???? ??? ???????< param ? name = "inputPath" > /upload/ </ param > ??? ????????? ????< result ? name = "success" ? type = "stream" > ?? ????????< param ? name = "contentType" > ${contentType} </ param > ?? ????????< param ? name = "inputName" > targetFile </ param > ?? ????????< param ? name = "contentDisposition" > ${filename} </ param > ?? ????????< param ? name = "bufferSize" > 4096 </ param > ?? ????</ result > ?? </ action > ??
java代碼
Java代碼 ?
? ? ? ?? public ?String?downloadKnowledge()? throws ?Exception{?? ????checkFormat(download);?? ????return ?SUCCESS;?? }?? ?? ? ? ? ?? private ? void ?checkFormat(String?fileName){?? ?????? ????String[]?splitString?=?fileName.split("//." );?? ????int ?length?=?splitString.length;?? ????String?format?=?null ;?? ????if ?(length?>? 1 ){?? ????????format?=?splitString[length?-?1 ];?? ????}?? ?????? ????DataFormat?df?=?Enum.valueOf(DataFormat.class ,?format);?? ????switch ?(df){?? ????????case ?xls:?? ???????????? ?? ????????????contentType?=?"application/vnd.ms-excel;charset=utf-8" ;?????? ???????????? ?? ????????????filename?=?"inline;?filename=" ?+?fileName;?????? ????????????break ;???????????????? ????????case ?xlsx:?? ???????????? ?? ????????????contentType?=?"application/vnd.ms-excel;charset=utf-8" ;?????? ???????????? ?? ????????????filename?=?"inline;?filename=" ?+?fileName;?????? ????????????break ;?? ????????case ?pdf:???? ???????????? ?? ????????????contentType?=?"application/pdf;charset=utf-8" ;?????? ???????????? ?? ????????????filename?=?"inline;?filename=" ?+?fileName;??? ????????????break ;?? ????????case ?doc:?? ???????????? ?? ????????????contentType?=?"application/msword;charset=utf-8" ;?????? ???????????? ?? ????????????filename?=?"inline;?filename=" ?+?fileName;?????? ????????????break ;???????????????? ????????case ?docx:?? ???????????? ?? ????????????contentType?=?"application/msword;charset=utf-8" ;?????? ???????????? ?? ????????????filename?=?"inline;?filename=" ?+?fileName;?????? ????????????break ;?? ????????case ?txt:?? ???????????? ?? ????????????contentType?=?"text/plain;charset=utf-8" ;?????? ???????????? ?? ????????????filename?=?"inline;?filename=" ?+?fileName;?????? ????????????break ;?? ????????default :?? ???????????? ?? ????????????contentType?=?"text/plain;charset=utf-8" ;?????? ???????????? ?? ????????????filename?=?"inline;?filename=" ?+?fileName;???? ????????????break ;?? ????}????? }?
總結
以上是生活随笔為你收集整理的在浏览器中直接打开PDF的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。