java中FCKeditor配置安装与常用问题解决

FCKeditor资料下载及介绍  
官方网站:http://www.fckeditor.net  

 1.下载FCKeditor *.*.*  

 2.下载fckeditor-java-*.*.*-bin.zip  

 3.下载fckeditor-java-demo-*.*.*.war (可作为参考)

    demo的查看、doc文档的查看  

    下载的说明,涉及java还得下个包    war工程的查看

 

安装与通过JavaScript调用FCKeditor的两种方法 

  部署:拷贝到webroot下 

  fckeditor的调用方式: 

  1.通过javascript调用 

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

     参考方式:      附带的例子 samples里      文档

   通过javascript调用

    方法一:

 代码如下 复制代码

<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
   <script type="text/javascript"><!-- 编辑器创建 -->
      var oFCKeditor = new FCKeditor("FCKeditor1");
      oFCKeditor.BasePath = "/test/fckeditor/";<!-- fckedior绝对路径,/结尾 -->
      oFCKeditor.Create();
   </script>

  方法二:

 代码如下 复制代码
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
      <head></head>里添加
    <script type="text/javascript">
       window.onload=function(){
       var oFCKeditor = new FCKeditor("MyTextarea");<!-- 下面指定 -->
       oFCKeditor.BasePath = "fckeditor/";<!-- fckedior相对路径,/结尾 -->
       oFCKeditor.ReplaceTextarea();
     }
     < /script>
      <body></body>里添加
    <textarea id="MyTextarea" name="MyTextarea">this is</textarea>

注意:BasePath要正确的设置 BasePath一定要以“/”结尾    

      fckeditor对象属性    

      Width 默认100%

      Height 默认200

      ToolbarSet 默认default

      BasePath 默认/fckeditor/

     构造器       

        var FCKeditor = function(instanceName,width,height,toolbarSet,value)        

        instanceName为编辑器输出的textarea元素的name属性值,必须指定       

        参数会赋值给同名属性

 

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

参考   演示工程   帮助文档   jar文件拷贝 

 步骤:   拷贝jar文件 

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

<FCK:editor instanceName="myEditor" basePath="/fckeditor" value="haha"></FCK:editor> 

注意:basePath要以“/”开头,/代表当前工程路径   一定要设置value属性的值,并且值不能为空字符串

配置_使用配置文件 

    webroot下创建myconfig.js文件 

    FCKConfig.AutoDetectLanguage=false; 自动检测语言 

    FCKConfig.DefaultLanguage="fr"; 

     在默认的配置文件里 

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

    二、在创建编辑器时指定下     oFCKeditor.Config["CustomConfigurationsPath"]="/test/myconfig.js"; 只对当前有效

    配置FCKeditor三种方式 

    直接修改主配置文件 fckconfig.js 

    定义单独的配置文件(只需用写需要修改的配置项) 

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

      配置加载顺序  

        1.加载主配置文件fckconfig.js  

        2.加载自定义的配置文件(如果有),覆盖相同的配置项  

        3.使用对实例的配置覆盖相同的配置项(只对当前实例有效)   

      提示 

      系统会自动侦测并运用适当的界面语言(默认,可以修改) 

      不能删除主配置文件fckconfig.js 

      修改配置后要清空浏览器缓存,以免影响结果     (或访问时强制刷新也可以) IE:Ctrl+F5 Firefox:Shift+Ctrl+R

 

