struts2多个文件上传
来源:互联网 发布:淘宝买东西返利软件 编辑:程序博客网 时间:2024/05/21 07:00
struts2多个文件上传
form表单:
<form action="<%=basePath%>upload!moreupload.action"
enctype="multipart/form-data" method="post">
选择文件1<input type="file" name="file" /><br><br>
选择文件2<input type="file" name="file" /><br><br>
选择文件3<input type="file" name="file" /><br><br>
选择文件4<input type="file" name="file" /> <br><br>
<input type="submit" value="上传文件" />
</form>
action类:
public String moreupload() throws IOException {
String realpath = ServletActionContext.getServletContext().getRealPath(
"/upload"); //获得文件目录
if (file != null) {
File savedir = new File(realpath); //创建文件
if (!savedir.exists()) //判断文件是否存在
savedir.mkdirs(); //创建目录
for (int i = 0; i < file.length; i++) {
File savefile = new File(savedir, fileFileName[i]); //依次把文件名保存起来
FileUtils.copyFile(file[i], savefile); //依次保存文件
}
ActionContext.getContext().put("message", "文件上传成功");
return "success";
}
return "fail";
}
页面上:
<body>
${message}
</body>
struts.xml配置略
form表单:
<form action="<%=basePath%>upload!moreupload.action"
enctype="multipart/form-data" method="post">
选择文件1<input type="file" name="file" /><br><br>
选择文件2<input type="file" name="file" /><br><br>
选择文件3<input type="file" name="file" /><br><br>
选择文件4<input type="file" name="file" /> <br><br>
<input type="submit" value="上传文件" />
</form>
action类:
public String moreupload() throws IOException {
String realpath = ServletActionContext.getServletContext().getRealPath(
"/upload"); //获得文件目录
if (file != null) {
File savedir = new File(realpath); //创建文件
if (!savedir.exists()) //判断文件是否存在
savedir.mkdirs(); //创建目录
for (int i = 0; i < file.length; i++) {
File savefile = new File(savedir, fileFileName[i]); //依次把文件名保存起来
FileUtils.copyFile(file[i], savefile); //依次保存文件
}
ActionContext.getContext().put("message", "文件上传成功");
return "success";
}
return "fail";
}
页面上:
<body>
${message}
</body>
struts.xml配置略
- Struts2多个文件上传
- Struts2多个文件上传
- struts2上传多个文件
- Struts2多个文件上传
- Struts2上传多个文件
- struts2多个文件上传
- Struts2多个文件上传
- struts2多个文件上传
- struts2 多个文件上传
- struts2 上传多个文件
- struts2多个文件上传
- Struts2教程:上传任意多个文件
- Struts2:上传任意多个文件
- struts2做上传多个文件
- struts2示例代码-多个文件上传
- Struts2 - 上传任意多个文件
- Struts2上传单个或多个文件
- struts2 单个文件上传 多个文件上传
- Unity3D游戏 设置Quality
- Windows 7 下使用超级终端
- js - 处理json
- struts2单个文件上传
- 越狱的iPhone、iPad 通过网站实现一键安装ipa格式的APP应用
- struts2多个文件上传
- 记使用JSTL时的一次愚蠢错误
- minix 挂载 cd-rom
- 关于RichTextBox字体的问题
- Android中实现下拉刷新
- 基于mjpg-streamer远程视频WEB监控 项目手札
- 如何学习c语言
- 程序员不错的网站
- Android自制发送短信程序