现在的位置: 首页 > 综合 > 正文

Ueditor图片上传设置(1.4.3 JSP版本) – 解决图片不能显示问题

2018年08月26日 ⁄ 综合 ⁄ 共 1236字 ⁄ 字号 评论关闭

转载:http://blog.csdn.net/pip123456/article/details/38120489

最近研究了一下Ueditor,发现图片上传功能不能直接使用,需要修改一些东西,记下来以备参考。

1. 修改com.baidu.ueditor.hunter.FileManager类下的一个方法,修改如下:

源代码

private String getPath ( File file ) {
String path = file.getAbsolutePath();
return path.replace( this.rootPath, "/" );
}

修改为:

private String getPath ( File file ) {
   String path = file.getAbsolutePath();
   String str=path.replace(this.rootPath.replaceAll("\\/", "\\\\"), "\\" );
   return str;
}

(此处如果不修改,会导致“在线管理”下的图片不能显示)

2. 修改image.js文件,有两处的图片地址设置有问题,这里导致的问题是上传的图片在编辑器中不能显示图片。

(1):需要自定义一个方法,获取当前项目的地址(方法比较笨,可自行修改)

function getRootPath(){
        //获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp
        var curWwwPath=window.document.location.href;
        var pathName=window.document.location.pathname;
        var pos=curWwwPath.indexOf(pathName);
        var localhostPaht=curWwwPath.substring(0,pos);
        var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
        return localhostPaht + projectName;
    }

(2)分别在以下两个地方添加刚才获取的项目地址

约775行:

src: getRootPath() + prefix + data.url,
_src: getRootPath() + prefix + data.url,

约912行

img.setAttribute('src', getRootPath() + urlPrefix + list[i].url + (list[i].url.indexOf('?') == -1 ? '?noCache=':'&noCache=') + (+new Date()).toString(36) );
 img.setAttribute('_src', getRootPath() + urlPrefix + list[i].url);

抱歉!评论已关闭.