jsp解决kindeditor在线编辑器struts图片上传问题

1、下载

    官网下载ckeditor,解压后去掉不需要的部分,仅需保留plugin,lang,theme文件夹,这三个文件夹中用不到的东西可以删除, 比如lang文件下存放所有语言文件js,仅仅  保留en.js和zh_CN.js即可,保留jsp文件夹下的json_upload.jsp文件和 kindeditor.js文件即可,把jsp下面的jar导入

  

在线编辑器:http://kindeditor.net/
 

 

2、修改json_upload.jsp

  修改json_upload.jsp文件保存路径即可修改一下两句即可。

  //文件保存目录路径
  String savePath = pageContext.getServletContext().getRealPath("/upload");

  //文件保存目录URL,此处为绝对路径
  String saveUrl  = request.getContextPath()+"/upload";

 3、可选

  obj.put("url", request.getContextPath()+"/img/" + newFileName);//修改返回到编辑器显示的图片

4、在plugins/images/image.js修改

          uploadJson = K.undef(self.uploadJson, self.basePath + 'jsp/upload_json.jsp')

5、在plugins/filemanager/filemanager.js修改

        fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'jsp/file_manager_json.jsp'),

6、jsp中

  <link rel="stylesheet" href="<%=application.getContextPath() %>/themes/default/default.css" />
    <script charset="utf-8" src="<%=application.getContextPath() %>/js/kindeditor.js"></script>
    <script charset="utf-8" src="<%=application.getContextPath() %>/lang/zh_CN.js"></script>

  <script charset="utf-8" src="<%=application.getContextPath() %>/lang/zh_CN.js"></script>
              <script>
            var editor;
            KindEditor.ready(function(K) {
                editor = K.create('textarea[id="content"]', {
                    filterMode:false,
                    resizeType : 1,
                    allowPreviewEmoticons : true,
                    allowImageUpload : true,
                    items : [
                        'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                        'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                        'insertunorderedlist', '|', 'emoticons', 'image', 'link']
                    
                    });
                K('input[name=submit]').click(function(e) {
                    editor.value=editor.text();
                });
            });
        </script>

       <textarea  tabindex="4"  name="brand.content" id="content" style="width:80.2%"></textarea>

----------------------------struts----------------------------------------------------

1、struts直接<url-pattern>/*</url-pattern>会拦截了在线编辑器的url,所以需要进行下面的配置,这个只是解决那个问题的其中一种

2、自定义filter

public class KindeditorUrlFilter extends StrutsPrepareAndExecuteFilter {

    @Override
    public void doFilter(ServletRequest req, ServletResponse res,
            FilterChain chain) throws IOException, ServletException {
        
        HttpServletRequest request = (HttpServletRequest) req;    
           //不过滤的url    
           String url = request.getServletPath();  
           
           if ("/js/jsp/file_manager_json.jsp".equals(url)) {     
                
               chain.doFilter(req, res);    
           }else if("/js/jsp/upload_json.jsp".equals(url)){  
               chain.doFilter(req, res);  
           }else{    
               //System.out.println("使用默认的过滤器");    
               super.doFilter(req, res, chain);    
           }    
    }
}

3、web.xml配置filter

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>com.dan.action.KindeditorUrlFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

转载于:https://www.cnblogs.com/danmao/p/4190611.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
# KindEditor 变更记录# ver 3.4.3 * BUG: 修改了重复编辑超级链接时每次都添加&的问题。 * BUG: 修改了在IE上右键菜单没有复制、剪切项目的问题。 * BUG: 修改了在IE上没有格式化<font color=#000>代码的问题。 * BUG: 修改了PHP上程序日期格式不正确的问题。 * BUG: 修改了在IE上代码模式下全屏本地URL自动变成绝对URL的问题。 * BUG: 修改了在代码模式下KE.util.setFullHtml函数不显示HTML内容的问题。 * 改善: 弹出框未指定任何按钮(yesButton, noButton, previewButton)时,不显示底部DIV。 ver 3.4.2 (2010-04-04) * 增加: 添加了KE.util.isEmpty函数,用于判断编辑器是否有可见内容。 * 改善: 页面很小时弹出菜单的上下位置不变。 * 改善: 插入超级链接未选中内容时插入URL文本。 * 改善: 插入超级链接的打开类型为当前窗口时删除A标签的target属性。 * BUG: 修改了在IE上HTML属性值里输入JS代码时格式出现错误的问题。 * BUG: 修改了cssPath属性为空时加载首页的问题。 * BUG: 修改了当浏览器出现滚动条并拖动调整大小时控制不住的问题。 * BUG: 修改了embed代码丢失自定义属性的问题。 * BUG: 修改了在IE上切换到代码模式后点击图标触发onbeforeunload事件的问题。 * BUG: 修改了在Firefox上光标在图片旁边时点击鼠标右键,弹出右键菜单的问题。 * BUG: 修改了在Firefox上无法修改/删除图片的超级链接的问题。 * BUG: 修改了在Webkit上有时候无法添加/修改/删除图片的超级链接的问题
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值