Ueditor 1.4.3 jsp utf-8版Bug修複

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   color   使用   sp   on   

最近發現Ueditor 1.4.3 jsp utf-8版,存在圖片上傳功能不能直接使用的Bug。在網上尋找有解決方案,但還是存在一定的問題。

方法一:

可參考:http://blog.sina.com.cn/s/blog_002e20310102vbz6.html

修改com.baidu.ueditor.hunter.FileManager類下的getPath方法,原始碼:

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

修改為:

 1     private String getPath ( File file ) { 2          3         String path = file.getAbsolutePath(); 4  5         String rootPath2 = this.rootPath;
//這裡的作用是給rootPath最後添加路徑分隔字元,而在後面替換時將整個路徑替換為"\",其實也可以不添加,但在後面替換的時候要替換成"".
//不然的話,最後出來的json資料中會以"//u/r/...",而導致多出http://u/r/...而無法拿到資料
6 if(!rootPath2.endsWith("\\/")){ 7 rootPath2+="/"; 8 } 9 String tempPath = rootPath2.replaceAll("\\/", "\\\\");10 String finalPath = path.replace(tempPath,"\\");11 return finalPath;12 13 }

這樣寫,可以顯示同一網站下的圖片。

雖然,這樣能解決問題,但總感覺不太對勁。後來仔細看代碼,原來在原始碼中,將rootPath的路徑轉了下導致後來的路徑分隔字元不一致而無法替換rootPath

在ConfigManager這個類中:

private ConfigManager ( String rootPath, String contextPath, String uri ) throws FileNotFoundException, IOException {                rootPath = rootPath.replace( "\\", "/" );

這在mac及linux下應該是沒有問題的,但在windows下會存在bug,故可以修改成:

private ConfigManager ( String rootPath, String contextPath, String uri ) throws FileNotFoundException, IOException {                //rootPath = rootPath.replace( "\\", "/" );        String fileSparator = System.getProperty("file.separator");
       //這裡的作用是給rootPath最後添加路徑分隔字元,而在後面替換時將整個路徑替換為"\"。
//不然的話,最後出來的json資料中會以"//u/r/...",而導致多出http://u/r/...而無法拿到資料
       if(!rootPath.endsWith(fileSparator)){ 
rootPath
+=fileSparator;
}

this.rootPath = rootPath;

只修改這一處地方,其他地方保持不變。返回結果為:

{"state": "SUCCESS","total": 60,"start": 0, list: [{"state": "SUCCESS","url": "/u/r/images/20141129/1417256636864029401.png"},{"state": "SUCCESS","url": "/u/r/images/jgsz.bmp"},{"state": "SUCCESS","url": "/u/r/images/nh/a.jpg"},{"state": "SUCCESS","url": "/u/r/images/nh/b.jpg"},{"state": "SUCCESS","url": "/u/r/images/nh/c.jpg"},{"state": "SUCCESS","url": "/u/r/images/nh/d.jpg"},{"state": "SUCCESS","url": "/u/r/images/nh/e.jpg"},{"state": "SUCCESS","url": "/u/r/images/nh/f.jpg"},{"state": "SUCCESS","url": "/u/r/images/nh/g.jpg"},{"state": "SUCCESS","url": "/u/r/images/nh/h.gif"},{"state": "SUCCESS","url": "/u/r/images/nh/i.jpg"},{"state": "SUCCESS","url": "/u/r/images/nh/j.jpg"},{"state": "SUCCESS","url": "/u/r/images/nh/k.jpg"},{"state": "SUCCESS","url": "/u/r/images/nh/l.jpg"},{"state": "SUCCESS","url": "/u/r/images/nh/m.jpg"},{"state": "SUCCESS","url": "/u/r/images/nh/n.jpg"},{"state": "SUCCESS","url": "/u/r/images/nh/o.jpg"},{"state": "SUCCESS","url": "/u/r/images/nh/p.jpg"},{"state": "SUCCESS","url": "/u/r/images/nh/_vti_cnf/a.jpg"},{"state": "SUCCESS","url": "/u/r/images/nh/_vti_cnf/b.jpg"} ]}

 

Ueditor 1.4.3 jsp utf-8版Bug修複

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.