Ueditor是百度公司推出的一个富文本编辑器,首先打开ueditor官网https://ueditor.baidu.com/website/index.html,进入官网下载相对应的语言,我以Jsp为例,下载Jsp源码。
下载之后解压,在项目新建一个文件夹,将解压的东西copy到项目新建的文件夹里。
在/jsp/lib文件夹下会有些jar包的,把这些jar直接复制,放到项目的lib文件夹下
以下是项目的lib文件夹
接下来需要改些配置文件,打开/ueditor/ueditor.config.js,配置资源所在根目录,testupload是我的项目名称,后面那个是我存放ueditor的文件夹。
再打开config.json文件,在ueditor的jsp目录下,主要修改两个地方,第一个:imageUrlPrefix,这个默认是空,需要填写上你的项目名,否则上传图片的时候,只显示图片名称,不显示图片。第二个:imagePathFormat,是上传图片存放的项目路径,我存放在项目的upload项目下,后面那一串是生成的图片名称,可以不用改。
最后,开始编写jsp页面,在ueditor拉入三个js文件
<script type="text/javascript" src="${ctx}/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="${ctx}/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="${ctx}/ueditor/lang/zh-cn/zh-cn.js"></script>
再编写HTML代码
<form action="${ctx}/CourseRelease/insert.do" method="post">
<div>
<textarea name="content" id="editor" style="width:60%;height:60%;"></textarea>
<button type="submit">看看</button>
</div>
</form>
最后实例化编辑器
<script type="text/javascript">
//实例化编辑器
var ue = UE.getEditor('editor');
</script>
最后效果图如下