CKEditor即大名鼎鼎的FCKeditor,改版后更名为CKeditor。这应该是和它的开发公司CKSource(波兰华沙的公司)的名字有关吧,该公司的另一个产品为CKFinder(一个Ajax文件管理器),这次可能为了保持一致,将FCK更改为CK。
1、下载CKEditor。
链接:https://ckeditor.com/
我用的是CKEditor 4。建议下载完全包(Full Package),功能,组件多一点,当然看自己喜好选择。
2、我们将下载好的压缩包解压
3、将解压后的文件放入我们的web工程中,即WebContent根目录下。
4、将将CKEditor添加到我们的jsp页面中。
首先,创建一个包含元素的简单HTML页面。然后,您需要做两件事:
(1)用js在页面中包含加载CKEditor 的 元素。
(2)使用该CKEDITOR.replace()方法用CKEditor 替换现有元素。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CKeditor Demo</title>
<script src="./ckeditor/ckeditor.js"></script><!-- 注意,这里的src地址为 ckeditor中ckeditor.js 文件的位置,请根据您自己的地址填写 -->
</head>
<body>
<form>
<textarea name="editor1" id="editor1" rows="10" cols="80">
This is my textarea to be replaced with CKEditor.
</textarea>
<script>
// Replace the <textarea id="editor1"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace( 'editor1' );
</script>
</form>
</body>
</html>
效果如图:
至此,我们就已将CKEditor嵌入了我们的jsp中。