配置_一般需要修改的配置 

     一般需要修改的配置   

          自定义ToolbarSet,去掉一些功能   

         加上几种常用的字体   

        修改"回车"和"Shift+回车"的换行行为   

        修改编辑区的样式   

        更换表情图片

 

  自定义ToolbarSet,去掉一些功能      

       先自定义工具集再引用该工具集     

         关于自定义工具集选择的工具看 '-'代表分隔符'|' '/'代表换行符 

 

    加上几种常用的字体  

        FCKConfig.FontNames = '实体;楷体_GB2312;黑体;隶书;Times New Roman;Arial';

 

   修改"回车"和"Shift+回车"的换行行为   

        FCKConfig.EnterMode = 'br'; // p | div | br   

        FCKConfig.ShiftEnterMode = 'p';

 

    修改编辑区的样式   

         文件路径 FCKConfig.basePath下 alert()下就知道在哪了

 

     配置_更换表情图片  

          配置选项  

          FCKConfig.SmileyPath = ''; //文件路径  

          FCKConfig.SmileyImages = ['','']; //路径下的图片名称  

          FCKConfig.SmileyColumns = 8; //每行显示数量  

          FCKConfig.SmileyWindowWidth = 320; //窗体宽度  

          FCKConfig.SmileyWindowHeight =210; //窗体高度   

         单个添加更换或整个文件夹更换     想添加滚动条,查看窗体的文件进行修改     

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

         工程不确定,应该修改为     FCKConfig.CustomConfigurationsPath=FCKConfig.EditorPath+'myconfig.js';

      注意:   自定义的配置文件要使用UTF-8编码保存 

         FCKConfig.BasePath和调用fckeditor时指定的   BasePath(FCKeditor.BasePath)不是同一个,其值也不一样

 

 

文件上传_基本使用  

      使用看java关联的文档  

      步骤    在web.xml文件添加一个servlet  

     

 代码如下 复制代码

<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>

在classpath下新建fckeditor.properties //名字路径不能改变   

      里面内容

connector.userActionImpl=net.fckeditor.requestcycle.impl.UserActionImpl
 

文件上传_问题一_上传中文名的文件会出现乱码 

     使用文件上传会遇到下面问题 

         上传中文名的文件会出现乱码 

         创建中文名的目录时会出现乱码 

         引用的中文名字的图片不能正常显示   解决:写个servlet把post方法中setHeaderEncoding("utf-8");

 代码如下 复制代码

package com.fck.fckeditor;

/*
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 * Copyright (C) 2003-2008 Frederico Caldeira Knabben
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
 */

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.UUID;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.fckeditor.connector.Messages;
import net.fckeditor.handlers.CommandHandler;
import net.fckeditor.handlers.ConnectorHandler;
import net.fckeditor.handlers.ExtensionsHandler;
import net.fckeditor.handlers.RequestCycleHandler;
import net.fckeditor.handlers.ResourceTypeHandler;
import net.fckeditor.response.UploadResponse;
import net.fckeditor.response.XmlResponse;
import net.fckeditor.tool.Utils;
import net.fckeditor.tool.UtilsFile;
import net.fckeditor.tool.UtilsResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Servlet to upload and browse files.<br />
 *
 * This servlet accepts 4 commands which interact with the server-side
 * filesystem.<br />
 * The allowed commands are:
 * <ul>
 * <li><code>GetFolders</code>: Retrieves a list of folders in the current
 * folder</li>
 * <li><code>GetFoldersAndFiles</code>: Retrives a list of files and folders
 * in the current folder</li>
 * <li><code>CreateFolder</code>: Creates a new folder in the current folder</li>
 * <li><code>FileUpload</code>: Stores an uploaded file into the current
 * folder. (must be sent with POST)</li>
 * </ul>
 *
 * @version $Id: ConnectorServlet.java 2101 2008-06-22 22:00:48Z mosipov $
 */
public class ConnectorServlet extends HttpServlet {

    private static final long serialVersionUID = -5742008970929377161L;
    private static final Logger logger = LoggerFactory.getLogger(ConnectorServlet.class);

    /**
     * Initialize the servlet: <code>mkdir</code> &lt;DefaultUserFilesPath&gt;
     */
    public void init() throws ServletException, IllegalArgumentException {
        String realDefaultUserFilesPath = getServletContext().getRealPath(
                ConnectorHandler.getDefaultUserFilesPath());

        File defaultUserFilesDir = new File(realDefaultUserFilesPath);
        UtilsFile.checkDirAndCreate(defaultUserFilesDir);

        logger.info("ConnectorServlet successfully initialized!");
    }

