第十七章 多文件上传
来源:互联网 发布:明星祝福生日快乐软件 编辑:程序博客网 时间:2024/05/24 07:30
多文件上传页面:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>My JSP 'employeeAdd.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> </head> <body> <form action="${pageContext.request.contextPath}/control/employee/list_execute.action" enctype="multipart/form-data" method="post"> 文件1:<input type="file" name="image"><br/> 文件2:<input type="file" name="image"><br/> 文件3:<input type="file" name="image"><br/> <input type="submit" value="上传"/> </form> </body></html>
action处理:
package cn.itcast.action;import java.io.File;import org.apache.commons.io.FileUtils;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionContext;public class HelloWorldAction {private File[] image;private String[] imageFileName; //imageFileName固定写法 FileName后缀可得到image的文件名public File[] getImage() {return image;}public void setImage(File[] image) {this.image = image;}public String[] getImageFileName() {return imageFileName;}public void setImageFileName(String[] imageFileName) {this.imageFileName = imageFileName;}public String addUI(){return "success";}public String execute() throws Exception{String realpath = ServletActionContext.getServletContext().getRealPath("/images");System.out.println(realpath);if(image!=null){File savedir = new File(realpath);if(!savedir.exists()) savedir.mkdirs();for(int i = 0 ; i<image.length ; i++){File savefile = new File(savedir, imageFileName[i]);FileUtils.copyFile(image[i], savefile);}ActionContext.getContext().put("message", "上传成功");}return "success";}}
- 第十七章 多文件上传
- SpringBoot非官方教程 | 第十七篇:上传文件
- SpringBoot非官方教程 | 第十七篇:上传文件
- SpringBoot非官方教程 | 第十七篇:上传文件
- SpringBoot非官方教程 | 第十七篇:上传文件
- 第十七章:内存映射文件
- 第十七章 特殊文件与程序
- 第十七章
- 第十七章
- 第十七周项目6 读取文件,多文件处理
- c++primer plus第十七章-文件输入和输出
- Windows核心编程 第十七章 -内存映射文件(上)
- Windows核心编程 第十七章 -内存映射文件(下)
- 文件上传(多文件)
- 第十七章 树
- 第十七章 现在时态
- 梦里人第十七章
- 第十七章 工具
- 第十三章 自定义类型转换器
- 第十四章 全局类型转换器
- 你知道我对你的好 年华
- 第十五章 访问或添加request等属性
- 第十六章 文件上传
- 第十七章 多文件上传
- 第十八章 自定义拦截器
- 第十九章 对Action中所有方法进行输入校验
- 第二十章 对action指定方法进行校验
- 第二十一章 输入校验的流程
- 第二十二章 基于XML配置方式实现对action的所有方法进行校验
- 随感数学和计算机教育
- 第二十三 基于XML配置方式实现校验
- JQuery插件第二十五个:改编自网络获取html控件的绝对位置