---
title: "maven2+struts2+velocity+fckeditor 配置"
author: "xiaominzi"
date: "2011-05-17T15:02:01Z"
tags: []
categories: ["编程语言"]
slug: "maven2-struts2-velocity-fckeditor"
draft: true
lastmod: "2011-05-17T15:02:01Z"
id: 1047069
url: "https://xiaominzi.iteye.com/blog/1047069"
---

1 下载fckeditor包

  地址：http://ckeditor.com/download  FCKeditor 2.6.6

2 项目部署

  将FCKeditor_2.6.4.zip解压缩,将整个目录FCKeditor复制到项目的根目录下，
  
  目录结构为：和WEB-INF平级

3 整合web.xml

  将以下代码放入web.xml中


 <servlet>  
     <servlet-name>Connector</servlet-name>  
     <servlet-class>  
          net.fckeditor.connector.ConnectorServlet   
     </servlet-class>  
     <load-on-startup>1</load-on-startup>  
 </servlet>  
  
 <servlet-mapping>  
     <servlet-name>Connector</servlet-name>  
    
     <url-pattern>  
          /fckeditor/editor/filemanager/connectors/*   
     </url-pattern>  
 </servlet-mapping> 

 4.精简FCKeditor

 1>临时文件及文件夹删除：从根目录下开始删除一切以“_”开头的文件及文件夹，因为他们为临时文件和文件夹。删除这类临时文件及文件夹之后，我们还要删除一些根目录下的多余文件，根目录下我们只保留fckconfig.js（配置文件）、fckeditor.js（js方式调用文件）、fckstyles.xml（样式）、fcktemplates.xml（模板）文件和editor文件夹。

      2>editor\lang目录：存放的是多语言配置文件，因为我们只可能用到en和zh-cn（简体中文）所以，根据我的选择，我删掉其他的语言配置文件。

      3>editor\skins界面目录：默认带有三个界面（default：默认界面，加载速度相对较快；office2003：相对pp的界面，不过速度确实要慢些；silver：银白色界面，加载速度也相对较快），可以自行决定是否删除其中一两个。

      4>editor\filemanager\browser\default\connectors目录：存放编辑器所支持的Web动态语言，我们以php为例所以保留php目录，test.html文件可以帮助你查看某语言下的上传设置等（具体上传设置我将在后面的配置作较为详细讲解），可以自行决定是否删除。

       5>editor\filemanager\upload目录：同理。

5 依赖包在maven2中配置
  
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.5.2</version>
        </dependency>
        <dependency>
            <groupId>net.fckeditor</groupId>
            <artifactId>java-core</artifactId>
            <version>2.4.2</version>
        </dependency>

6 创建在Velocity中使用FCKeditor的类

  public class FCKeditorWrapper{
    private HttpServletRequest request;
    public FCKeditorWrapper(final HttpServletRequest request) {
        this.request = request;
     }
    /**
     *
     * @param instanceName 参数名称
     * @param value
     * @return
     */
    public String get(final String instanceName,final String value) {
        FCKeditor editor = new FCKeditor(request, instanceName);
        editor.setValue(value);
        return editor.createHtml();
    }

    /**
     *
     * @param instanceName 参数名称
     * @param width
     * @param height
     * @param toolbarSet
     * @param value
     * @return
     */
    public String get(final String instanceName, final String width,
            final String height, final String toolbarSet, final String value) {
        FCKeditor editor = new FCKeditor(request, instanceName, width, height,
                toolbarSet, value, null);
        editor.setValue(value);
        return editor.createHtml();
    }
  }
 
  7 action 代码调用

        FCKeditorWrapper fck = new FCKeditorWrapper(request);
        Result result = new Result();//自己封装的 
        result.addDefaultModel("FCKeditor",fck);
        toVm(result);
        return "";

  8  velocity 调用

     $!FCKeditor.get("book.extendedAttributes", "99%","120px","Default","请在这里填入内容")
     book.extendedAttributes //上传到action的名字
     99% 宽度
     120px 高度
     Default 默认显示风格 可以定义自己的风格
     最后一个参数是 要显示的内容

 9  FCKeditor优化

    网络有很多瘦化内容。

 10 注意

   按此步骤配置后不需要有任何配置，velocity自动能加载。