您的位置:首页 > 其它

CKeditor在线编译器的配置与使用

2013-07-16 15:55 543 查看
CKeditor是一款免费、开源、用户量庞大的在线编译器,有良好的社区支持。源码结构如下:



官方网站:http://ckeditor.com/

官方下载地址:http://ckeditor.com/download

CKEditor目前的版本是CKEditor 4.1.1,支持java的版本为ckeditor-java-core-3.5.3。

CKEditor运行效果图如图:



测试在jsp页面表单中使用CKeditor在线编辑器,主要步骤如下:

(1) 在CKeditor官方网站下载最新的ckeditor_4.1.1_standard.zip,解压后将ckeditor目录复制到需要使用编辑器项目下面,如下图





(2) 将CKeditor使用到的ckeditor-java-core-3.5.3.jar复制到项目的WEB-INF/lib目录下。至此,CKeditor已经配置完成,在项目下可以使用了。

建立测试项目如下:



下面介绍jsp程序中如何调用在线编辑器,代码如下图。程序使用定义的jsp标签指令<ckeditor:editor></ckeditor:editor>。

index.jsp代码如下:

<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8" errorPage="" %>

<%@ taglib uri="http://ckeditor.com" prefix="ckeditor" %>

<%@ page import="com.ckeditor.CKEditorConfig" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>在线编译器</title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

</head>

<body>

<form id="form" name="form" method="post" action="fckeditorpost.jsp">

文章标题:<input name="title" type="text" id="title" size="60" ><br />

文章正文:

<%

String value = "CKeditor 测试";

Map<String,String> attr = new HashMap<String,String>();

attr.put("rows","8");

attr.put("cols","50");

CKEditorConfig setting = new CKEditorConfig();

setting.addConfigValue("width","850");

//setting.addConfigValue("toolbar","Basic");

%>

<ckeditor:editor editor="ArtContent" basePath="ckeditor/" textareaAttributes="<%=attr %>" config="<%=setting %>" value="<%=value %>" />

<input type="submit" name="Submit" value="提交" />

</form>

</body>

</html>

程序说明:该程序是一个使用了jsp标签调用在线编辑器的表单,程序中使用如下代码调用在线编辑器。



其中,textareaAttributes用户设置编辑器的属性,该属性可以指定显示在线编辑器的行数、列数;basePath属性用于设置编辑器的位置;config为编辑器的配置信息,可以用CKEditorConfig类定义;editor为编辑器的名称,表示表单元素名,其后可以根据该属性值获得内容;value属性表示表单文本区的默认值。

程序运行效果如下图:



工作中用到,经过测试,分享给大家……
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: