首先 去官網那下載ueditor源碼 下載地址http://ueditor.baidu.com/website/download.html


下載完成之后 解壓 得到

可以參考ueditor文檔進行學習,文檔地址:http://fex.baidu.com/ueditor/#server-path
現在開始學習:環境 myeclipse10、tomcat7.0、win7
在myeclipse中創建 javaweb項目 項目名為 uedemo

在項目webroot下面創建ueditor文件夾,
然后打開utf8-jsp文件:所有的文件

拷貝到項目中的ueditor文件中,jsp文件夾中的lib文件夾中的jar包拷貝到項目web-inf文件中的lib文件夾中
再打開文件ueditor-1.4.3.3文件夾,找到jsp文件的src文件夾復制到項目中
完成這些之后,發現項目中有報錯,
第一步jsp中的錯誤消除:那是js驗證報錯,只需要取消js的驗證即可;
在報錯的文件上右擊選擇myeclipse在右邊選擇exclude from validation就可以了
第二步:類中的錯誤,打開報錯的類,刪除對應的錯誤的方法頭上的注解即可;
開始編輯頁面index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<title>ueditor demo</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="ueditor/lang/zh-cn/zh-cn.js"></script>
</head>
<!--主體 包含具體說明內容-->
<body>
<textarea id="myeditor" style="height:800px;"></textarea>
<script type="text/javascript">
var ue = UE.getEditor("myeditor");
</script>
</body>
</body>
</html>
然后在瀏覽器中訪問 http://localhost:9099/uedemo/

並出現ueditor編輯器 這時就可以進行編輯,但是上傳文件圖片還是失敗的
下面開始配置上傳:

找項目中的config.json文件打開,這個里面就是關於上傳的配置,里面注釋的很清楚,
我只需要配置自己需要的就好,其他的默認。
"imageUrlPrefix": "/uedemo", /* 圖片訪問路徑前綴 */
將此處的配置為自己的項目名稱即可,下面的其他imageUrlPrefix一樣,這樣再次訪問就可以上傳圖片了,
但是在在線圖管理哪一欄中圖片的回顯是失敗的,這個需要修改源代碼
修改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;
}
重啟即可完成,其他學習 ,請看ueditor文檔,菜鳥一枚,如有不妥,請包涵。