    /**
     * Manage the <code>GET</code> requests (<code>GetFolders</code>,
     * <code>GetFoldersAndFiles</code>, <code>CreateFolder</code>).<br/>
     *
     * The servlet accepts commands sent in the following format:<br/>
     * <code>connector?Command=&lt;CommandName&gt;&Type=&lt;ResourceType&gt;&CurrentFolder=&lt;FolderPath&gt;</code>
     * <p>
     * It executes the commands and then returns the result to the client in XML
     * format.
     * </p>
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        logger.debug("Entering ConnectorServlet#doGet");

        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/xml; charset=UTF-8");
        response.setHeader("Cache-Control", "no-cache");
        PrintWriter out = response.getWriter();

        String commandStr = request.getParameter("Command");
        String typeStr = request.getParameter("Type");
        String currentFolderStr = request.getParameter("CurrentFolder");

        logger.debug("Parameter Command: {}", commandStr);
        logger.debug("Parameter Type: {}", typeStr);
        logger.debug("Parameter CurrentFolder: {}", currentFolderStr);

        XmlResponse xr;

        if (!RequestCycleHandler.isEnabledForFileBrowsing(request))
            xr = new XmlResponse(XmlResponse.EN_ERROR, Messages.NOT_AUTHORIZED_FOR_BROWSING);
        else if (!CommandHandler.isValidForGet(commandStr))
            xr = new XmlResponse(XmlResponse.EN_ERROR, Messages.INVALID_COMMAND);
        else if (typeStr != null && !ResourceTypeHandler.isValid(typeStr))
            xr = new XmlResponse(XmlResponse.EN_ERROR, Messages.INVALID_TYPE);
        else if (!UtilsFile.isValidPath(currentFolderStr))
            xr = new XmlResponse(XmlResponse.EN_ERROR, Messages.INVALID_CURRENT_FOLDER);
        else {
            CommandHandler command = CommandHandler.getCommand(commandStr);
            ResourceTypeHandler resourceType = ResourceTypeHandler.getDefaultResourceType(typeStr);

            String typePath = UtilsFile.constructServerSidePath(request, resourceType);
            String typeDirPath = getServletContext().getRealPath(typePath);

            File typeDir = new File(typeDirPath);
            UtilsFile.checkDirAndCreate(typeDir);

            File currentDir = new File(typeDir, currentFolderStr);

            if (!currentDir.exists())
                xr = new XmlResponse(XmlResponse.EN_INVALID_FOLDER_NAME);
            else {

                xr = new XmlResponse(command, resourceType, currentFolderStr, UtilsResponse
                        .constructResponseUrl(request, resourceType, currentFolderStr, true,
                                ConnectorHandler.isFullUrl()));

                if (command.equals(CommandHandler.GET_FOLDERS))
                    xr.setFolders(currentDir);
                else if (command.equals(CommandHandler.GET_FOLDERS_AND_FILES))
                    xr.setFoldersAndFiles(currentDir);
                else if (command.equals(CommandHandler.CREATE_FOLDER)) {
                   
                    //修改新建文件夹中文乱码
                   
                     String temStr= request.getParameter("NewFolderName");
                    temStr=new String(temStr.getBytes("iso8859-1"),"utf-8");
                    // 完毕
                   
                    String newFolderStr = UtilsFile.sanitizeFolderName(temStr);
                    logger.debug("Parameter NewFolderName: {}", newFolderStr);

                    File newFolder = new File(currentDir, newFolderStr);
                    int errorNumber = XmlResponse.EN_UKNOWN;

                    if (newFolder.exists())
                        errorNumber = XmlResponse.EN_ALREADY_EXISTS;
                    else {
                        try {
                            errorNumber = (newFolder.mkdir()) ? XmlResponse.EN_OK
                                    : XmlResponse.EN_INVALID_FOLDER_NAME;
                        } catch (SecurityException e) {
                            errorNumber = XmlResponse.EN_SECURITY_ERROR;
                        }
                    }
                    xr.setError(errorNumber);
                }
            }
        }

        out.print(xr);
        out.flush();
        out.close();
        logger.debug("Exiting ConnectorServlet#doGet");
    }

    /**
     * Manage the <code>POST</code> requests (<code>FileUpload</code>).<br />
     *
     * The servlet accepts commands sent in the following format:<br />
     * <code>connector?Command=&lt;FileUpload&gt;&Type=&lt;ResourceType&gt;&CurrentFolder=&lt;FolderPath&gt;</code>
     * with the file in the <code>POST</code> body.<br />
     * <br>
     * It stores an uploaded file (renames a file if another exists with the
     * same name) and then returns the JavaScript callback.
     */
    @SuppressWarnings("unchecked")
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        logger.debug("Entering Connector#doPost");

        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html; charset=UTF-8");
        response.setHeader("Cache-Control", "no-cache");
        PrintWriter out = response.getWriter();

