在线文本编辑器对于任何网络系统来说都是必不可少的的模块,尤其是对于表单页面程序来说几乎是必需模块。本文主要介绍如何在表单中调用FCKeditor。
1、下载FCKeditor的相关软件
FCKeditor_2.6.6 fckeditor-java-2.4-bin(可以对FCKeditor进行精简,这样不仅可以提高其加载速度,还可以提高Java web项目的运行速度。当然,为了省事,可以不用精简,不影响FCKeditor的使用)。
下载链接:FCKeditor_2.6.6点击打开链接 fckeditor-java-2.4-bin点击打开链接
2、利用JavaScript语言调用FCKeditor
新建一个名叫myFCKeditortest的JavaWeb项目,然后把解压后的fckeditor文件夹以及该文件夹下的所有文件复制到myFCKeditortest/WebRoot目录下。至此完成了FCKeditor在线文本编辑器环境的配置,接下来通过俩种方式在myFCKeditor项目中实现对FCKeditor在线文本编辑器的调用。
1)JavaScript语言直接调用
在myFCKeditortest/WebRoot目录下新建一个叫JavaScript1.jsp的JSP页面,代码如下:
<span style="font-family:SimSun;font-size:24px;"><%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<head>
<title>通过JavaScript语言调用</title>
<!-- 引入外部的js文件 -->
<script type="text/javascript" src="fckeditor/fckeditor.js">
</script>
</head>
<body>
<h1>通过JavaScript语言调用</h1>
<!-- 调用FCKeditor在线文本编辑器 -->
<script type="text/javascript">
var oFCKeditor = new FCKeditor('FCKeditor1');
oFCKeditor.BasePath = "/myFCKeditortest/fckeditor/";
oFCKeditor.Create();
</script>
</body>
</html></span>
2)标签<textarea>调用FCKeditor
在myFCKeditortest/WebRoot目录下新建一个叫JavaScript2.jsp的JSP页面,代码如下:
<span style="font-family:SimSun;font-size:24px;"><%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<head>
<title>通过JavaScript语言调用</title>
<!-- 引入外部的js文件 -->
<script type="text/javascript" src="fckeditor/fckeditor.js">
</script>
<!-- 引入网页后需要加载的代码 -->
<script type="text/javascript">
window.onload = function()
{
var oFCKeditor = new FCKeditor('MyTextarea');
oFCKeditor.BasePath = "/myFCKeditortest/fcked itor/";
oFCKeditor.ReplaceTextarea();
}
</script>
</head>
<body>
通过JavaScript语言调用
<textarea name="MyTextarea">测试语言</textarea>
</body>
</html></span>
3、利用JSP标签调用FCKeditor在线文本编辑器
由于JSP技术是服务器端的编程技术,在具体使用时需要连接服务器,所以需要引进
fckeditor-java-2.4-bin文件中的类来配置开发环境,具体架包如下图所示:
新建JSP.jsp,具体代码如下:
<span style="font-family:SimSun;font-size:24px;"> <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!-- 引入标签库 -->
<%@ taglib uri="http://java.fckeditor.net" prefix="FCK"%>
<html>
<head>
<title>通过JSP页面中的自定义标签来调用FCKeditor在线文本编辑器 </title>
</head>
<body>
通过JSP页面中的自定义标签来调用FCKeditor在线文本编辑器
<!-- 设置FCK标签 -->
<FCK:editor instanceName="editorDefault" basePath="/fckeditor"
value="测试代码"></FCK:editor>
</body>
</html></span>
<span style="font-family:SimSun;font-size:24px;"> 将项目myFCKeditortest发布到服务器上,打开浏览器,在地址栏中输入:http://localhost:8080/myFCKeditortest/JSP.jsp。运行结果如下所示:</span>
</pre><pre name="code" class="html"><span style="font-family:SimSun;font-size:24px;"><img src="https://img-blog.csdn.net/20150413170520635" alt="" />
</span>