当在上传表单中设置了enctype="multipart/form-data"
时post传过去的字符串的值为null,会报HTTP Status 400 - Required String parameter 'description' is not present
错误。
解决方案:
1、首先在pom.xml中添加
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.2</version>
</dependency>
然后在applicationContext.xml中添加即可解决,这样的话spring会对表单的数据进行处理,就算使用了enctype="multipart/form-data"进行传值也能拿到数据
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8"></property>
<property name="maxUploadSize" value="10485760000"></property>
<property name="maxInMemorySize" value="40960"></property>
</bean>