日期:2014-05-20 浏览次数:20878 次
<form name="myform" method="post" action="add.action" enctype="multipart/form-data"> <input type="text" name="user" /><input type="file" name="pic" /> <input type="text" name="user" /><input type="file" name="pic" /> </form>
private List<File> pic;
private List<String> user;
//对应的getter 和 setter方法略
public String execute(){
//(1)下面种情况,只有当文件域都为空或者都不为空时可用。
for(int i=0;i<user.size();i++){
if(pic!=null){
//上传文件和将user,pic路径信息写入数据库.
}else{
//只将user信息写入数据库.
}
}
//(1)下面种情况,必须文件域都不为空,否则将抛出nullpointexception。
for(int i=0;i<user.size();i++)
if(pic.get(i)!=null){
//上传文件和将user,pic路径信息写入数据库.
}else{
//只将user信息写入数据库.
}
}
private FormFile pic;
------解决方案--------------------
接收用FormFile,试试。 接收不到估计就是这儿的问题
------解决方案--------------------
好像设计上有问题
这样只添一个文件根本判断不出来是属于user的
------解决方案--------------------
属于哪个user的