---
title: "fckeditor_for_java的用法"
author: "hyh2011"
date: "2012-11-18T22:52:58Z"
tags: []
categories: ["编程语言"]
slug: "fckeditor-for-java"
draft: false
lastmod: "2012-11-18T22:52:58Z"
id: 1729170
url: "https://hyh2011.iteye.com/blog/1729170"
---

在很多时候都需要使用网页编辑器，包括在文章发布的时候或是在表单设计的时候。下面为fckeditor的使用。

 

以javascript方法调用

 方法(一)

 将fckeditor.jar包拷贝到webroot目录下,新建一html文件,加如一下代码

 拷代码(在head内):

 &lt;script type="text/javascript" src="fckeditor/fckeditor.js"&gt;&lt;/script&gt;

 在body内:

 &lt;script type="text/javascript"&gt;

    var oFCKeditor = new FCKeditor('FCKeditor');

    // http://localhost:8080/fckeditor

    // http://localhost:8080/test/fckeditor

    oFCKeditor.BasePath = "test/fckeditor/"; // test/是基路径,注意Basepath一定要以斜线结尾

    

     oFCKeditor.Width = "60";  //指定fckeditor的宽度

     oFCKeditor.Height = "400"; //指定fckeditor的高度

     oFCKeditor.Value = "initial value"; //指定fckeditor的初始值

     oFCKeditor.ToolBarSet = "Basic"; //指定fckeditor的工具集类型

     

    oFCKeditor.Create();

 &lt;/script&gt;

 

 方法(二)

 将fckeditor.jar包拷贝到webroot目录下,新建一html文件

   拷代码(在head内):

      &lt;script type="text/javascript" src="fckeditor/fckeditor.js"&gt;&lt;/script&gt; //src中第一个fckeditor是项目名称

      &lt;script type="text/javascript"&gt;

        window.onload = function(){

            var oFCKeditor = new FCKeditor('MyTextarea');

            oFCKeditor.BasePath = "fckeditor/";

            oFCKeditor.ReplaceTextarea();

          }

      &lt;/script&gt;

     在body内加代码:

        &lt;TEXTAREA row="4" cols="60" name="MyTextarea"&gt;this is value&lt;/TEXTAREA&gt; 

        

 \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**       

 在jsp中通过自定义标签调用:

   可以参考:(根据最新版本来定)  

     1,演示工程fckeditor-java-demo-2.4.war

           不能直接查看已经发布后访问到的页面的源码,因为那是个jsp页面,看项目本身的js文档

     2,fckeditor-java-2.4的文档(解压fckeditor-java-bin.rar)

           1)新建jsp页面

           2)拷jar包:fckeditor-java-core.jar(核心jar包),lib下的两个文件上传的和日志的jar包

           3)写代码:

                &lt;%@ taglib uri="http://java.fckeditor.net" prefix="FCK"%&gt;

              在body内:

                 &lt;FCK:editor instanceName="myEditor" basePath="/fckeditor" value="this is my content"&gt;&lt;/FCK:editor&gt; 

              //basepath一定要以'/'开头,  '/'代表当前工程的路径

              //一定要设置value属性的值,并且值不能是空字符串 

            注:可能会出现缺少类的情况,比较方便的方法是看已提供的demo项目!!     

            

   \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**

   配置文件(自定义配置):

      1,在fckeditor中有一个fckconfig.js文件,然后可以直接进行相应的修改,一般不采用这种方法,而是采用额外的文件

      2,在webroot下见一个myconfig.js文件,只需写需要修改的配置项(参考文档)

          FCKConfig.AutoDetectLanguage = false ;

       3,

          1&gt;在fckeditor中自带的fckconfig.js文件中指定

             FCKConfig.CustomConfigurationsPath = '/test/myconfig.js';

          2&gt;在页面代码中调用代码对FCKeditor的实例进行配置:

             body中的fckeditor中指定: oFCKeditor.Config\["CustomConfigurationPath"] = '/test/myconfig.js';

       4,重新部署即可

 

以上为fckeditor的使用步骤，同时也可以用java代码的方式写成标签。