百度富文本JSP版本
引入后打开ueditor.config.js
添加获取服务器地址
var server_url = window.location.protocol+"//"+window.location.hostname+":"+window.location.port;
替换服务器地址
// 服务器统一请求接口路径
serverUrl: server_url + "/config"
我采用的动态加config.json
后端代码
@RequestMapping(value = "/config")
public void config(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "text/html");
//静态资源文件
ClassPathResource classPathResource = new ClassPathResource("/static/ajax/libs/ueditor/jsp/config.json");
StringBuilder builer = new StringBuilder();
InputStream inputStream = classPathResource.getInputStream();
try {
InputStreamReader reader = new InputStreamReader(classPathResource.getInputStream(), "UTF-8");
BufferedReader bfReader = new BufferedReader(reader);
String temContent = null;
while ((temContent = bfReader.readLine()) != null) {
builer.append(temContent);
}
log.info("读取的config.json文件====" + builer.toString());
String exec = builer.toString().trim();
log.info("读取的exec====" + builer.toString());
PrintWriter writer = response.getWriter();
writer.write(exec);
writer.flush();
writer.close();
bfReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
html代码
<script id="container" type="text/plain">
</script>
jsp页面 初始化 并配置上传图片地址
var ue = UE.getEditor('container');
//建议使用工厂方法getEditor创建和引用编辑器实例,
UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
UE.Editor.prototype.getActionUrl = function(action) {
if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadimage') {
return '/common/uploadu'; //对应后台上传图片的方法
} else if (action == 'uploadvideo') {
return '/common/uploadVideou'; //对应后台上传视频的方法
} else {
return this._bkGetActionUrl.call(this, action);
}
大功告成