我去啊,费劲了心思综合了百家之长终于终于,解决了这ueditor 编辑器上传视频的问题,,,,
1 首先是要引入ueditor jsp版本, 可以在官网下载 相应的版本 官网地址:http://ueditor.baidu.com/website/download.html
我这里就下在了
下载完成后可以看到目录结构,
2 接下来就是正题啦,,
因为spring 框架重写了 request 请求,,所以这里呢处理视频上传的方式就通过简单的servlet 类来进行,
贴一下 servlet 的类的实现
package com.byzk.p2p.admin.base.controller;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.baidu.ueditor.ActionEnter;
/**
* Servlet implementation class ControllerServlet
*/
public class ControllerServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ControllerServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setHeader("Content-Type", "text/html");
String rootPath = request.getSession().getServletContext().getRealPath("/");
String jsonFilePath = rootPath + "static/script/ueditor/config.json";
response.getWriter().write(new ActionEnter(request,rootPath,jsonFilePath).exec());
}
}
注意config.josn 的位置对应相应的存放地址,,
3 , 需要引入ueditor 相关的架包 ,,第一步下载的jsp版本的ueditor 就已经友好的提供了,,在lib 目录下,,把除了 ueditor-1.1.3.jar 包之外的架包都引入项目当中 因为这要运行这个servlet 需要用重写后的架包 , 重写的方式是参考了这位大神的博客 http://doc.okbase.net/swtjavaspace/archive/251972.html
为了大家方便 重写后的架包的下载地址为:https://pan.baidu.com/s/1jIHnQAi 下载完成后把架包引入,
4 ,需要配置一下web.xml 文件,使可以成功的加载的上传的控制类,
配置如下
<servlet>
<servlet-name>upload</servlet-name>
<servlet-class>com.byzk.p2p.admin.base.controller.ControllerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>upload</servlet-name>
<url-pattern>/ueditor/upload</url-pattern>
</servlet-mapping>
5,配置完成后,后端的配置就做完了,接下来就是需要在前端引用的时候,定位分发的这个上传类,
前端需要引入三个ueditor 相关的js 文件
<script type="text/javascript" charset="utf-8" src="${_js}/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="${_js}/ueditor/ueditor.all.js"> </script>
<script type="text/javascript" charset="utf-8" src="${_js}/ueditor/ueditor.all.js"> </script>
编写相关代码如下:
UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
UE.Editor.prototype.getActionUrl = function(action) {
if (action == 'uploadvideo') {
return 'http://'+window.location.host+'/ueditor/upload?action='+action;
} else {
return this._bkGetActionUrl.call(this, action);
}
}
这样就完成了前端的配置,,接下来就可以愉快的玩耍一下试试啦,,
完成后的效果截图,