没有选择附件,但是点击上传按钮的时候会报错。
之前不选择文件,直接上传空文件是可以的,后来不知道改了什么就不行了。
错误信息:
2014-03-14 17:32:40 [http-8080-1] TRACE org.springframework.beans.TypeConverterDelegate - Field [] isn't an enum value java.lang.NoSuchFieldException: at java.lang.Class.getField(Unknown Source) at org.springframework.beans.TypeConverterDelegate.attemptToConvertStringToEnum(TypeConverterDelegate.java:296) at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:223) at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:111) at org.springframework.beans.TypeConverterDelegate.convertToTypedArray(TypeConverterDelegate.java:461) 省略一部分………… at java.lang.Thread.run(Unknown Source) 2014-03-14 17:32:40 [http-8080-1] TRACE org.springframework.web.method.HandlerMethod - Error resolving argument [2] [type=[Lorg.springframework.web.multipart.MultipartFile;] HandlerMethod details: Controller [com.cvicin.ssm.sys.fileUpload.FileUploadClass] Method [public java.lang.String com.cvicin.ssm.sys.fileUpload.FileUploadClass.hotProductFinance_fileUpload(java.lang.String,java.lang.String,org.springframework.web.multipart.MultipartFile[],javax.servlet.http.HttpServletRequest)] org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String[]' to required type 'org.springframework.web.multipart.MultipartFile[]'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.MultipartFile]: no matching editors or conversion strategy found at org.springframework.beans.SimpleTypeConverter.convertIfNecessary(SimpleTypeConverter.java:58) at org.springframework.validation.DataBinder.convertIfNecessary(DataBinder.java:553) at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:97) at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:75) at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162) 省略一部分………… at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.MultipartFile]: no matching editors or conversion strategy found at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:247) at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:111) at org.springframework.beans.TypeConverterDelegate.convertToTypedArray(TypeConverterDelegate.java:461) at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:178) at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:93) at org.springframework.beans.SimpleTypeConverter.convertIfNecessary(SimpleTypeConverter.java:49) ... 46 more
解决办法:在上传之前判断有没有附件,没有的话就不执行了上传事件了。
页面代码:
<form id="saveFile" method="post" enctype="multipart/form-data"> <div>上传新的附件:</div> <div> <input type="file" name="file" /> <input type="file" name="file" /> <input type="file" name="file" /> <input type="file" name="file" /> <input type="file" name="file" /> </div> </form>
js代码:
var fileFlag = false; $("input[name=file]").each(function(){ if($(this).val()!="") { fileFlag = true; return false; } }); if(fileFlag) { var url = "${pageContext.request.contextPath}/fileUpload/fileUpload"; $("#saveFile").ajaxSubmit({//执行上传 url:url, success:function(msg){ // } }); }
其实就是jquery选择器,遍历name = file是不是空值。
记下了,省的以后忘了。。。 o(╯□╰)o