網上有許多關于FCKeditor支持jsp的配置,但自己還是要總結一下。
IDE:MyEclipse6.5
框架:Struts2+spring+hibernate
步驟:
1. 在fckeditor的官方網站http://ckeditor.com/download下載FCKeditor_2.5.1.zip和FCKeditor-2.3.zip(for java),版本不同內容不同
2. 在MyEclipse中新建web項目,我的叫做wsjx
3. 解壓縮兩個文件,把FCKeditor_2.5.1.zip解壓出來的fckeditor文件夾放在WebRoot目錄下,把FCKeditor-2.3.zip(for java)解壓出來的web下的WEB-INF下的lib目錄中的commons-fileupload.jar和FCKeditor-2.3.jar兩個jar包拷到項目的lib目錄下,把FCKeditor-2.3.zip(for java)解壓出來的src目錄下的FCKeditor.tld拷貝到項目的WEB-INF下
4. 修改fckeditor文件夾下的fckeditor.js,找到FCKeditor.BasePath 并附值FCKeditor.BasePath = '/wsjx/fckeditor/'
5. 修改fckeditor文件夾下的fckconfig.js,找到并作如下修改
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.ImageUploadURL = FCKConfig.BasePath + 'filemanager/upload/simpleuploader?Type=Image' ;
FCKConfig.FlashUploadURL = FCKConfig.BasePath + 'filemanager/upload/simpleuploader?Type=Flash' ;
不好意思,這部分的修改沒有搞明白什么原因
6. 修改web.xml,加入:
web.xml

<servlet>
<servlet-name>Connector</servlet-name>
<servlet-class>
com.fredck.FCKeditor.connector.ConnectorServlet
</servlet-class>
<init-param>
<param-name>baseDir</param-name>
<param-value>/UserFiles/</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>SimpleUploader</servlet-name>
<servlet-class>
com.fredck.FCKeditor.uploader.SimpleUploaderServlet
</servlet-class>
<init-param>
<param-name>baseDir</param-name>
<param-value>/UserFiles/</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>enabled</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>AllowedExtensionsFile</param-name>
<param-value></param-value>
</init-param>
<init-param>
<param-name>DeniedExtensionsFile</param-name>
<param-value>
php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cgi
</param-value>
</init-param>
<init-param>
<param-name>AllowedExtensionsImage</param-name>
<param-value>jpg|gif|jpeg|png|bmp</param-value>
</init-param>
<init-param>
<param-name>DeniedExtensionsImage</param-name>
<param-value></param-value>
</init-param>
<init-param>
<param-name>AllowedExtensionsFlash</param-name>
<param-value>swf|fla</param-value>
</init-param>
<init-param>
<param-name>DeniedExtensionsFlash</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>Connector</servlet-name>
<url-pattern>
/fckeditor/editor/filemanager/browser/default/connectors/jsp/connector
</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>SimpleUploader</servlet-name>
<url-pattern>
/fckeditor/editor/filemanager/upload/simpleuploader
</url-pattern>
</servlet-mapping>7. 現在開始編寫頁面:有兩個頁面,一個是提交頁面(addContent.jsp),一個是顯示頁面(showContent.jsp)
addContent.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<%@ taglib uri="/WEB-INF/FCKeditor.tld" prefix="fck"%>
<html>
<head>
<title>FCKeditor</title>
</head>

<body>
<form action="showContent.jsp" method="post">
<table align="center">

<tr>
<td></td>
</tr>
<tr>
<td>
<fck:editor id="content" basePath="/wsjx/fckeditor/" width="1000"
height="500" skinPath="/wsjx/fckeditor/editor/skins/office2003/"
toolbarSet="Default">
</fck:editor>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Submit">
</td>
</tr>
</table>

</form>

</body>
</html>

showConten.jsp:這個相對簡單
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<html>
<head>

<title>顯示頁面</title>

</head>

