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

jsp struts2一次上传多张图片
<s:file name="file"></s:file> 这个一次只能一次选中一次上传图片
要是想上传多张图片就要用多个这个标签  但是这样不好看 也不知道别人要上传几张的 怎么用这么一个标签 上传多张图片呢
要是有案例能不能发我 邮箱 623594768@qq.com 谢谢
------解决方案--------------------
利用网上的上传组件 楼主google一下
------解决方案--------------------

<html>
<head>
<scriptlanguage="javascript">
functionaddComponent()
{
varuploadHTML=document.createElement("<inputtype='file' name='upload'/>");
document.getElementById("files").appendChild(uploadHTML);
uploadHTML=document.createElement("<p/>");
document.getElementById("files").appendChild(uploadHTML);
}
</script>
</head>
<body>
<inputtype="button"onclick="addComponent();"value="添加文件"/>
<br/>
<formonsubmit="returntrue;"action="/struts2/test/upload.action"
method="post"enctype="multipart/form-data">
<spanid="files"><inputtype='file'name='upload'/>
<p/>
</span>
<inputtype="submit"value="上传"/>
</form>
</body>
</html>



importjava.io.*;
importcom.opensymphony.xwork2.ActionSupport;
publicclassUploadMoreActionextendsActionSupport
{
privatejava.util.List<File>uploads;
privatejava.util.List<String>fileNames;
privatejava.util.List<String>uploadContentTypes;
publicjava.util.List<String>getUploadFileName()
{
returnfileNames;
}
publicvoidsetUploadFileName(java.util.List<String>fileNames)
{
this.fileNames=fileNames;
}
publicjava.util.List<File>getUpload()
{
returnuploads;
}
publicvoidsetUpload(java.util.List<File>uploads)
{
this.uploads=uploads;
}
publicvoidsetUploadContentType(java.util.List<String>contentTypes)
{
this.uploadContentTypes=contentTypes;
}
publicjava.util.List<String>getUploadContentType()
{
returnthis.uploadContentTypes;
}
publicStringexecute()throwsException
{
if(uploads!=null)
{
inti=0;
for(;i<uploads.size();i++)
{
java.io.InputStreamis=newjava.io.FileInputStream(uploads.get(i));
java.io.OutputStreamos=newjava.io.FileOutputStream(
"d:upload"+fileNames.get(i));
bytebuffer[]=newbyte[8192];
intcount=0;
while((count=is.read(buffer))>0)
{
os.write(buffer,0,count);
}
os.close();
is.close();
}
}
returnSUCCESS;
}
}





上传任意多文件