JSP專案中使用ueditor(百度編輯器)
JSP專案中使用ueditor
2. 在Web Project專案的WebRoot目錄下新增thirdparts目錄,然後將ueditor新增到thirdparts目錄中。
3. 將ueditor_utf8目錄下的jsp/lib目錄中的jar包拷貝到專案的lib目錄。
4. 修改ueditor.config.js檔案,新增如下程式碼
window.UEDITOR_HOME_URL ="/thirdparts/ueditor_utf8/";
5. 在JSP頁面中匯入ueditor相關的js檔案
<script type="text/javascript" charset="utf-8" src="<%= request.getContextPath() %>/thirdparts/ueditor_utf8/ueditor.config.js"></script> <script type="text/javascript" charset="utf-8" src="<%= request.getContextPath() %>/thirdparts/ueditor_utf8/ueditor.all.min.js"> </script> <!--建議手動加在語言,避免在ie下有時因為載入語言失敗導致編輯器載入失敗--> <!--這裡載入的語言檔案會覆蓋你在配置專案裡新增的語言型別,比如你在配置專案裡配置的是英文,這裡載入的中文,那最後就是中文--> <script type="text/javascript" charset="utf-8" src="<%= request.getContextPath() %>/thirdparts/ueditor_utf8/lang/zh-cn/zh-cn.js"></script> |
6. 在需要顯示ueditor的頁面位置(注意id和name兩個屬性),新增如下程式碼:
<script id="editor" name="details" type="text/plain" style="width:900px;height:400px;"></script> <script type="text/javascript"> var ue = UE.getEditor('editor'); </script> |
7. 在伺服器端如何獲取ueditor中的html字串
使用request.getParameter(“script標記的name屬性值”);
在ueditor中上傳圖片
1. 修改ueditor_utf8/jsp/config.json檔案
imageUrlPrefix
imageManagerUrlPrefix
上述配置項的值,應該為javaweb的專案名稱。
如果需要上傳附件,那麼還應該修改fileUrlPrefix為javaweb專案名稱。
2. 因為ueditor官方給的jar存在bug,所以在顯示已經上傳的圖片時,會存在無法顯示的問題,可以通過修改原始碼解決。
FileManager.java中的getPath方法,修改完畢後重新生成jar包檔案。
//String path = file.getAbsolutePath(); String path = PathFormat.format(file.getAbsolutePath()); |