【发布时间】:2014-12-01 11:52:59
【问题描述】:
我的 Spring 应用程序中的多部分文件上传功能遇到问题。我在我的应用程序的其他几个 jsp 文件中使用 struts2.3 标记。在我的 spring 应用程序中将 struts 从 1.2 迁移到 2.3 之前,上传功能运行良好。
我上传的jsp文件中的代码sn-p:
<td nowrap="nowrap">
<input type="file" name="file" class="formElement" size="40"/>
<input name="actionAdd" type="button" class="button" value="Add File to Table" onclick="addFileToTable();"/>
<div id="noFileSelected" style="display:none"><p><span class="error">No File selected.</span> </p></div>
</td>
实现类中的代码块:
multiPartRequest = (MultipartHttpServletRequest) request;
MultipartFile multipartFile = multiPartRequest.getFile("file");
spring 配置文件中的代码
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="500000"/>
</bean>
multiPartRequest.getFile("file") 返回 null。
之前相同的代码块运行良好。
【问题讨论】:
标签: spring file-upload struts2