<body>
<%=request.getParameter("content")%>
</body>
</html>現在部署到tomcat中,瀏覽,提交,看效果
這還沒有完,因為可能會出現幾種錯誤:
1. 當你上傳圖片時,提示“沒有權限”,在控制臺會輸出“找不到Image文件夾”,那么在UserFiles里新建Image文件夾,即可
2. 當傳輸文字包括中文時,可能會出現顯示亂碼的問題,那么把showContent.jsp中的<%=request.getParameter("content")%>改成<%=new String(request.getParameter("content").getBytes("ISO-8859-1"),"utf-8")%> 即可
3. 當上傳中文名的圖片時,圖片名稱顯示亂碼,解決方式,在FCKeditor-2.3.zip(for java)解壓出來的文件夾下,找到ConnectorServlet.java和SimpleUploadServlet.java,分別在兩個文件中找到DiskFileUpload upload = new DiskFileUpload();這句,并在后面加上upload.setEncoding("utf-8");重新編譯,并使用WinRAR打到jar包FCKeditor-2.3.jar的對應位置,替換掉原來的那個,即可
4. 當瀏覽服務器,并新建中文名的文件夾出現亂碼時,只需設置tomcat的server.xml : <Connector port="8181" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="utf-8" /> 以及
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="utf-8" /> 紅色為添加部分,即可
5. 如果你還使用了struts2來過濾,那么就修改web.xml(也可以有其他方法,但這個相對簡單些)
把原來的:
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
改成如下方式:
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/struts/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.js</url-pattern>
</filter-mapping>
即可
這樣,就能暢快的享受fckeditor帶給你的樂趣了……
IDE:MyEclipse6.5
框架:Struts2+spring+hibernate
步驟:
1. 在fckeditor的官方網站http://ckeditor.com/download下載FCKeditor_2.5.1.zip和FCKeditor-2.3.zip(for java),版本不同內容不同
2. 在MyEclipse中新建web項目,我的叫做wsjx
3. 解壓縮兩個文件,把FCKeditor_2.5.1.zip解壓出來的fckeditor文件夾放在WebRoot目錄下,把FCKeditor-2.3.zip(for java)解壓出來的web下的WEB-INF下的lib目錄中的commons-fileupload.jar和FCKeditor-2.3.jar兩個jar包拷到項目的lib目錄下,把FCKeditor-2.3.zip(for java)解壓出來的src目錄下的FCKeditor.tld拷貝到項目的WEB-INF下
4. 修改fckeditor文件夾下的fckeditor.js,找到FCKeditor.BasePath 并附值FCKeditor.BasePath = '/wsjx/fckeditor/'
5. 修改fckeditor文件夾下的fckconfig.js,找到并作如下修改
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.ImageUploadURL = FCKConfig.BasePath + 'filemanager/upload/simpleuploader?Type=Image' ;
FCKConfig.FlashUploadURL = FCKConfig.BasePath + 'filemanager/upload/simpleuploader?Type=Flash' ;
不好意思,這部分的修改沒有搞明白什么原因
6. 修改web.xml,加入:













































































addContent.jsp:

















































這還沒有完,因為可能會出現幾種錯誤:
1. 當你上傳圖片時,提示“沒有權限”,在控制臺會輸出“找不到Image文件夾”,那么在UserFiles里新建Image文件夾,即可
2. 當傳輸文字包括中文時,可能會出現顯示亂碼的問題,那么把showContent.jsp中的<%=request.getParameter("content")%>改成<%=new String(request.getParameter("content").getBytes("ISO-8859-1"),"utf-8")%> 即可
3. 當上傳中文名的圖片時,圖片名稱顯示亂碼,解決方式,在FCKeditor-2.3.zip(for java)解壓出來的文件夾下,找到ConnectorServlet.java和SimpleUploadServlet.java,分別在兩個文件中找到DiskFileUpload upload = new DiskFileUpload();這句,并在后面加上upload.setEncoding("utf-8");重新編譯,并使用WinRAR打到jar包FCKeditor-2.3.jar的對應位置,替換掉原來的那個,即可
4. 當瀏覽服務器,并新建中文名的文件夾出現亂碼時,只需設置tomcat的server.xml : <Connector port="8181" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="utf-8" /> 以及
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="utf-8" /> 紅色為添加部分,即可
5. 如果你還使用了struts2來過濾,那么就修改web.xml(也可以有其他方法,但這個相對簡單些)
把原來的:
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
改成如下方式:
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/struts/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.js</url-pattern>
</filter-mapping>
即可
這樣,就能暢快的享受fckeditor帶給你的樂趣了……