標籤:style class java tar ext color
FCKeditor這個線上HTML編輯工具具說是一個不錯的東西,速度快而且穩定,而且還是開源的。以前我一直在寫ASP代碼,所以都是用的國產的eWebEditor。現在寫JSP代碼,所以就用到FCKeditor了。網上很多文章介紹它都是ASP程式的,現在我把它如何加入JSP的方法,寫出來
先去下載一個FCKeditor,我下的是2.3版。再下一個FCKeditor.java 2.3 (FCKeditot for java) 這個檔案就是用來讓它支援JSP的。這裡面還有一個東西,要下,就是xalan.jar。為什麼要下呢,後面我們就知道了。xalan.jar的下載不太好找,xml.apache.org這個是它的網站,可以下一個。
好了,現在我們開始設定,先到tomcat->webapps裡建立一個檔案夾叫mysite。把FCKeditor裡的/editor和fckconfig.js, fckeditor.js, fckstyles.xml, fcktemplates.xml四個檔案copymysite檔案夾裡,因為別的檔案對我們來說沒有什麼意義,還佔用空間。再把FCKeditor.java 2.3中的web目錄下的WEB-INF目錄copy到mysite下(裡面有commons-fileupload.jar, FCKeditor-2.3.jar,web.xml等幾個檔案), 把其中的src目錄下的FCKeditor.tld檔案copy到mysite/WEB-INF/下.這樣它才支援JSP。
下面我們就要對其中的一些檔案進行修改,不然不好用:
開啟fckconfig.js 檔案
修改 FCKConfig.DefaultLanguage = ‘zh-cn‘ ;
把FCKConfig.LinkBrowserURL等的值替換成以下內容:
FCKConfig.LinkBrowserURL =
FCKConfig.BasePath + "filemanager/browser/default/browser.html?Connector=connectors/jsp/connector" ;
FCKConfig.ImageBrowserURL =
FCKConfig.BasePath + "filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connector" ;
FCKConfig.FlashBrowserURL =
FCKConfig.BasePath + "filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/jsp/connector" ;
FCKConfig.LinkUploadURL = FCKConfig.BasePath + ‘filemanager/upload/simpleuploader?Type=File‘ ;
FCKConfig.FlashUploadURL = FCKConfig.BasePath + ‘filemanager/upload/simpleuploader?Type=Flash‘ ;
FCKConfig.ImageUploadURL = FCKConfig.BasePath + ‘filemanager/upload/simpleuploader?Type=Image‘ ;
開啟WEB-INF下面的web.xml檔案:
把SimpleUploader中的配置屬性enabled定義為true(開啟檔案上傳功能)
添加標籤定義:
<taglib>
<taglib-uri>/mysite</taglib-uri>
<taglib-location>/WEB-INF/FCKeditor.tld</taglib-location>
</taglib>
這樣檔案就設定完了。
這時建立一個檔案試試。建立一個叫aaa.jsp的檔案
在裡面寫上
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" import="java.util.*" import="java.text.*" errorPage="" %>
<%@ page language="java" import="com.fredck.FCKeditor.*" %>
<%@ taglib uri="/mysite" prefix="FCK" %>
<script type="text/javascript" src="/mysite/fckeditor.js"></script>
<form method="POST" action="Bs_Bulletin_save.jsp">
<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="19%" bgcolor="#F0F0F0" height="25" align="right">
標題:
</td>
<td width="81%" bgcolor="#F0F0F0"><INPUT TYPE="text" NAME="title" size="58"></td>
</tr>
<tr>
<td width="19%" height="300" bgcolor="#F0F0F0"> <div align="center">中文資訊設定<BR><BR>
<span style="color: #FF0000">支援html(圖片大小寬度不要超過170個象素)</span></div></td>
<td width="81%" bgcolor="#F0F0F0">
<textarea name="content" cols="58" rows="15"></textarea>
<script type="text/javascript">
var oFCKeditor = new FCKeditor(‘content‘) ;
oFCKeditor.BasePath = "/mysite/" ;
oFCKeditor.Height = 400;
oFCKeditor.ToolbarSet = "Default" ;
oFCKeditor.ReplaceTextarea();
</script>
</td>
</tr>
<tr>
<td width="19%" height="25" bgcolor="#F0F0F0">發布時間:</td>
<td width="81%" bgcolor="#F0F0F0"><INPUT TYPE="text" NAME="datatimes" value="<%=time%>" size="58"></td>
</tr>
<tr>
<td colspan="2" bgcolor="#F0F0F0">
<div align="center"><input type="submit" value=" 添 加 " name="cmdok"> <input type="reset" value=" 重 寫 " name="cmdcancel"></div></td>
</tr>
</table>
</form>
加紅字的部分,就是調用這個線上編輯器了。現在我們可以試一下。
怎麼樣,很好用吧。上傳的圖看一下,哦,不好用,提示internal server error 500,這是為什麼呢,
還記得一開始時,我們提到的xalan.jar嗎,現在就要用到它了,很方便。你把xalan.jar放到lib檔案夾裡,關掉tomcat再重起一下,怎麼樣,好用了。呵呵。。。。。。。。。。