简体   繁体   English

在Spring 2.5中使用MultipartFile上传文件中的null值

[英]null value in file upload by using MultipartFile in spring 2.5

I am stucked to something. 我被困在某事上。 In spring 2.5 framework, I want to upload file by using MultipartFile. 在Spring 2.5框架中,我想使用MultipartFile上传文件。 I have a class called Dosya including property which is MultipartFile multiDosya. 我有一个名为Dosya的类,其中包括MultipartFile multiDosya属性。 My command object is dosya. 我的命令对象是dosya。 Additonally, The file which will be uploaded is stored BLOB type in database, sql developer,. 此外,将要上载的文件存储在数据库SQL Developer中的BLOB类型。 In jsp, I try to bind this propert like below: 在jsp中,我尝试如下绑定此属性:

<spring:bind path="dosya.multiDosya">
  <input class="file" type="file" name="yuklenecekDosya" id="yuklenecekDosya" />
</spring:bind>

In onSubmit, 在onSubmit中,

 Dosya dosyaObjesi = (Dosya)command;
 MultipartFile yuklenecekDosya = dosyaObjesi.getMultiDosya();

The commandObject dosyaObjesi is taken without problem, however, 可以毫无问题地使用commandObject dosyaObjesi,但是,

dosyaObjesi.getMultiDosya()

value is coming null although file that will be uploaded is selected in jsp. 尽管在jsp中选择了要上载的文件,但值仍为null。

After searching on the net, I found that this line below should be added to the initBinder. 在网上搜索后,我发现下面的这一行应添加到initBinder中。

 binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());

However, my class says that there is no such class ByteArrayMultipartFileEditor, but it is available in spring-2.5.jar. 但是,我的班级说没有此类ByteArrayMultipartFileEditor,但在spring-2.5.jar中可用。 I import 我汇入

import org.springframework.web.multipart.*;

can trace out the problem . 可以找出问题所在。 could someone please help me out 有人可以帮我吗

Thanks in advance. 提前致谢。

Have you specified form encryption type(enctype="multipart/form-data")?. 您是否指定了表单加密类型(enctype =“ multipart / form-data”)? That could be the reason sometimes. 有时可能是原因。

Ex: 例如:

<form method="post"  name="formName" action="action.htm" commandName="object" enctype="multipart/form-data">

I have solved the problem. 我已经解决了问题。 Everything is ok, however, in the code below 一切正常,但是,在下面的代码中

<input class="file" type="file" name="yuklenecekDosya" id="yuklenecekDosya" />

the attribute name must be ${status.expression} . 属性名称必须为${status.expression} That is, exactly, name="${status.expression}" like that. 也就是说,就是这样的name="${status.expression}" If only the name property value is given like that, bind operation works correctly. 如果仅给出name属性值,则绑定操作将正常工作。 Thanks, Regards, 感谢和问候,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 上传文件时,Spring REST MultipartFile文件始终为null - Spring REST MultipartFile file is always null when do upload file Spring MultipartFile上传文件位置 - Spring MultipartFile upload file location 使用Spring MultipartFile和谷歌应用引擎上传文件 - upload a file using spring MultipartFile and google app engine 对于大于 150kb 的文件上传请求参数为 null,使用 multipartfile 上传,Spring 3.2,wildfly 9.0.0 - request parameters null for file upload greater than 150kb with multipartfile upload, Spring 3.2, wildfly 9.0.0 Spring 引导 MultipartFile 的值始终为 null - Spring Boot MultipartFile always has value of null Spring REST MultipartFile文件始终为null - Spring REST MultipartFile file is always null Spring 3.0 MultipartFile上传 - Spring 3.0 MultipartFile upload 使用MultipartFile的多个文件上传在Spring Boot中不起作用,从JSP在Controller中获取空数组 - Multiple file upload using MultipartFile not working in Spring Boot , getting empty array in Controller from JSP Spring + ExtJS 文件上传所需的 MultipartFile 参数“文件”不存在 - Spring + ExtJS File Upload Required MultipartFile parameter 'file' is not present 使用spring将File转换为MultiPartFile - Converting File to MultiPartFile with spring
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM