jsp代码:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ include file="/pages/common/getPath.jsp" %> <%@ page import="com.daorigin.common.dto.SessionDto" %> <% SessionDto sessionDto=(SessionDto) request.getSession().getAttribute("sessionDto"); String filePath = request.getParameter("filePath"); String fileType = request.getParameter("fileType"); %> <!DOCTYPE html> <html lang="zh-CN"> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <link rel="stylesheet" type="text/css" href="<%=path%>/public/css/smelp.css"> <link type="text/css" rel="stylesheet" href="<%=path%>/public/bootstrap32/css/bootstrap.min.css" /> <link type="text/css" rel="stylesheet" href="<%=path%>/public/temp/font-awesome.min.css" /> <link type="text/css" rel="stylesheet" href="<%=path%>/public/temp/main2.css" /> <script type="text/javascript" src="<%=path%>/public/js/officeOnline.js"></script> <script type="text/javascript" src="<%=path%>/public/js/jquery-1.9.1.min.js"></script> <script type="text/javascript"> $(function(){ var height = window.innerHeight-47; $("#oframe").attr("height",height+"px"); }) function openWord(){ var filePath = '<%=filePath%>'; var webUrl = "<%=basePath%>/common/file/getWord.do?filePath="+filePath; OpenWebWord(webUrl); ToggleMenubar(); ToggleRibbonBar(); ToggleMenubar(); ToggleShowRevisions(true); SetUserName('<%=sessionDto.getUserName()%>'); } function saveToWeb(){ var filePath = '<%=filePath%>'; document.getElementById("oframe").HttpInit(); document.getElementById('oframe').HttpAddPostString("filePath",filePath); document.getElementById("oframe").HttpAddPostCurrFile("FileData",""); document.getElementById("oframe").HttpPost("<%=basePath%>/common/file/saveToWeb.do"); alert("保存成功!"); } function isIE() { //ie? if (!!window.ActiveXObject || "ActiveXObject" in window) return true; else return false; } function isSupportOfficeOnline(){ var filePath = '<%=filePath%>'; var fileType = '<%=fileType%>'; if(filePath == ''){ window.location.href="<%=basePath%>/contInfo/anlysisError.do?errorType=2"; }else if(fileType != ".docx"){ window.location.href="<%=basePath%>/contInfo/anlysisError.do?filePath="+filePath+"&errorType=1"; }else{ if(isIE()){ openWord(); }else{ window.location.href="<%=basePath%>/contInfo/anlysisError.do?filePath="+filePath+"&errorType=0"; } } } </script> </head> <body onload="InitEvent();isSupportOfficeOnline();" style="background-color: #ffffff;"> <input type="hidden" name="filePath" id="filePath" value="${commonFile.filePath}"> <div> <table width="100%"> <tr> <td> <input type="button" onclick="saveToWeb()" name="保存" class="btn btn-info btn-sm" style="margin-top: 20px;float:right" value="保存"> <object classid="clsid:00460182-9E5E-11d5-B7C8-B8269041DD57" id="oframe" width="100%" height="100%" codebase="dsoFramer.CAB#version=2,2,1,2"> <param name="BorderStyle" value="1" /> <param name="TitlebarColor" value="52479" /> <param name="TitlebarTextColor" value="0" /> <param name="Menubar" value="0" /> <param name="Titlebar" value="0" /> <param name="Menubar" value="0" /> </object> <div style="display: none"> <!-- dsoframe事件 开始 --> <script type="text/javascript" language="jscript" for="oframe" event="OnDocumentOpened(str,obj)"> OnDocumentOpened(str, obj); </script> <script type="text/javascript" language="jscript" for="oframe" event="OnDocumentClosed()"> OnDocumentClosed(); </script> <!-- dsoframe事件 结束 --> </div> </td> </tr> </table> </div> </body> </html>
后台代码:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38@RequestMapping(value = "/getWord.do") public void getWord(String filePath,HttpServletRequest request, HttpServletResponse response) { String upload_path = ConfigManager.getConfigValue("upload_path"); String path = upload_path + "\" + filePath; File file = new File(path); response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "no-cache"); response.setHeader("Content-type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); response.setHeader("Content-Disposition", "attachment;filename=" + "asdas1.docx"); response.setDateHeader("Expires", 0); FileInputStream fis = null; OutputStream os = null; try { fis = new FileInputStream(file); os = response.getOutputStream(); int count = 0; byte[] buffer = new byte[1024 * 8]; while ((count = fis.read(buffer)) != -1) { os.write(buffer, 0, count); os.flush(); } } catch (Exception e) { e.printStackTrace(); } finally { try { fis.close(); os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34@RequestMapping(value = "/saveToWeb.do") public void saveToWeb(HttpServletRequest request,HttpServletResponse response) throws Exception { String flag = "0"; String filePath = ""; FileItemFactory dfif = new DiskFileItemFactory(); ServletFileUpload servletfileupload = new ServletFileUpload(dfif); try{ List fileItems = servletfileupload.parseRequest(request); // 依次处理请求 Iterator iter = fileItems.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) { // 如果item是正常的表单域 String name = item.getFieldName(); String value = item.getString("UTF-8"); if(name.equals("filePath")){ filePath=value;//附件标题赋值 } } else { //获取文件实体 String upload_path = ConfigManager.getConfigValue("upload_path"); File savefile = new File(upload_path + "\" + filePath); item.write(savefile); } } flag = "0"; }catch (Exception e) { flag = "1"; } response.setHeader("Content-type","text/html;charset=UTF-8");//向浏览器发送一个响应头,设置浏览器的解码方式为UTF-8 OutputStream stream = response.getOutputStream(); stream.write(flag.getBytes("UTF-8")); }
最后
以上就是丰富薯片最近收集整理的关于dsoframer在线编辑(读取保存服务器文档)的全部内容,更多相关dsoframer在线编辑(读取保存服务器文档)内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复