页面加入ue
<!-- umeditor -->
<script type="text/javascript" charset="utf-8" src="ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="ueditor/lang/zh-cn/zh-cn.js"></script>
<div class="form-group">
<script id="editor" type="text/plain" style="width:720px;height:300px;margin: 0px auto;"></script>
</div>
配置ue
// 参考:/gfmsM/src/main/webapp/tpl/activityDialog.html
<script type="text/javascript">
//实例化编辑器
var ue = new UE.ui.Editor();
ue.render("editor");
ue.addListener("ready", function() {
var id = getSelectedId();
var contentValue="";
// 设置内容,是否追加
ue.setContent(contentValue, false);
});
</script>
rootPath=D:/apache-tomcat-6.0.43/webapps/gfmsM/
savePath=../../../images/server/1453862540713001502.png
physicalPath=D:/apache-tomcat-6.0.43/webapps/gfmsM/../../../images/server/1453862540713001502.png
实际保存路径:D:/images/server/1453862540713001502.png
回显请求地址:http://localhost:8888/gfmsM/../../../images/server/1453862540713001502.png
除去干扰字段:http://localhost:8888/gfmsM/images/server/1453862540713001502.png
// 基于当前项目根路径
// 项目路径: D:\apache-tomcat-6.0.43\webapps\gfmsM\
// 保存路径:../../../images/server/1453862540713001502.png
// 图片物理路径:D:\images\server
// 保存路径:../../images/server/1453862540713001502.png
// 图片物理路径:D:\apache-tomcat-6.0.43\images\server
修改位置:
保存时不需要修改,这里修改只是回显给页面加载的地址,
页面要根据 /gfmsM/src/main/webapp/ueditor/jsp/config.json 中的
"imageUrlPrefix": "http://localhost:8888/gfmsM/", /* 图片访问路径前缀 */ + 返回的url去取图片
所以要将../../../../../去除
正常的访问图片的路径应该是 "http://localhost:8888/gfmsM/images/server/1453862540713001502.png
图片是要存放在tomcat之外的文件,所以要在tomcat中做一个映射,访问tomcat之外的文件
<Context docBase="D:\images\server" path="/gfmsM/images/server" reloadable="true"/>
path对应的是访问url中的/gfmsM/images/server,根据不同项目将gfmsM替换即可,docBase即是图片物理路径
1./gfmsM/src/main/java/com/baidu/ueditor/upload/BinaryUploader.java
if (storageState.isSuccess()) {
//将返回的url做截取
storageState.putInfo("url",PathFormat.format(savePath.split("../../../../../")[1]));
storageState.putInfo("type", suffix);
storageState.putInfo("original", originFileName + suffix);
}
2./gfmsM/src/main/java/com/baidu/ueditor/upload/Base64Uploader.java
if (storageState.isSuccess()) {
//将返回的url做截取
storageState.putInfo("url", PathFormat.format(savePath.split("../../../../..//")[1]));
storageState.putInfo("type", suffix);
storageState.putInfo("original", "");
}