您的位置:首页 > 编程语言 > Java开发

Java Web 通过CKEditor实现在线编译器

2016-04-01 22:45 393 查看
1、CKEditor的下载

2、CKEditor的创建

(1)将下载的ckeditor复制到Web工程的WebRoot下

(2)创建jsp页面或者HTML页面,在页面中导入ckeditor.js文件,通过<script type="text/javascript" src="ckeditor/ckeditor.js">
</script>导入,创建textarea元素,将其class属性设置为ckeditor。

3、CKEditor的配置

CKEditor的配置都集中在ckeditor/config.js文件中。

可以在{}中对CKEditor进行配置,常用的参数如下

(1)config.language:界面语言,常见取值'en','zh-cn'。

(2)config.width,config.height:编辑器的宽度和高度,以像素为单位。

(3)config.skin:编译器样式,取值有3个——'kama'(默认)、'office2003'、'v2'。

(4)config。UIColor:编译器背景颜色。

(5)config.toolbar:定义工具栏,有基础'Basic'、全能'Full'、自定义3个取值

案例——使用CKEditor编译器公告内容

1、公告编辑界面

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

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

<title>Insert title here</title>

</head>

<body>
<center>
<form action="show.jsp" method="post">
编辑公告内容<textarea class="ckeditor" name="newsBody" rows="80" cols="10"></textarea>

<input type="submit" value="显示公告内容">
</form>
</center>

</body>

</html>

2、公告显示界面

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>

</head>

<body>
<% request.setCharacterEncoding("UTF-8"); %>
<%=request.getParameter("newsBody") %>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: