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('内容');
      }); 
     
  • 相关阅读:
    SQL Server 2008R2 附件数据库问题记录
    关于.NET C#调用Sqlite的总结二
    关于.NET C#调用Sqlite的总结一
    MS Server中varchar与nvarchar的区别
    Intellij IDEA中使用Debug调试
    使用idea关联mysql时报错Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezon'
    学Redis这篇就够了
    java的动态代理机制详解
    mybatis-sql执行流程源码分析
    mybatis
  • 原文地址:https://www.cnblogs.com/freeatalk/p/10977586.html
Copyright © 2011-2022 走看看