1. http://ueditor.baidu.com/website/index.html 下载包
2.解压然后放入自己项目目录
3.
<script type="text/javascript">
window.UEDITOR_HOME_URL="${jspPath}/js/editor/"; //指向根目录 初始化对象
</script>
4.
<script type="text/javascript" src="${jspPath}/js/editor/editor_all.js"></script>
<script type="text/javascript" src="${jspPath}/js/editor/editor_config.js"></script>
<link rel="stylesheet" href="${jspPath}/js/editor/themes/default/css/ueditor.css">
<textarea id="summarys" rows="15" cols="120" name="summarys" onclick="testedior('summarys')">${summary}</textarea>
<script type="text/javascript">
function testedior(id){
new UE.ui.Editor({
toolbars:[['fullscreen', 'source', '|', 'undo', 'redo', '|',
'bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch','autotypeset','blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist','selectall', 'cleardoc', '|',
,'lineheight','|', 'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|','indent', '|',
'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|','touppercase','tolowercase','|',
'link', 'unlink', 'anchor', '|','imagecenter', '|','insertimage','pagebreak', '|',
'horizontal', 'date', 'time', 'spechars', '|','inserttable', 'deletetable', '|', 'preview','help']],
initialFrameWidth:950,//宽度
theme:"default", //皮肤
autoFloatEnabled:false,//工具栏不随着浏览器的滚动漂浮
autoHeightEnabled:false,//内容不自动增高
lang:'zh-cn' //语言
}).render(id);
}
</script>
5.
上传图片需要修改配置editor_config.js
里面的路径
//图片上传配置区
,imageUrl:URL+"file!bdupload.action?_charset_=utf-8" //图片上传提交地址
,imagePath:"" //返回是网络地址直接为空
,imageFieldName:"filedata" //图片数据的key,若此处修改,需要在后台对应文件修改对应参数
//,compressSide:0 //等比压缩的基准,确定maxImageSideLength参数的参照对象。0为按照最长边,1为按照宽度,2为按照高度
//,maxImageSideLength:900 //上传图片最大允许的边长,超过会自动等比缩放,不缩放就设置一个比较大的值,更多设置在image.html中
java
/**
* 新编辑器
* @return
* @throws Exception
*/
public String bdupload() throws Exception{
admin=(Admin)ServletActionContext.getRequest().getSession().getAttribute("admin");
ServletActionContext.getResponse().setContentType("text/html; charset=utf-8");
String path1="";
int nid=admin.getAdid();
if(filedata!=null){
path1 = fileService.newuploadPicture(filedata, filedataFileName, new int[] {550, 150},15,nid);
}
String json="{\"title\":\"tt\",\"state\":\"SUCCESS\",\"url\":\""+path1+"\"}";
try {
ServletActionContext.getResponse().getWriter().write(json);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}