当前位置: 移动技术网 > IT编程>开发语言>Java > JSP 页面中使用FCKeditor控件(js用法)

JSP 页面中使用FCKeditor控件(js用法)

2017年12月12日  | 移动技术网IT编程  | 我要评论

它可和php、javascript、asp、asp.net、coldfusion、java、以及abap等不同的编程语言相结合。“fckeditor”名称中的“fck” 是这个编辑器的作者的名字frederico caldeira knabben的缩写。

fckeditor控件请到官方网站下载,本例主要用到fckeditor_2.6.3.zip、fckeditor-java-demo-2.4.1.zip、fckeditor-java-2.4.1-bin.zip里面的一些内容,读者可以自行下载。

1. 解开压缩包fckeditor_2.6.3.zip,将其中的fckeditor文件夹复制到web-inf下面,后面可以直接使用。

2. 在页面中使用fckeditor有两种方式。

方式一:javascript的方式

(1)直接使用,见method1.html

<!doctype html public "-//w3c//dtd html 4.01 transitional//en">
<html>
<head>
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
</head>
<body>
方法一:通过javascript来实现的实现编辑器导入<br>
<script type="text/javascript">
var ofckeditor = new fckeditor('fckeditor1') ;
ofckeditor.basepath = "fckeditor/";
//ofckeditor.basepath   = "/fckedittest/fckeditor/";
ofckeditor.width="50%";
ofckeditor.height="400";
ofckeditor.value="initial value";
//ofckeditor.toolbarset="basic";
//默认是default
ofckeditor.toolbarset="default";
ofckeditor.create() ;
</script>
<hr>
</body>
</html>

(2)通过textarea,祥见method2.html

<!doctype html public "-//w3c//dtd html 4.01 transitional//en">
<html>
<head>
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
<script type="text/javascript">
window.onload=function(){
var ofckeditor = new fckeditor('mytextarea') ;
ofckeditor.basepath = "fckeditor/"; //这里注意相对路径
//ofckeditor.basepath   = "/fckedittest/fckeditor/";
ofckeditor.replacetextarea();
}
</script>
</head>
<body>
方法二:通过textarea来实现的实现编辑器导入<br>
<textarea rows="4" cols="60" name="mytextarea">this is a value</textarea>
</body>
</html>

方式二:在标签使用fckeditor

在使用标签之前,需要搭建环境。将fckeditor-java-2.4.1-bin.zip包中的fckeditor-java-core-2.4.1.jar、commons-fileupload-1.2.1.jar、commons-io-1.3.2.jar、slf4j-api-1.5.2.jar以及包fckeditor-java-demo-2.4.1.zip中的slf4j-simple-1.5.2.jar复制到lib目录下,并构建环境。

构建完后,就可以在jsp页面中进行使用。祥见页面method_jsp.jsp

<%@ page language="java" import="java.util.*" pageencoding="utf-8"%>
<%@ taglib uri="http://java.fckeditor.net" prefix="fck"%>
<!doctype html public "-//w3c//dtd html 4.01 transitional//en">
<html>
<head>
<title>method_jsp.jsp</title>
</head>
<body>
早些版本必需将fckeditor的value属性必需指定对应的值,且值不能为空。
而此处版本是2.6.3,该问题已经解决。
<fck:editor instancename="myeditor" basepath="/fckeditor"></fck:editor>
</body>
</html>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网