ITeye博客

fckeditor_for_java的用法

hyh2011 · 2012-11-18 22:52 · java · 编程语言 · Markdown

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

 

以javascript方法调用

 方法(一)

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

 拷代码(在head内):

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

 在body内:

 <script type="text/javascript">

    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();

 </script>

 

 方法(二)

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

   拷代码(在head内):

      <script type="text/javascript" src="fckeditor/fckeditor.js"></script> //src中第一个fckeditor是项目名称

      <script type="text/javascript">

        window.onload = function(){

            var oFCKeditor = new FCKeditor('MyTextarea');

            oFCKeditor.BasePath = "fckeditor/";

            oFCKeditor.ReplaceTextarea();

          }

      </script>

     在body内加代码:

        <TEXTAREA row="4" cols="60" name="MyTextarea">this is value</TEXTAREA> 

        

 *********************************       

 在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)写代码:

                <%@ taglib uri="http://java.fckeditor.net" prefix="FCK"%>

              在body内:

                 <FCK:editor instanceName="myEditor" basePath="/fckeditor" value="this is my content"></FCK:editor> 

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

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

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

            

   *****************************

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

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

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

          FCKConfig.AutoDetectLanguage = false ;

       3,

          1>在fckeditor中自带的fckconfig.js文件中指定

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

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

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

       4,重新部署即可

 

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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。