问答中编辑富文本框中的图片上传不了


1.spring-servlet.xml添加下面的代码

class="com.velcro.base.file.CustomCommonsMultipartResolver"> 
        
            
                /kms/team/thoto/add
                /bbs/fileUpload
                /kms/excel/importExcel
            
        
        
            524288000
         
        
            UTF-8
        
    

2.添加CustomCommonsMultipartResolver类

package com.velcro.base.file;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import java.util.List;

/**
 * 不转换request中的文件流
 * Controller里的request对象是初始时HttpServletRequest的对象。刚开始认为fileList对象不会为空,但是却空。主要原因在于我配置的spring MVC的文件解析器如下:
 
 
 
 关键之处在于CommonsMultipartResolver中的方法parseRequest已经解析过request对象了.
 自定义一个类
 * @author ZamXie
 *
 */
public class CustomCommonsMultipartResolver extends CommonsMultipartResolver {

    private List excludeUrls;

    public void setExcludeUrls(List excludeUrls) {
        this.excludeUrls = excludeUrls;
    }

    public List getExcludeUrls() {
        return excludeUrls;
    }

    @Override
    public boolean isMultipart(HttpServletRequest request) {
        String requestURL=request.getRequestURI();
        if(requestURL.contains(".do")){
            requestURL=requestURL.substring(0,requestURL.indexOf(".do"));
            if(excludeUrls.contains(requestURL)){
                return false;
            }else{
                return super.isMultipart(request);
            }
        }
        return false;
    }

}

参考系统:cyy

相关