MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;类型转换异常问题

	String root = request.getParameter("root");
		// 先实例化一个文件解析器
        CommonsMultipartResolver coMultipartResolver = new CommonsMultipartResolver(request.getSession()
                .getServletContext());

        // 判断request请求中是否有文件上传
        if (coMultipartResolver.isMultipart(request)) {
            // 转换request
            MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
            // 获得文件
            MultipartFile file = multiRequest.getFile("Filedata");
            if(!file.isEmpty()){
            	resourceMng.saveFile(root, file);
            }
        }
		request.setAttribute("root", root);
		
		ResponseUtils.renderText(response, "");
		return null;
	}
上传文件时,
MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;

报错类型转换异常,原来是需要在Spring的配置文件进行如下配置:


	  
       
         
    

你可能感兴趣的:(工程)