整合ueditor步骤(这里使用的1.1.2版本的ueditor)
1.在jsp页面中引入相关的文件
<!-- 富文本编辑器引入文件 -->
<script type="text/javascript" src="../ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="../ueditor/ueditor.all.js"></script>
2.下载ueditor,解压后将ueditor目录复制到自己项目路径下
3.创建编辑器实例及其DOM容器,先在jsp页面中添加一个<textarea>容器,再用脚本创建ueditor编辑器
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/common/header.jsp" %>
<!-- 富文本编辑器引入文件 -->
<script type="text/javascript" src="../ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="../ueditor/ueditor.all.js"></script>
<style>
body {
background: #f0f4ff;
}
</style>
<body style="width:95%;height:100% ;overflow:auto">
<div style="padding:10px 10px 20px 10px">
<form id="actionform" method="post">
<table cellpadding="5" style="font-size: 14px">
<tr>
<td>新闻内容:</td>
<td><textarea name="news" id="news"></textarea></td>
</tr>
</table>
</form>
</div>
</body>
<script>
//ueditor编辑器
UE.getEditor('news');
</script>
<!-- 富文本编辑器引入文件 -->
<script type="text/javascript" src="../ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="../ueditor/ueditor.all.js"></script>
<style>
body {
background: #f0f4ff;
}
</style>
<body style="width:95%;height:100% ;overflow:auto">
<div style="padding:10px 10px 20px 10px">
<form id="actionform" method="post">
<table cellpadding="5" style="font-size: 14px">
<tr>
<td>新闻内容:</td>
<td><textarea name="news" id="news"></textarea></td>
</tr>
</table>
</form>
</div>
</body>
<script>
//ueditor编辑器
UE.getEditor('news');
</script>
这里需要注意的是红色字体标示的部分,这么写可以解决ueditor工具栏被悬置在页面顶端无法下来的问题,如下图所示:
4.做到这里ueditor还没有配置完成,还需要在pom.xml中加载ueditor的依赖,先运行整合ueditor的页面,可看到后台报错如下:
现在在pom.xml中加载ueditor的依赖jar包:
<!-- 添加Ueditor依赖 -->
<dependency>
<groupId>com.baidu</groupId>
<artifactId>ueditor</artifactId>
<version>1.1.2</version>
</dependency>
5.到这里,ueditor基本配置完成,这里再介绍可能遇到的问题:
后台报org.json.JSONObject找不到类的错误,只需要在pom.xml中添加其依赖即可