springboot使用百度富文本UEditor遇到的问题一览(springboot controller中request.getInputStream无法读取)

先吐槽一下UEditor作为一个前端的js类库,非要把4种后端的代码给出来,而实际生产中用的框架不同,其代码并不具有适应性。(通常类似其它项目仅仅是给出数据交互的规范、格式,后端实现就可以自由定制)

接下来还是说各种问题把

1.首先下载其jsp的版本...

然而我并没有用jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    import="com.baidu.ueditor.ActionEnter"
    pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%

    request.setCharacterEncoding( "utf-8" );
    response.setHeader("Content-Type" , "text/html");
    
    String rootPath = application.getRealPath( "/" );
    
    out.write( new ActionEnter( request, rootPath ).exec() );
    
%>

改成springmvc的controller版本

@ResponseBody
    public String config(HttpServletRequest request){
        String rootPath=request.getServletContext().getRealPath("/");
        return new ActionEnter( request, rootPath+"static\\javascript\\plugins\\UEditor\\" ).exec();
    }

对应项目config.json存放位置

2.记得要把给的lib下的包导入

3.项目加载上传显示找不到上传数据

好!想都不用想,lib下ueditor-1.1.2.jar包妥妥的写死了 妥妥的冲突了

查看源码可知是通过request.getInputStream读取的,而controller中request.getInputStream并不能读取

经过大量debug模式断点调试和查看springboot文档

springboot会默认加载一个HiddenHttpMethodFilter,其request.getParameter方法会读取流,导致之后读取不了

在配置类中手动配置一个HiddenHttpMethodFilter的bean

    @Bean
    public HiddenHttpMethodFilter hiddenHttpMethodFilter() {
        return new OrderedHiddenHttpMethodFilter(){
            @Override
            protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
                    throws ServletException, IOException {
                filterChain.doFilter(request, response);
            }
        };
    }

发现一般的表单数据可以获取到有内容的inputStream,而文件依旧不行

于是乎,继续debug Orz

 

springboot还有个默认加载的MultipartResolver实现类为StandardServletMultipartResolver,会对request进行一个包装(见上图),request.getParts方法也是会读取inputStream


网上找到的解决方法中重写了ueditor-1.1.2.jar的BinaryUploader类,原因讲的不清,实现感觉也不是很好(并没读配置),准备自己写一个,未完待续

 

posted on 2016-10-24 11:08  幽魂步  阅读(15726)  评论(1)    收藏  举报

导航