---
title: "JSP页面中使用fckeditor控件入门"
author: "ajavafan2008"
date: "2009-02-11T15:01:00Z"
tags: []
slug: "jsp-fckeditor"
draft: false
lastmod: "2014-01-15T10:17:10Z"
id: 2004171
url: "https://gilping.iteye.com/blog/2004171"
---

fckeditor控件请到官方网站下载[http://www.fckeditor.net](http://www.fckeditor.net/)，本例主要用到FCKeditor\_2.6.3.zip、fckeditor-java-demo-2.4.1.zip、fckeditor-java-2.4.1-bin.zip里面的一些内容，读者可以自行下载。

1、解开压缩包FCKeditor\_2.6.3.zip，将其中的fckeditor文件夹复制到WEB-INF下面，后面可以直接使用。

2、在页面中使用FCKeditor有两种方式。  
方式一：JavaScript的方式  
(1)直接使用，见**method1.html**

01. &lt;!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"&gt;
02. &lt;html&gt;
03. &lt;head&gt;
04. &lt;scripttype="text/javascript"src="fckeditor/fckeditor.js"&gt;&lt;/script&gt;
05. &lt;/head&gt;
06. &lt;body&gt;
07. 方法一：通过JavaScript来实现的实现编辑器导入&lt;br&gt;
08. &lt;scripttype="text/javascript"&gt;
09. varoFCKeditor=newFCKeditor('FCKeditor1');
10. oFCKeditor.BasePath="fckeditor/";
11. //oFCKeditor.BasePath="/FCKEditTest/fckeditor/";
12. oFCKeditor.Width="50%";
13. oFCKeditor.Height="400";
14. oFCKeditor.Value="initialvalue";
15. //oFCKeditor.ToolbarSet="Basic";
16. //默认是default
17. oFCKeditor.ToolbarSet="Default";
18. oFCKeditor.Create();
19. &lt;/script&gt;
20. &lt;hr&gt;
21. &lt;/body&gt;
22. &lt;/html&gt;

(2)通过**Textarea，祥见method2.html**

01. &lt;!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"&gt;
02. &lt;html&gt;
03. &lt;head&gt;
04. &lt;scripttype="text/javascript"src="fckeditor/fckeditor.js"&gt;&lt;/script&gt;
05. &lt;scripttype="text/javascript"&gt;
06. window.onload=function(){
07. varoFCKeditor=newFCKeditor('**MyTextarea**');
08. oFCKeditor.BasePath="fckeditor/";
09. //oFCKeditor.BasePath="/FCKEditTest/fckeditor/";
10. oFCKeditor.ReplaceTextarea();
11. }
12. &lt;/script&gt;
13. &lt;/head&gt;
14. &lt;body&gt;
15. 方法二：通过Textarea来实现的实现编辑器导入&lt;br&gt;
16. &lt;textarearows="4"cols="60"name="**MyTextarea**"&gt;thisisavalue&lt;/textarea&gt;
17. &lt;/body&gt;
18. &lt;/html&gt;

方式二：在标签使用FCKeditor  
在使用标签之前，需要搭建环境。将fckeditor-java-2.4.1-bin.zip包中的fckeditor-java-core-2.4.1.jar、commons-fileupload-1.2.1.jar、commons-io-1.3.2.jar、slf4j-api-1.5.2.jar以及包fckeditor-java-demo-2.4.1.zip中的slf4j-simple-1.5.2.jar复制到lib目录下，并构建环境。  
构建完后，就可以在JSP页面中进行使用。祥见页面method\_jsp.jsp

01. &lt;%@pagelanguage="java"import="java.util.\*"pageEncoding="utf-8"%&gt;
02. &lt;%@tagliburi="http://java.fckeditor.net"prefix="FCK"%&gt;
03. &lt;!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"&gt;
04. &lt;html&gt;
05. &lt;head&gt;
06. &lt;title&gt;method\_jsp.jsp&lt;/title&gt;
07. &lt;/head&gt;
08. &lt;body&gt;
09. 早些版本必需将fckeditor的Value属性必需指定对应的值，且值不能为空。
10. 而此处版本是2.6.3，该问题已经解决。
11. &lt;FCK:editorinstanceName="myEditor"basePath="/fckeditor"&gt;&lt;/FCK:editor&gt;
12. &lt;/body&gt;
13. &lt;/html&gt;

效果如下图：  
![](http://p.blog.csdn.net/images/p_blog_csdn_net/guoquanyou/EntryImages/20081219/fckeditor1.JPG)