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('内容');
      }); 
     
  • 相关阅读:
    【转】常用插件的使用—grunt入门指南(上)
    基于Cordova的android项目入门
    【转】隐藏元素的子元素隐藏无效
    【转】IE7以下绝对定位被某元素遮挡
    关于“No projects are found to import”的解决方法
    【转】IE6中a标签触发图片和ajax请求被abort
    JS小笔记
    mysql删除重复数据
    国内优秀的团队技术博客
    mysql中的union和order by、limit
  • 原文地址:https://www.cnblogs.com/freeatalk/p/10977586.html
Copyright © 2011-2022 走看看