jsp页面:

  1. <a href=\'#\' onclick=onLine(\''+urls[i]+'\') >在线打开</a>

html页面超链接单击打开online函数

  1. var onLine = function(filename){
  2. var param="toolbar=yes,location=yes,menubar=yes,
  3. scrollbars=yes,resizable=yes";
  4. var path = "DocumentCabinetAction!openOnLine.action?
  5. filepath="+encodeURI(filename);
  6. window.open(path,'maxwindow',param);
  7. };

online函数:打开一个新的窗口,path为后台函数,直接输出流到页面,在线打开。这个函数不能异步提交。

  1. //type 为response 返回类型,filename 为要打开的文件名称
  2. if((filename.indexOf(".xls")>0) || (filename.indexOf(".xlsx")>0)){
  3. type = "application/vnd.ms-excel";
  4. }else if(filename.indexOf(".pdf")>0){
  5. type = "application/pdf";
  6. }else if((filename.indexOf(".doc")>0)  || (filename.indexOf(".docx")>0)){
  7. type = "application/msword";
  8. }else if(filename.indexOf(".txt")>0){
  9. type = "text/plain";
  10. }else if(filename.indexOf(".ppt") >0){
  11. type = "application/ppt";
  12. }
  13. //response设置返回内容type,outputStream输出
  14. response.setContentType(type);
  15. response.setHeader("Content-disposition","inline;filename="+URLEncoder.encode(filename, "utf-8"));
  16. //ftp读取文件,并放入到输出流中
  17. ftp.retrieveFile(new String(filename.getBytes("GBK"),"ISO-8859-1"), outputStream);
  18. outputStream.flush();
  19. outputStream.close();

注意点:一般下载、在线打开不要使用ajax提交,ajax提交会有问题,页面预览的时候第一次还是会弹出下载/打开对话框,第二次就正常显示了

在线打开的条件是:电脑中有相应的打开软件,不然在线显示不了,要想直接靠浏览器打开,要使用插件,比如dsoframer.ocx,这个插件只能打开word,excel ,代码如下:

  1. <div id="div1" style="width:100%;height:90%;">
  2. <OBJECT id="FramerControl1" codeBase="dsoframer.ocx" style="margin:0px;top:0px;height:700px;width:100%" classid="clsid:00460182-9E5E-11D5-B7C8-B8269041DD57">
  3. <PARAM NAME="_ExtentX" VALUE="16960">
  4. <PARAM NAME="_ExtentY" VALUE="13600">
  5. <PARAM NAME="BorderColor" VALUE="-2147483632">
  6. <PARAM NAME="BackColor" VALUE="-2147483643">
  7. <PARAM NAME="ForeColor" VALUE="-2147483640">
  8. <PARAM NAME="TitlebarColor" VALUE="-2147483635">
  9. <PARAM NAME="TitlebarTextColor" VALUE="-2147483634">
  10. <PARAM NAME="BorderStyle" VALUE="1">
  11. <PARAM NAME="Titlebar" VALUE="0">
  12. <PARAM NAME="Toolbars" VALUE="1">
  13. <PARAM NAME="Menubar" VALUE="0">
  14. </OBJECT>
  15. </div>
  1. //在线打开word,excel path 为全路径,
  2. getWord = function(path){
  3. if(path == null)
  4. {
  5. Ext.Msg.alert('提示', '要打开的文件路径不存在!');
  6. }else if((path.indexOf(".xls") >0) || (path.indexOf(".doc")>0) ){
  7. document.getElementById('FramerControl1').Open(path);
  8. document.getElementById('FramerControl1').ProtectDoc(1,2,"satellite");
  9. //显示修订留痕
  10. document.getElementById('FramerControl1').ShowRevisions(0);
  11. }else{
  12. Ext.Msg.alert('提示', '该格式的文件不能打开!');
  13. }
  14. };

最新文章

  1. Sql Server系列:系统函数
  2. Android 异步消息处理机制
  3. easyui-datagrid行数据field原样输出html标签
  4. SlidingMenu的简单使用
  5. Dynamic CRM 2013学习笔记(十五)报表设计:报表入门、开发工具及注意事项
  6. java动态代理汇总
  7. node.js JS对象和JSON字符串之间的转换
  8. Windows Server Backup 2008 R2 备份Hyper-V
  9. 通过Scrapy抓取QQ空间
  10. LintCode-Compare Strings
  11. jQuery中的经典动画
  12. OpenVPN多实例优化的思考过程
  13. win10 uwp 九幽图床
  14. 移动端300ms点击延迟
  15. [Swift]LeetCode745. 前缀和后缀搜索 | Prefix and Suffix Search
  16. 日常踩坑 — 相邻元素之间的margin合并问题。
  17. 21天打造分布式爬虫-Crawl类爬取小程序社区(八)
  18. eclipse 快捷键Open Implementation 直接退出
  19. Oracle修改监听端口教程
  20. IDEA中的替换功能(替换代码中的变量名很好用哦)

热门文章

  1. 利用java反射机制对方法进行调用
  2. C语言多维数组的地址
  3. 搬寝室(HDU 1421 DP)
  4. Memory Region
  5. eclipse安装github插件egit
  6. bzoj1753 [Usaco2005 qua]Who&#39;s in the Middle
  7. MySQL数据库配置主从服务器实现双机热备
  8. JS中简单的this学习
  9. 《Java程序员面试笔试宝典》之switch使用时有哪些注意事项
  10. struts——文件上传