日期:2014-05-17  浏览次数:20597 次

文件上传 为什么拿不到文件
前台:
<form id="orderForm" encType="multipart/form-data"  action="create.ered" method="post">
<td>
<input type="text" class="text deliveryCorp" name="shippingFaces[0].deliveryCorp" />
</td>
<td>
<input type="text" class="text shippingMethod" name="shippingFaces[0].shippingMethod" />
</td>
<td>
<input type="file" class="file" name="shippingFaces[0].file" />
</td>
</form>

后台:
for(ShippingFace shippingFace : shippingFaces) {
System.out.println(shippingFace.getShippingMethod()); //有值
System.out.println(shippingFace.getFile()); // 为null
this.shippingFaceService.uploadFile(shippingFace);
}

shippingFace的其它两个属性都有值,为什么上传的这个文件没有值、、、?
实本:
/** 配送方式 */
private String shippingMethod;
/** 物流公司 */
private String deliveryCorp;
/** 文件 */
private MultipartFile file;

------解决方案--------------------
文件上传时,<input type="file" name="file"/>,则在Action中必须有一下三个属性:
private File file;
private String fileFileName;
private String fileContentType;
分别添加对应的get和set方法