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

来源:互联网 发布:洛天依黑暗五部曲 知乎 编辑:程序博客网 时间:2024/05/22 15:52

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>

0 0
原创粉丝点击