1. 程式人生 > >Ueditor圖片上傳設定(1.4.3 JSP版本)

Ueditor圖片上傳設定(1.4.3 JSP版本)

最近研究了一下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);