Struts upload组件同一个页面中多文件上传
来源:互联网 发布:拐个弯儿来爱你网络剧 编辑:程序博客网 时间:2024/05/17 05:56
jsp代码如下:
<html:form method="post" action="/upload.do" enctype="multipart/form-data">
<table width="75%" border="1" align="center">
<tr>
<td>
<div align="center">
1、
<html:file property="file1" size="30"/>
</div>
</td>
</tr>
<tr>
<td>
<div align="center">
2、
<html:file property="file2" size="30"/>
</div>
</td>
</tr>
<tr>
<td>
<div align="center">
3、
<html:file property="file3" size="30"/>
</div>
</td>
</tr>
<tr>
<td>
<div align="center">
4、
<html:file property="file4" size="30"/>
</div>
</td>
</tr>
<tr>
<td>
<div align="center">
<html:submit>上传它!</html:submit>
</div>
</td>
</tr>
</table>
</html:form>
struts配置文件中配置动态ActionForm如下:
<form-bean name="uploadForm" type="org.apache.struts.action.DynaActionForm">
<form-property name="file3" type="org.apache.struts.upload.FormFile" />
<form-property name="file1" type="org.apache.struts.upload.FormFile" />
<form-property name="file4" type="org.apache.struts.upload.FormFile" />
<form-property name="file2" type="org.apache.struts.upload.FormFile" />
</form-bean>
Action中处理上传的代码如下:
DynaActionForm upForm = (DynaActionForm) form;
String dir = this.getServlet().getServletContext().getRealPath("/upload/uploaded");
FormFile fileOne = (FormFile)upForm.get("file1");
FormFile fileTwo = (FormFile)upForm.get("file2");
FormFile fileThree = (FormFile)upForm.get("file3");
FormFile fileFour = (FormFile)upForm.get("file4");
FormFile[] files = new FormFile[]{fileOne, fileTwo, fileThree, fileFour};
List fileList = new ArrayList();
for(int i = 0;i<files.length;i++){
if(files[i] == null)
continue;
String fileName = files[i].getFileName();
int size = files[i].getFileSize();
try {
InputStream streamIn = files[i].getInputStream();
OutputStream streamOut = new FileOutputStream(dir + "/" + fileName);
int bytesRead = 0;
byte[] buffer = new byte[4096];
while((bytesRead = streamIn.read(buffer, 0, 4096)) != -1)
streamOut.write(buffer, 0, bytesRead);
streamOut.close();
streamIn.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
ActionMessages msgs = new ActionMessages();
ActionMessage msg = new ActionMessage("error.upload.fail");
msgs.add("error.upload.fail",msg);
request.setAttribute(Globals.MESSAGE_KEY,msgs);
} catch (IOException e) {
e.printStackTrace();
ActionMessages msgs = new ActionMessages();
ActionMessage msg = new ActionMessage("error.upload.fail");
msgs.add("error.upload.fail",msg);
request.setAttribute(Globals.MESSAGE_KEY,msgs);
}
fileList.add(fileName);
ActionMessages msgs = new ActionMessages();
ActionMessage msg = new ActionMessage("error.upload.success");
msgs.add("error.upload.success",msg);
request.setAttribute(Globals.MESSAGE_KEY,msgs);
}
- Struts upload组件同一个页面中多文件上传
- Struts upload组件同一个页面中多文件上传
- Struts 的文件上传组件org.apache.struts.upload
- struts实现upload文件上传
- 无upload组件上传文件
- Bestcomy.Web.Controls.Upload 组件支持多文件上传
- UI upload多文件上传
- UI upload多文件上传
- struts文件上传、Cos组件文件上传
- 使用struts upload包 进行文件上传的例子
- struts实现upload文件上传(步骤很清楚,一目了然)
- Android+struts上传文件时upload.parseRequest(request)为空
- 【文件上传->jQuery-File-Upload】jQuery-File-Upload图片上传组件简要使用指南(挥泪共享)
- kendo ui 使用springMVC upload组件上传文件
- 简单的Struts upload上传
- 关于java中http上传组件Upload的使用
- SpringMVC File Upload 多文件上传
- upload文件的上传
- 当sql server提示日志满时,如何截断日志。
- [转]如何用正确的方法来写出质量好的软件的75条体会
- js 里如何比较字符串大小
- CSDN Blog中的问题
- java数据结构及算法三
- Struts upload组件同一个页面中多文件上传
- 如何在UNIX/LINUX环境中创建Oracle9i 数据库
- html:multibox的使用
- log4net使用指南
- Java数据库编程简略
- 转·ASP.NET验证控件详解
- 新的历程
- 不露也锋茫
- 各编译器对C99的支持