日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

在浏览器中直接打开PDF

發布時間:2024/1/18 HTML 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在浏览器中直接打开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代碼 ?
  • /** ?
  • ?*?下載Action ?
  • ?*?@return ?
  • ?*/ ??
  • public ?String?downloadKnowledge()? throws ?Exception{??
  • ????checkFormat(download);??
  • ????return ?SUCCESS;??
  • }??
  • ??
  • /** ?
  • ?*?檢查格式,文件后綴 ?
  • ?*?@param?fileName ?
  • ?*/ ??
  • 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設定???? ??
  • ????????????contentType?=?"application/vnd.ms-excel;charset=utf-8" ;??????
  • ????????????//?attachment表示網頁會出現保存、打開對話框???? ??
  • ????????????filename?=?"inline;?filename=" ?+?fileName;??????
  • ????????????break ;????????????????
  • ????????case ?xlsx:??
  • ????????????//?contentType設定???? ??
  • ????????????contentType?=?"application/vnd.ms-excel;charset=utf-8" ;??????
  • ????????????//?attachment表示網頁會出現保存、打開對話框???? ??
  • ????????????filename?=?"inline;?filename=" ?+?fileName;??????
  • ????????????break ;??
  • ????????case ?pdf:????
  • ????????????//?contentType設定???? ??
  • ????????????contentType?=?"application/pdf;charset=utf-8" ;??????
  • ????????????//?attachment表示網頁會出現保存、打開對話框???? ??
  • ????????????filename?=?"inline;?filename=" ?+?fileName;???
  • ????????????break ;??
  • ????????case ?doc:??
  • ????????????//?contentType設定???? ??
  • ????????????contentType?=?"application/msword;charset=utf-8" ;??????
  • ????????????//?attachment表示網頁會出現保存、打開對話框???? ??
  • ????????????filename?=?"inline;?filename=" ?+?fileName;??????
  • ????????????break ;????????????????
  • ????????case ?docx:??
  • ????????????//?contentType設定???? ??
  • ????????????contentType?=?"application/msword;charset=utf-8" ;??????
  • ????????????//?attachment表示網頁會出現保存、打開對話框???? ??
  • ????????????filename?=?"inline;?filename=" ?+?fileName;??????
  • ????????????break ;??
  • ????????case ?txt:??
  • ????????????//?contentType設定???? ??
  • ????????????contentType?=?"text/plain;charset=utf-8" ;??????
  • ????????????//?attachment表示網頁會出現保存、打開對話框???? ??
  • ????????????filename?=?"inline;?filename=" ?+?fileName;??????
  • ????????????break ;??
  • ????????default :??
  • ????????????//?contentType設定???? ??
  • ????????????contentType?=?"text/plain;charset=utf-8" ;??????
  • ????????????//?attachment表示網頁會出現保存、打開對話框???? ??
  • ????????????filename?=?"inline;?filename=" ?+?fileName;????
  • ????????????break ;??
  • ????}?????
  • }?
  • 總結

    以上是生活随笔為你收集整理的在浏览器中直接打开PDF的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。