        String commandStr = request.getParameter("Command");
        String typeStr = request.getParameter("Type");
        String currentFolderStr = request.getParameter("CurrentFolder");

        logger.debug("Parameter Command: {}", commandStr);
        logger.debug("Parameter Type: {}", typeStr);
        logger.debug("Parameter CurrentFolder: {}", currentFolderStr);

        UploadResponse ur;

        // if this is a QuickUpload request, 'commandStr' and 'currentFolderStr'
        // are empty
        if (Utils.isEmpty(commandStr) && Utils.isEmpty(currentFolderStr)) {
            commandStr = "QuickUpload";
            currentFolderStr = "/";
        }

        if (!RequestCycleHandler.isEnabledForFileUpload(request))
            ur = new UploadResponse(UploadResponse.SC_SECURITY_ERROR, null, null,
                    Messages.NOT_AUTHORIZED_FOR_UPLOAD);
        else if (!CommandHandler.isValidForPost(commandStr))
            ur = new UploadResponse(UploadResponse.SC_ERROR, null, null, Messages.INVALID_COMMAND);
        else if (typeStr != null && !ResourceTypeHandler.isValid(typeStr))
            ur = new UploadResponse(UploadResponse.SC_ERROR, null, null, Messages.INVALID_TYPE);
        else if (!UtilsFile.isValidPath(currentFolderStr))
            ur = UploadResponse.UR_INVALID_CURRENT_FOLDER;
        else {
            ResourceTypeHandler resourceType = ResourceTypeHandler.getDefaultResourceType(typeStr);

            String typePath = UtilsFile.constructServerSidePath(request, resourceType);
            String typeDirPath = getServletContext().getRealPath(typePath);

            File typeDir = new File(typeDirPath);
            UtilsFile.checkDirAndCreate(typeDir);

            File currentDir = new File(typeDir, currentFolderStr);

            if (!currentDir.exists())
                ur = UploadResponse.UR_INVALID_CURRENT_FOLDER;
            else {

                String newFilename = null;
                FileItemFactory factory = new DiskFileItemFactory();
                ServletFileUpload upload = new ServletFileUpload(factory);
            // 修改上传中文名乱码
                upload.setHeaderEncoding("UTF-8");
                //  完毕
                try {

                    List<FileItem> items = upload.parseRequest(request);

                    // We upload only one file at the same time
                    FileItem uplFile = items.get(0);
                    String rawName = UtilsFile.sanitizeFileName(uplFile.getName());
                    String filename = FilenameUtils.getName(rawName);
                    String baseName = FilenameUtils.removeExtension(filename);
                    String extension = FilenameUtils.getExtension(filename);
                   
                    //修改上传文件名字,用UUID方法
                    filename=UUID.randomUUID().toString()+ "."+ extension;
                    //  完毕
                   
                   
                   
                   
                   
                   
                    //添加限制上传大小方法
                    //如果这个文件的扩展名不允许上传
                   
                    if (!ExtensionsHandler.isAllowed(resourceType, extension))
                        ur = new UploadResponse(UploadResponse.SC_INVALID_EXTENSION);
                   
                    //如果超出大小10M
                    else if(uplFile.getSize()> 10000 * 1024)
                    //传递一个自定义的错误码
                        ur = new UploadResponse(204);
                   
                    // 如果不存在以上情况,则保存
                    else {

                        // construct an unique file name
                        File pathToSave = new File(currentDir, filename);
                       
                       
                       
                       
                       
                       
                        int counter = 1;
                        while (pathToSave.exists()) {
                            newFilename = baseName.concat("(").concat(String.valueOf(counter))
                                    .concat(")").concat(".").concat(extension);
                            pathToSave = new File(currentDir, newFilename);
                            counter++;
                        }

                        if (Utils.isEmpty(newFilename))
                            ur = new UploadResponse(UploadResponse.SC_OK, UtilsResponse
                                    .constructResponseUrl(request, resourceType, currentFolderStr,
                                            true, ConnectorHandler.isFullUrl()).concat(filename));
                        else
                            ur = new UploadResponse(UploadResponse.SC_RENAMED,
                                    UtilsResponse.constructResponseUrl(request, resourceType,
                                            currentFolderStr, true, ConnectorHandler.isFullUrl())
                                            .concat(newFilename), newFilename);

                        // secure image check
                        if (resourceType.equals(ResourceTypeHandler.IMAGE)
                                && ConnectorHandler.isSecureImageUploads()) {
                            if (UtilsFile.isImage(uplFile.getInputStream()))
                                uplFile.write(pathToSave);
                            else {
                                uplFile.delete();
                                ur = new UploadResponse(UploadResponse.SC_INVALID_EXTENSION);
                            }
                        } else
                            uplFile.write(pathToSave);

                    }
                } catch (Exception e) {
                    ur = new UploadResponse(UploadResponse.SC_SECURITY_ERROR);
                }
            }

        }

