UEditor 使用调试过程

最近醒目需要,需要对文本内容进行编辑。最后选择了UEditor,其中遇到了一些问题。记录一下。

1:首先去官网下载最新版本http://ueditor.baidu.com/website/download.html

我下载的是1.4.3.2JSP版本,如果需要调试的话可以一起把源码下载下来。

下载解压以后的目录结构如下:

把文件引入到自己的项目中,其中jsp文件夹下的lib中的jar包,根据自己的项目,选择适当的方式引入,引入后我的项目路径如下。

我把index.html转换为了jsp文件,是项目需要。


2:到此整个UEditor实际上已经可以使用了,但是我们的项目是web项目,路径会有问题,需要对UEditor的配置文件进行修改,其中修改的文件为ueditor.config.js

其中serverUrl: URL + "jsp/controller.jsp"的属性是服务器的请求地址,请求处理的代码在controller.jsp文件,如果上传图片不可以使用,在jsp上不好调试,我把jsp文件转换为

java版本的controller,serverUrl这个属性修改为修改后的请求路径。

@RequestMapping("jsp/ueditor/jsp/ueditorDispatch")
    public void ueditorDispatch(HttpServletRequest request,    HttpServletResponse response, String action) {
        try {
            request.setCharacterEncoding("utf-8");
            response.setHeader("Content-Type", "text/html");
                    
            String rootPath = request.getSession().getServletContext().getRealPath("/")+ "WEB-INF/";

            
            ActionEnter actionEnter = new ActionEnter(request, rootPath);
            String exec = actionEnter.exec();

            response.getWriter().write(exec);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


如果代码保存可以进行调试,调试代码如下:

/***
     * 测试代码,代码调试通过,编辑器可以使用。主要调试路径问题。
     */
    public void a(HttpServletRequest request, HttpServletResponse response,    String action) {
        try {
            String contextPath = request.getContextPath();
            String basePath = request.getScheme() + "://"
                    + request.getServerName() + ":" + request.getServerPort()
                    + contextPath;
            String rootPath = request.getSession().getServletContext()
                    .getRealPath("/")
                    + "WEB-INF/";
            rootPath = rootPath.substring(0, rootPath.length() - 1);

            String actionType = request.getParameter("action");
            System.out.println("rootPath = " + rootPath);
            System.out.println("actionType = " + actionType);
            System.out.println("uri = " + request.getRequestURI());
            System.out.println("contextPath = " + contextPath);
            String originalPath = rootPath.replace("\\", "/")
                    + request.getRequestURI().substring(contextPath.length());
            System.out.println("originalPath=" + originalPath);
            File file = new File(originalPath);

            if (!file.isAbsolute()) {
                file = new File(file.getAbsolutePath());
            }

            String parentPath = file.getParent();

            String ConfigPath = parentPath + File.separator + "config.json";

            String configContent = this.readFile(ConfigPath);

            request.setCharacterEncoding("utf-8");
            response.setHeader("Content-Type", "text/html");

            System.out.println(basePath);
            rootPath = rootPath.substring(0, rootPath.length() - 1);
            ActionEnter actionEnter = new ActionEnter(request, rootPath);
            String exec = actionEnter.exec();
            System.out.print(exec);
            response.getWriter().write(exec);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

如果以上调试代码能过,图片上传的功能就可以使用了,主要是路径的问题,这样可以根据自己项目的路径进行修改。


3:调试通过以后UEditor就可以使用了。


4:UEditor加载完成

$(function(){
        UE.getEditor('editor').ready(function() {
            
            alert("加载完成")。
        })

    });




  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值