Eclipse或Myeclipse中搭建KindEditor环境并测试

转载:http://blog.csdn.net/lhq13400526230/article/details/9256301

      

    最近在学习KindEditor,按照官方手册在Eclipse中搭建KindEditor的环境时出现了问题,后来解决了,在我的博客里写出来希望对其他的人有帮助。

最后实现的效果应该是这样的:

(1)可以输入文字,可以上传文件,可以上传照片。



(2)点击提交以后是跳转显示页面,显示出刚才的文字,图片,并可以下载文档




实现步骤


1、在KindEditor的官方网站下载http://www.kindsoft.net/ 下载插件。我使用的是KindEditor-4.1.7


2、解压下载的KindEditor,因为我是用Java编程,所以可以删除asp、asp.net、php、examples文件夹。


3、创建一个JavaEE工程,将目录kindeditor-4.1.7\jsp\lib下面的三个Jar包json_simple-1.1.jar、commons-io-1.4.jar、commons-fileupload-1.2.1.jar


4、如图所示,在src下面的webapp复制粘贴刚才解压的kindeditor-4.1.7,有的Eclipse会报错有的Eclipse不会报错,原因是因为里面的JavaScript的书写规范不符合要求,但是不会影响到程序的正常运行。


除去报错的方法。在项目的物理路径下面找到文件 .project,用记事本打开,或者用UE打开。找到下面一段代码并删除。接着将Eclipse关闭,并重新打开。然后此时找到报错的文件,全选-->剪切-->保存-->粘贴-->保存

[html]  view plain  copy
  1. <buildCommand>  
  2.     <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>  
  3.     <arguments>  
  4.     </arguments>  
  5. </buildCommand>  

[html]  view plain  copy
  1. <nature>org.eclipse.wst.jsdt.core.jsNature</nature>  

5、在目录src\main\webapp\kindeditor-4.1.7\jsp下找到文件demo.jsp。将demo.jsp赋值粘贴到src\main\webapp\下面方便测试。并将demo.jsp的代码进行修改。

[html]  view plain  copy
  1. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>  
  2. <%  
  3. request.setCharacterEncoding("UTF-8");  
  4. String htmlData = request.getParameter("content1") != null ? request.getParameter("content1") : "";  
  5. %>  
  6. <!doctype html>  
  7. <html>  
  8. <head>  
  9.     <meta charset="utf-8" />  
  10.     <title>KindEditor JSP</title>  
  11.     <link rel="stylesheet" href="kindeditor-4.1.7/themes/default/default.css" />  
  12.     <link rel="stylesheet" href="kindeditor-4.1.7/plugins/code/prettify.css" />  
  13.     <script charset="utf-8" src="kindeditor-4.1.7/kindeditor.js"></script>  
  14.     <script charset="utf-8" src="kindeditor-4.1.7/lang/zh_CN.js"></script>  
  15.     <script charset="utf-8" src="kindeditor-4.1.7/plugins/code/prettify.js"></script>  
  16.     <script>  
  17.         KindEditor.ready(function(K) {  
  18.             var editor1 = K.create('textarea[name="content1"]', {  
  19.                 cssPath : 'kindeditor-4.1.7/plugins/code/prettify.css',  
  20.                 uploadJson : 'kindeditor-4.1.7/jsp/upload_json.jsp',  
  21.                 fileManagerJson : 'kindeditor-4.1.7/jsp/file_manager_json.jsp',  
  22.                 allowFileManager : true,  
  23.                 afterCreate : function() {  
  24.                     var self = this;  
  25.                     K.ctrl(document, 13, function() {  
  26.                         self.sync();  
  27.                         document.forms['example'].submit();  
  28.                     });  
  29.                     K.ctrl(self.edit.doc, 13, function() {  
  30.                         self.sync();  
  31.                         document.forms['example'].submit();  
  32.                     });  
  33.                 }  
  34.             });  
  35.             prettyPrint();  
  36.         });  
  37.     </script>  
  38. </head>  
  39. <body>  
  40.     <form name="example" method="post" action="show.jsp">  
  41.         <textarea name="content1" cols="100" rows="8" style="width:700px;height:200px;visibility:hidden;"><%=htmlspecialchars(htmlData)%></textarea>  
  42.         <br />  
  43.         <input type="submit" name="button" value="提交内容" /> (提交快捷键: Ctrl + Enter)  
  44.     </form>  
  45. </body>  
  46. </html>  
  47. <%!  
  48. private String htmlspecialchars(String str) {  
  49.     str = str.replaceAll("&", "&");  
  50.     str = str.replaceAll("<", "<");  
  51.     str = str.replaceAll(">", ">");  
  52.     str = str.replaceAll("\"", """);  
  53.     return str;  
  54. }  
  55. %>  

6、再建立起一个显示页面show.jsp

[html]  view plain  copy
  1. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>  
  2. <%  
  3. request.setCharacterEncoding("UTF-8");  
  4. String htmlData = request.getParameter("content1") != null ? request.getParameter("content1") : "";  
  5. %>  
  6. <!doctype html>  
  7. <html>  
  8. <head>  
  9.     <meta charset="utf-8" />  
  10.     <title>KindEditor JSP</title>  
  11. </head>  
  12. <body>  
  13.     <%=htmlData%>  
  14. </body>  
  15. </html>  

7、修改src\main\webapp\kindeditor-4.1.7\jsp目录下的 upload_json.jsp和file_manager_json.jsp文件中一段代码


String saveUrl  = request.getContextPath() + "attached/"; 给成

String saveUrl  = request.getContextPath() + "/attached/";多加一个斜杠


8、并在webapp下面创建文件夹attached


9、启动工程,输入网址:localhost:8080/kindeditor/demo.jsp 进行测试


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值