`

CKEditor 3.0(FCKEditor3.0)的简单安装配置使用

    博客分类:
  • html
阅读更多


CKEditor 3.0安装配置,只是简单的配置使用。

下载CKEditor 3.0,地址:http://ckeditor.com/

首先,下载下来解压后,把文件夹ckeditor放到你的项目的下。

其次,在你的网页里面加入下面脚本:

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

注意红色部分,这里根据你自己的编辑器路径修改,请务必配置正确。

再次,在需要引用CKEditor编辑器的地方加入下面代码:

<textarea class="ckeditor" cols="80" id="editor1" name="editor1" rows="10">
这里是内容
</textarea>

<script type="text/javascript">
CKEDITOR.replace( 'editor1' );
</script>


这样,一个编辑器就基本可以使用了。



  


<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<body id="homepage">
<div class="contentbox">

   <script type="text/javascript" src="ckeditor/ckeditor.js"></script>  
<!-- Top Breadcrumb Start -->
<form id="boardform" action="board!save.action" name=""boardform"" method="POST">
 
 
<table width="100%" border="0" cellspacing="3" cellpadding="0">
    <tr>
      <td align="right">标题:</td>
      <td colspan="3">
         <input type="text" value=""  size="70"  name="title" id="title"  class="easyui-validatebox"   required="true" />
      </td>
    </tr>
     
    <tr>
      <td align="right">公告内容:</td>
      <td colspan="3">
     
            <textarea class="ckeditor" cols="80" id="editor1" name="editor1" rows="10">
</textarea>
     
      </td>
    </tr>
     
    <tr>
      <td width="80" align="right">&nbsp;</td>
      <td colspan="3">
       <input type="button" value="提交" class="btn"  onClick="sub()" />
        <input type="button" value="返回" class="btnalt"  onClick="javascript:window.location='board.action'" />
        </td>
    </tr>
  </table>
  </form>
  
 <script type="text/javascript"> 
   function sub(){
    if($("#title").val() == ""){
     top.easyAlert('提示信息','请输入标题!');
     return;
    }
    if(CKEDITOR.instances.content.getData() == ""){
     top.easyAlert('提示信息','请输入内容!');
     return;
    }
    $.ajax({
        type : "POST",
     url : "board!save.action",  
     data : {'id' : $("#id").val(),'title' : $("#title").val(),'content' : CKEDITOR.instances.content.getData()},
     success : function(json){
      if(json != "error"){
        top.easyAlert('提示信息','保存成功!','info',function(){window.location.href="/bo/board/board!newOrEdit.action?id="+json});
      }else{
       top.easyAlert('提示信息','更新失败!');
      }
     }
    });
   }
  
 
  CKEDITOR.replace( 'content',
   {
    extraPlugins : 'docprops',
    // Remove unused plugins.
    removePlugins : 'bidi,button,dialogadvtab,div,filebrowser,flash,format,forms,horizontalrule,iframe,indent,justify,liststyle,pagebreak,showborders,stylescombo,table,tabletools,templates',
    // Width and height are not supported in the BBCode format, so object resizing is disabled.
    disableObjectResizing : true,
    // Define font sizes in percent values.
    fontSize_sizes : "30/30%;50/50%;100/100%;120/120%;150/150%;200/200%;300/300%",
    toolbar :
    [
     ['Undo','Redo'],
     ['Find','Replace','-','SelectAll','RemoveFormat'],
     ['SpecialChar'],
     ['Bold', 'Italic','Underline'],
     ['FontSize'],
     ['TextColor'],
     ['NumberedList','BulletedList','-','Blockquote'],
     ['Maximize']
    ],
    // Strip CKEditor smileys to those commonly used in BBCode.
    smiley_images :
    [
     'regular_smile.gif','sad_smile.gif','wink_smile.gif','teeth_smile.gif','tounge_smile.gif',
     'embaressed_smile.gif','omg_smile.gif','whatchutalkingabout_smile.gif','angel_smile.gif','shades_smile.gif',
     'cry_smile.gif','kiss.gif'
    ],
    smiley_descriptions :
    [
     'smiley', 'sad', 'wink', 'laugh', 'cheeky', 'blush', 'surprise',
     'indecision', 'angel', 'cool', 'crying', 'kiss'
    ]
  } );
</script>


 

 

   servlet中关于ckedit处理文件上传 ,如果需要ckeditor的上传页签显示需要修改images.js,具体可参考http://blog.csdn.net/mydwr/article/details/8669594,同时需要在config.js中配置请求的action 或者servlet的url,如

/**
 * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
 * For licensing, see LICENSE.html or http://ckeditor.com/license
 */

CKEDITOR.editorConfig = function( config ) {
	// Define changes to default configuration here.
	// For complete reference see:
	// http://docs.ckeditor.com/#!/api/CKEDITOR.config

	// The toolbar groups arrangement, optimized for two toolbar rows.
	config.toolbarGroups = [
		{ name: 'clipboard',   groups: [ 'clipboard', 'undo' ] },
		{ name: 'editing',     groups: [ 'find', 'selection', 'spellchecker' ] },
		{ name: 'links' },
		{ name: 'insert' },
		{ name: 'forms' },
		{ name: 'tools' },
		{ name: 'document',	   groups: [ 'mode', 'document', 'doctools' ] },
		{ name: 'others' },
		'/',
		{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
		{ name: 'paragraph',   groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] },
		{ name: 'styles' },
		{ name: 'colors' },
		{ name: 'about' }
	];

	// Remove some buttons provided by the standard plugins, which are
	// not needed in the Standard(s) toolbar.
	config.removeButtons = 'Underline,Subscript,Superscript';

	// Set the most common block elements.
	config.format_tags = 'p;h1;h2;h3;pre';

	// Simplify the dialog windows.
	config.removeDialogTabs = 'image:advanced;link:advanced';
	
	config.filebrowserUploadUrl="actions/ckeditorUpload";
	var pathName = window.document.location.pathname;
    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    config.filebrowserImageUploadUrl = projectName+'/servlet?flag=uploadFile'; 


};

  Java代码如下

	try {
				PrintWriter out = response.getWriter();
				DiskFileItemFactory dff = new DiskFileItemFactory();// 创建该对象0
				dff.setSizeThreshold(1024000);// 指定在内存中缓存数据大小,单位为byte
				ServletFileUpload sfu = new ServletFileUpload(dff);// 创建该对象
				sfu.setFileSizeMax(10*1024*1024);// 指定单个上传文件的最大尺寸}
				String realPath=request.getSession().getServletContext().getRealPath("/");
				String filePath = realPath + CommonResource.RESOURCES_UPLOAD_IMAGES_PATH;
				List<FileItem> fileItems = sfu.parseRequest(request);
				CommonStrCoding csc = new  CommonStrCoding();
				for(FileItem item:fileItems){
					String callback = request.getParameter("CKEditorFuncNum");  
					String expandedName = "";  //文件扩展名     
					String file = item.getName();
					if(StringUtils.isNotEmpty(file)){
						expandedName =file.substring(file.lastIndexOf(".")+1);
					}
					if ("png".equals(expandedName)) {    
						expandedName = ".png";    
					}else if("jpg".equals(expandedName)){    
						expandedName = ".jpg";    
					}else if("gif".equals(expandedName)){    
						expandedName = ".gif";    
					}else if("bmp".equals(expandedName)){    
						expandedName = ".bmp";    
					}else{    
						String message =csc.getStrCodingISO8859("文件格式不正确(必须为.jpg/.gif/.bmp/.png文件)");
						out.println("<script type=\"text/javascript\">");      
						out.println("window.parent.CKEDITOR.tools.callFunction(" + callback + ",''," + "'"+message+"');");     
						out.println("</script>"); 
						return;
					}    
					if(item.getSize() > 600*1024){    
						String message = csc.getStrCodingISO8859("文件大小不得大于600K");
						out.println("<script type=\"text/javascript\">");      
						out.println("window.parent.CKEDITOR.tools.callFunction(" + callback + ",''," + "'"+message+"');");     
						out.println("</script>");  
						return ;
					}    
					BufferedInputStream in = new BufferedInputStream(item.getInputStream());// 获得文件输入流
					File targetFilePath = new File(filePath);
					if(!targetFilePath.exists()){
						targetFilePath.mkdirs();
					}
					String file_name="";
					if(StringUtils.isNotEmpty(file)){
						file_name = file.substring(file.lastIndexOf("\\")+1);
					}
					File targetFile = new File(targetFilePath,file_name);
					BufferedOutputStream ou = new BufferedOutputStream(new FileOutputStream(targetFile));// 获得文件输出流
					Streams.copy(in, ou, true);    // 把文件写到你指定的上传文件夹
					// 返回"图像"选项卡并显示图片     
					String showpath = "/portal/uploadFile/images/"+file_name;
					out.println("<script type=\"text/javascript\">");      
					out.println("window.parent.CKEDITOR.tools.callFunction(" + callback + ",'" + showpath + "','')");      
					out.println("</script>"); 
				}
			} catch (Exception e) {
				throw new IOException(e.getMessage());
			}

 

 

关于其他是形式文件上传配置可参考:

参考: http://blog.csdn.net/xiao__gui/article/details/7684505

分享到:
评论

相关推荐

    fckeditor最新版ckeditor_3.0.zip 资源包免费下载

    fckeditor文本编辑器旧版漏洞太多 先出了最新版 欢迎下载使用

    ckeditor_3.0.zip

    CKEditor即大名鼎鼎的...这应该是和它的开发公司CKSource的名字有关吧,该公司的另一个产品为CKFinder(一个Ajax文件管理器),这次可能为了保持一致,将FCK更改为CK,但是版本号继承了下来,为CKeditor3.0版。

    ckeditor_3.0.tar.gz

    FCKeditor是sourceforge.net上面的一个开源项目,主要是实现在线网页编辑器的功能,可以让web程序拥有如MS Word这样强大的编辑功能。官方网站为http://www.fckeditor.net ,在服务器端支持...这里是最新版的ckeditor3.0

    将CKfinder 整合进 CKEditor3.0的方法

    CKFinder是一款基于AJAX的文件浏览器,这是ASP.NET专用版,它可以在线浏览文件、管理文件、上传文件,以树形Tree的方式展开目录,自动检测图片并生成缩略图,它是由Fckeditor公司出品,同时也可配合FckEditor来使用,...

    ckeditor3.6 API

    著名的开源网页编辑软件FCKEditor在09年发布更新到3.0,并改名为CKEditor。原来叫FCK,是因为最初的开发者叫Frederico Calderia Knabben;现在叫CK,意指"Content and Knowledge"。新版的编辑器的更新包括:新的用户...

    CKEditor-3-JavaScript-API-Documentation.chm

    CKEditor-3-配置文档 config.height = 500; config.htmlEncodeOutput = true config.language = 'de';

    ckeditor 编辑器

     著名的开源网页编辑软件FCKEditor在09年发布更新到3.0,并改名为CKEditor。原来叫FCK,是因为最初的开发者叫Frederico Calderia Knabben;现在叫CK,意指"Content and Knowledge"。新版的编辑器的更新包括:新的...

    FCKEditor——开源的网页编辑器

     著名的开源网页编辑软件FCKEditor在09年发布更新到3.0,并改名为CKEditor。原来叫FCK,是因为最初的开发者叫Frederico Calderia Knabben;现在叫CK,意指"Content and Knowledge"。新版的编辑器的更新包括:新的...

    FCKeditor编辑器(适用于。net)

    FckEditor更名CKEditor 著名的开源网页编辑软件FCKEditor在09年发布更新到3.0,并改名为CKEditor。原来叫FCK,是因为最初的开发者叫Frederico Calderia Knabben;现在叫CK,意指"Content and Knowledge"。新版的...

    酷纬企业网站管理系统Kuwebs 3.0 双语版.zip

    4.FCKeditor变更为CKEditor,大大提高安全性和效率说 5.增加数据块功能,可以自定义数据块并添加到网页任意位置。 6.增加邮件配置功能,支持SMTP邮件和PHP邮件方式的配置。 7.修改导航栏为二级导航时无选定状态...

Global site tag (gtag.js) - Google Analytics