zoukankan      html  css  js  c++  java
  • springmvc+ueditor 使用request和response设置上传路径 (个人备忘)

    1.先修改ueditor.config.js下的serverUrl,改成serverUrl: URL + "jsp/config"

    2.Ueidtor会向服务器请求config.json,因为我配置的是jsp/config,所以路径是/plugins/UEditor/jsp/config?action=config

    3.新建一个controller,@RequestMapping("/plugins/UEditor/jsp") ,新建一个方法@RequestMapping("/config"),两个加起来的路径是/plugins/UEditor/jsp/config

    4.方法里头接受参数action,如果"config".equals(action),则response.sendRedirect(request.getContextPath()+"/plugins/UEditor/jsp/config.json");

    5.上传图片和视频action分别是uploadimage和uploadvideo,这两个值可以在config.json查到,分别是imageActionName和videoActionName,controller代码:

    @Controller
    @RequestMapping("/plugins/UEditor/jsp")
    public class UeditorController {
    
    @RequestMapping("/config")
    public void config(String action,HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
    
      if ("config".equals(action)) {
        System.err.println("config");
        response.sendRedirect(request.getContextPath()+"/plugins/UEditor/jsp/config.json");
      }else if("uploadimage".equals(action)) {
        System.err.println("uploadimage 转发到上传路径");
        request.getRequestDispatcher("/fileUploadfile").forward(request, response);
      }else if ("uploadvideo".equals(action)) {
        System.err.println("uploadvideo 转发到上传路径");
        request.getRequestDispatcher("/fileUploadfile").forward(request, response);
      }
    
    }
    
    }

    6.上传完成之后返回的格式

     Map<String, Object> map = new HashMap<String, Object>();
     map.put("state", "SUCCESS");
     //因为手机端用到,所以图片路径包含端口,并使用断点下载 map.put(
    "url",req.getScheme()+"://"+req.getServerName()+":"+req.getServerPort()+req.getContextPath()+ "/downloadfile?id="+fileid); map.put("title", "demo.jpg"); map.put("original", "demo.jpg"); return map ;

    备注:获取文本内容UE.getEditor('editor').getContent()

         回填文本内容:

      var ue = UE.getEditor('editor');
      ue.ready(function() {
          ue.setContent('内容');
      }); 
     
  • 相关阅读:
    windows 物理内存获取
    windbg-.process切换进程(内核)
    cnetos 6.7彻底解决vmware NAT网络问题
    优秀的博客链接地址
    使用Spring MVC统一异常处理实战
    active mq 配置
    socket demo程序
    flume 中的 hdfs sink round 和roll
    软链接与硬链接
    flume A simple example
  • 原文地址:https://www.cnblogs.com/freeatalk/p/10977586.html
Copyright © 2011-2022 走看看