SpringMVC中servletFileUpload.parseRequest(request)解析为空获取不到数据问题
2017-06-26 15:02
489 查看
下面是文件接收的方法,其中List<FileItem> items为空,获取不到上传文件。
经过查找资料,分析后,发现在springmvc的配置文件中有这样一段代码:
这两种分别是两种上传文件的设置方式,但是不能同时使用。切记。
把这个配置删除测试发现问题解决。
如果你想使用springmvc的文件上传方式,只需要后台接收的方法这么写:
亲测好使。
@RequestMapping(value = "/imagedetect", method = { RequestMethod.POST}) @ResponseBody public Object imagedetect(ModelMap model, HttpServletResponse response) throws IOException { logger.info("检测任务开始====" + DateUtil.getCurrentTime()); HttpServletRequest request=CommonUtil.getRequest(); String access_token = request.getParameter("access_token"); String url = request.getParameter("image"); String tag = request.getParameter("tag"); Object obj = new Object(); //判断该请求是否有上传文件 if(ServletFileUpload.isMultipartContent(request)) { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); try { List<FileItem> items = upload.parseRequest(request); for(FileItem item: items) { } } catch (FileUploadException e) { e.printStackTrace(); } }else{ } }
经过查找资料,分析后,发现在springmvc的配置文件中有这样一段代码:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="UTF-8" /> <property name="maxUploadSize" value="104857600"/> <property name="maxInMemorySize" value="4096"/> </bean>
这两种分别是两种上传文件的设置方式,但是不能同时使用。切记。
把这个配置删除测试发现问题解决。
如果你想使用springmvc的文件上传方式,只需要后台接收的方法这么写:
@RequestMapping(value = "imagedetectufile", method = { RequestMethod.POST }) @ResponseBody public Object detectPictureTask( @RequestParam(value = "image", required = false) MultipartFile file[], ModelMap model, HttpServletResponse response) throws IOException { //业务逻辑。。。 //............ }
亲测好使。
相关文章推荐
- SpringMVC中servletFileUpload.parseRequest(request)解析为空获取不到数据问题
- SpringMVC中servletFileUpload.parseRequest(request)解析为空获取不到数据问题
- kindeditor上传文件在SpringMVC中servletFileUpload.parseRequest(request)解析为空获取不到数据问题 .
- SpringMVC中servletFileUpload.parseRequest(request)解析为空获取不到数据问题
- SpringMVC中servletFileUpload.parseRequest(request)解析为空获取不到数据问题
- SpringMVC中servletFileUpload.parseRequest(request)解析为空获取不到数据问题
- SpringMVC中servletFileUpload.parseRequest(request)解析为空获取不到数据问题
- servletFileUpload.parseRequest(request)解析为空获取不到数据问题
- SpringMVC中servletFileUpload.parseRequest(request)解析为空获取不到数据问题
- springMvc 完美解决 multipart/form-data 方式提交请求 在 Filter 中 ServletRequest.getParameter方法 获取不到参数的问题
- springMvc 完美解决 multipart/form-data 方式提交请求 在 Filter 中 ServletRequest.getParameter方法 获取不到参数的问题
- Controller中servletFileUpload.parseRequest(request)解析为空
- SpringMVC中servletFileUpload.parseRequest(request)解析为空获取不到数据问题
- springMvc 完美解决 multipart/form-data 方式提交请求 在 Filter 中 ServletRequest.getParameter方法 获取不到参数的问题
- 使用bootstrap-fileinput的问题:上传时upload.parseRequest(request)得到的List为空
- struts接收url文件使用upload.parseRequest 获取文件为空的问题
- servletFileUpload.parseRequest(request)报错解决办法
- struts1.2中ActionForm和ServletFileUpload.parseRequest(request)不能同时使用
- MultipartHttpServletRequest,ajaxFileUpload上传文件,读取文件乱码问题
- 关于SpringMVC中json数据request获取不到和bean获取为null