歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> SSH2 struts2 FCKeditor在線編輯器實現

SSH2 struts2 FCKeditor在線編輯器實現

日期:2017/2/28 14:50:05   编辑:Linux教程
Ø 在線編輯器建議使用開源的FCKeditor,FCKeditor官方網站下載地址http://sourceforge.net/projects/fckeditor/files/

Ø 需要下載的是兩個文件夾:FCKeditor_2.6.6及fckeditor-java-2.4-bin。(此非最新版本版本)前者是解壓開後即fckeditor在線編輯器,後者為fckeditor應用在java上的核心包。

Ø 接下來開始安裝fckeditor,解壓FCKeditor_2.6.6後得到fckeditor文件夾。將該文件夾復制到項目的webroot目錄下。

Ø 然後通過在頁面中調用的方式實現fckeditor的使用。具體的調用方法有兩種:一、通過javascript調用(推薦)。首先在新建的jsp頁面的開頭部分聲明引入js標簽

<%String contextPath=request.getContextPath(); %>

<script type="text/javascript" src="<%=contextPath %>/fckeditor/fckeditor.js"></script>

以上的contextPath是為了解決相對路徑的問題,即站點的根路徑webroot

接下來在body部分應用script代碼。例如:

<s:form name="postform" action="saveDrafts.action" method="post">

<table width="100%">

<s:textfield name="personal_Notes.Title" label="題目(非空)"/>

<s:textarea name="personal_Notes.Neirong" rows="19" cols="97" label="內容"></s:textarea>

<s:select name="personal_Notes.ShareType" label="權限" list="#{'2':'僅自己可見','1':'公開'}"/>

<script type="text/javascript">

var oFCKeditor=new FCKeditor("personal_Notes.Neirong");

oFCKeditor.BasePath= "<%=contextPath %>/fckeditor/";

oFCKeditor.Height=300;

oFCKeditor.ToolbarSet="itcastbbs";

oFCKeditor.ReplaceTextarea();

</script>

<s:submit value="存草稿" method="savePersonal_Notes2"/>

<s:submit value="發表筆記" method="savePersonal_Notes"/>

</table>

</s:form>

在以上的打代碼中,通過script引用,新建一個fckeditor對象,並將它的內容賦值給textarea傳入到數據庫,注意,textarea的名字和fckeditor的對象的名字必須相同。oFCKeditor.BasePath即fckeditor文件夾裡面被調用內容的路徑。ToolbarSet屬性的值為工具欄的名字,可以自己新建一個工具欄調用。
Copyright © Linux教程網 All Rights Reserved