坑多的Ueditor富编辑器
第一步:修改serverUrl: window.BASEPATH + "notice/word"
第二部:添加依赖包
<dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.17</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.13</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>ooxml-schemas</artifactId> <version>1.1</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>openxml4j</artifactId> <version>1.0-beta</version> </dependency> <dependency> <groupId>fr.opensagres.xdocreport</groupId> <artifactId>org.apache.poi.xwpf.converter.xhtml</artifactId> <version>1.0.6</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-scratchpad</artifactId> <version>3.13</version> </dependency> <dependency> <groupId>org.jsoup</groupId> <artifactId>jsoup</artifactId> <version>1.8.3</version> </dependency> <dependency> <groupId>net.sourceforge.cssparser</groupId> <artifactId>cssparser</artifactId> <version>0.9.25</version> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.3</version> </dependency> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20160810</version> </dependency> <!-- emf转png --> <dependency> <groupId>org.freehep</groupId> <artifactId>freehep-graphicsio</artifactId> <version>2.3</version> </dependency> <dependency> <groupId>org.freehep</groupId> <artifactId>freehep-graphicsio-emf</artifactId> <version>2.3</version> </dependency> <!-- wmf转svg --> <dependency> <groupId>net.arnx</groupId> <artifactId>wmf2svg</artifactId> <version>0.9.5</version> </dependency> <!-- svg转jpg --><!-- 缺少 batik-all-1.7.jar--> <dependency> <groupId>xml-apis</groupId> <artifactId>xml-apis-ext</artifactId> <version>1.3.04</version> </dependency> <dependency> <groupId>com.gitee.qdbp.thirdparty</groupId> <artifactId>ueditor</artifactId> <version>1.4.3.3</version> </dependency>
第三部:写controller
@RequestMapping(value = "word") public void word(HttpServletRequest request,HttpServletResponse response) throws Exception{ String rootPath = request.getSession() .getServletContext().getRealPath("/"); boolean isMultipart = ServletFileUpload.isMultipartContent(request); FileItem fileItem = null; if (isMultipart) { DiskFileItemFactory factory = new DiskFileItemFactory(1024 * 1024 * 20, null); ServletFileUpload uploader = new ServletFileUpload(factory); uploader.setHeaderEncoding("UTF-8"); uploader.setSizeMax(1024 * 1024 * 20); List<FileItem> fileItems = uploader.parseRequest(request); for (FileItem item : fileItems) { if (!item.isFormField()) { fileItem = item; } } } try { String exec = new ActionEnter(request, rootPath, fileItem).exec(); PrintWriter writer = response.getWriter(); writer.write(exec); writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); } }
<textarea id="container" name = "container" type="text/plain" style="width: 1200px;"></textarea> <!-- 配置文件 --> <script type="text/javascript" src="js/ueditor/ueditor.config.js"></script> <!-- 编辑器源码文件 --> <script type="text/javascript" src="js/ueditor/ueditor.all.js"></script> <script type="text/javascript" src="js/ueditor/lang/zh-cn/zh-cn.js"></script>
var ue = UE.getEditor('container',{ toolbars: [ ['undo', 'redo','importword','print','cleardoc'] ], initialFrameWidth : 690, }); ue.ready(function() { ue.setHeight(300); ue.setContent(''); })
二次加载ueditor
UE.delEditor('container'); var ue = UE.getEditor('container',{ toolbars: [ ['undo', 'redo','importword','print','cleardoc'] ], initialFrameWidth : 690, }); ue.ready(function() { ue.setHeight(300); ue.setContent(''); ue.setContent(dgmcfjData); })
//ueditor.all.js UE.plugin.register('importword', function (){ domUtils.on(input, 'change', function(){ me.execCommand('cleardoc');//清空内容 //var message = document.getElementById('edui1_message_holder'); //替换为 var message = document.getElementById(me.ui.id + '_message_holder'); }) })