        out.print(ur);
        out.flush();
        out.close();

        logger.debug("Exiting Connector#doPost");
    }

}

问题二_创建中文名的目录时会出现乱码  

      解决:在servlet的get方法,当request.getParameter("");之后重新编码

问题三_引用的中文名字的图片不能正常显示  

    解决:  

    方案一:修改tomcat的servlet.xml在<Connector>添加URIEncoding="UTF-8"    不推荐使用,因为将对创建中文文件夹有影响  

    方案二:避免使用中文名称保存图片,在servlet修改,采用UUID随机设置名称

 

文件上传允许上传的文件类型

       a.控制允许上传的文件类型

             FCKeditor把文件的上传分成4类  

                   File  

                   Image  

                   Flash  

                   Media

        b.设置允许上传的文件扩展名列表 禁止上传的文件扩展名列表 只能配置一项

         c.修改时除了media客户端不用设置,其它的客户端和服务器端都必须设置,且设置相同

 

 

文件上传允许上传的文件的大小

   步骤:   在服务器端的servlet中,在保存文件之前先判断一下文件的大小,  

               如果超出限制,就传递一个自定义的错误码,并且不再保存文件   修改对应界面的回调函数,增加对这个自定义的错误码的处理

              在表单中使用FCKeditor a.一般都放在表单中提交,只要放在<form></form>中 b.通过fckeditor提交的中文内容,在服务器端得到的为乱码的解决

时间: 2024-10-03 18:52:09

java中FCKeditor配置安装与常用问题解决的相关文章

Java中对List集合的常用操作详解_java

目录: 1.list中添加,获取,删除元素: 2.list中是否包含某个元素: 3.list中根据索引将元素数值改变(替换): 4.list中查看(判断)元素的索引: 5.根据元素索引位置进行的判断: 6.利用list中索引位置重新生成一个新的list(截取集合): 7.对比两个list中的所有元素: 8.判断list是否为空: 9.返回Iterator集合对象: 10.将集合转换为字符串: 11.将集合转换为数组: 12.集合类型转换: 备注:内容中代码具有关联性. 1.list中添加,获取,

