ueditor version : 1.4.32


web项目名为home,在项目的根路径下创建文件夹ue,ue下面存放UEditor的文件。

在ue下面放置了自定义的用于测试的ueditor.html文件,改文件定义如下

<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title>ueditor demo</title>
    <script type="text/javascript" src="../js/jquery-2.2.0.min.js" ></script>
    <!-- 配置文件 -->
    <script type="text/javascript" src="ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="ueditor.all.js"></script>
    <script>
     $(function(){
      //实例化编辑器 
      var ue = UE.getEditor('container');
     })
    </script>
</head>
<body>
 <form action="/submit.action" method="get">
     <textarea id="container" name="contents">UEditor Demo</textarea>
     <input type="submit" value="submit" />
 </form>
</body>
</html>


 创建如下的一个Handler

@RequestMapping("/ue/upload.action")
 public void upload(HttpServletRequest request,HttpServletResponse response) throws IOException{
  request.setCharacterEncoding( "utf-8" );
  response.setHeader("Content-Type" , "text/html");
  String rootPath = PathUtil.ROOT_PATH ;
  log.debug("UEditor 上传,rootPath:{}",rootPath);
  ActionEnter action = new ActionEnter(request, rootPath ) ;
  String res = action.exec() ;
  log.debug("UEditor 上传操作结果:{}",res);
  response.getWriter().print(res);
 }


在ueditor.config.js里面修改serverUrl配置,格式 serverUrl: URL + "upload.action"。这个路径是UE在上传操作时候的请求路径。

注:这里的URL变量UEditor会自动设置为UE编辑器所在页面的路径。由于这里UE编辑器所在页面为ue下的ueditor.html中,所以URL为...../ue


修改config.json里面的p_w_picpathUrlPrefix 和 p_w_picpathPathFormat 值。如下:
"p_w_picpathUrlPrefix": "/home",
"p_w_picpathPathFormat": "/ue/upload/p_w_picpath/{yyyy}{mm}{dd}/{time}{rand:6}",


要让UE编辑器能使用上传的功能,我们需要保证访问以下地址能成功的返回正确的Json数据
http://localhost:8080/home/ue/upload.action?action=config

其数据格式(部分内容):

{"videoMaxSize":102400000,"videoActionName":"uploadvideo","fileActionName":"uploadfile","fileManagerListPath":"/home/ueditor/jsp/upload/file/","p_w_picpathCompressBorder":1600,"p_w_picpathManagerAllowFiles":[".png",".jpg",".jpeg",".gif",".bmp"],"p_w_picpathManagerListPath":"/home/ueditor/jsp/upload/p_w_picpath/","fileMaxSize":51200000,"fileManagerAllowFiles":[".png",".jpg",".jpeg",".gif",".bmp",".flv",".swf",".mkv",".avi",".rm",".rmvb",".mpeg",".mpg",".ogg",".ogv",".mov",".wmv",".mp4",".webm",".mp3",".wav",".mid",".rar",".zip",".tar",".gz",".7z",".bz2",".cab",".iso",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".pdf",".txt",".md",".xml"],"fileManagerActionName":"listfile","snapscreenInsertAlign":"none","scrawlActionName":"uploadscrawl","videoFieldName":"upfile","p_w_picpathCompressEnable":true,"videoUrlPrefix":"","fileManagerUrlPrefix":"","catcherAllowFiles":[".png",".jpg",".jpeg",".gif",".bmp"],"p_w_picpathManagerActionName":"listp_w_picpath","snapscreenPathFormat":"/ueditor/jsp/upload/p_w_picpath/{yyyy}{mm}{dd}/{time}{rand:6}","scrawlPathFormat":"/home/ue/jsp/upload/p_w_picpath/{yyyy}{mm}{dd}/{time}

由于在UE提供的上传功能的Java代码中,在获取文件信息的时候首先是要获取config.json文件,并且根据处理逻辑会获取请求路径下的config.json文件,这里即为.../home/ue路径下面的config.json文件。但由于该文件实际是放在...home/ue/jsp路径下,所以我将config.json文件拷贝到了..../home/ue下。


至此,配置完成,顺利运行。