java中struts配置_java

1.了解struts Struts2框架中核心组件就是Action.拦截器等,Struts2框架使用包来管理Action和拦截器等.每个包就是多个Action.多个拦截器.多个拦截器引用的集合. 在struts.xml文件中package元素用于定义包配置,每个package元素定义了一个包配置.它的常用属性有: l name:必填属性,用来指定包的名字. l extends:可选属性,用来指定该包继承其他包.继承其它包,可以继承其它包中的Action定义.拦截器定义等. l namespace

linux中postfix配置安装

  postfix是Wietse Venema在IBM的GPL协议之下开发的MTA(邮件传输代理)软件.postfix是Wietse Venema想要为使用最广泛的sendmail提供替代品的一个尝试,下面我们来看看postfix配置安装方法. 安装Postfix  代码如下   yum install postfix system-switch-mail 设定postfix  代码如下   vi /etc/postfix/main.cf myhostname = ha.xxx.kh.edu.t

php5中Xdebug配置安装步骤介绍

Xdebug版本下载 http://www.xdebug.com/download.php 注意在下载Xdebug时我们必须查看自己php版本之后与xdebug一样,并且要查看你的php是线程安全或非线程序安全的,否则可以没有用哦. 下载好 php_xdebug.dll 之后我们复制到你的php ext目录,如 D:/phpStudy/PHP5/ext/php_xdebug.dll 这个是我本地的,放好之后再把php.ini文件进行修改,加入下面代码  代码如下 复制代码 [Xdebug] ze

java 环境变量配置-安装eclipse遇到如下情况是什么原因

问题描述 安装eclipse遇到如下情况是什么原因 我已经在C盘里面下载了jdk 并且设置了环境变量 然后在eclipse官网里下载了eclipse 解压后 打开时就弹出这个对话框 是什么意思 我该怎么安装eclipse 解决方案 参考这里试试:http://blog.my-eclipse.cn/eclipse-failed-to-load-the-jni-shared-library-jvm-dll.html 解决方案二: JDK的位数要与eclipse的位数一样 解决方案三: 是不是jdk的

windows2003中IIS配置安装图文教程

Windows Server 2003 包含了网页服务器最基本的服务:Internet Information Services(IIS,互联网信息服务),本文讲解如何在Windows 2003下安装IIS.   一.放入系统光盘,加载光盘映象       二.进入"添加或删除程序"     单击"开始"菜单,找到"控制面板"选项卡,再单击"添加或删除程序".   三.增加组件     单击"添加/删除Windows

MySQL 5.5中如何配置安装半同步复制

确认master和slave上是否开启have_dynamic_loading master MASTER(none) 10:54:58>show variables like 'have_dynamic_loading'; +----------------------+-------+ | Variable_name        | Value | +----------------------+-------+ | have_dynamic_loading | YES   | +----

CentOS FastDFS中Client配置安装教程

# 连接超时时间 # 默认值 30s connect_timeout=30 # 网络超时时间 # 默认值 30s network_timeout=60 # the base path to store log files 存放日志的根目录 base_path=/rekfan.com/fastdfs_data # tracker_server can ocur more than once, and tracker_server format is #  "host:port", hos

深入理解Java中的克隆_java

前言 Java克隆(Clone)是Java语言的特性之一,但在实际中应用比较少见.但有时候用克隆会更方便更有效率. 对于克隆(Clone),Java有一些限制:       1.被克隆的类必须自己实现Cloneable 接口,以指示 Object.clone() 方法可以合法地对该类实例进行按字段复制.Cloneable 接口实际上是个标识接口,没有任何接口方法.       2.实现Cloneable接口的类应该使用公共方法重写 Object.clone(它是受保护的).某个对象实现了此接口就