单文件上传
上传页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>Insert title here
struts.xml配置
/success.jsp
Action类
public class UploadAction extends ActionSupport{ //存放上传的文件对象 private File upload; //上传的文件名称 private String uploadFileName; //上传的上传者 private String author; public String fileUpload() throws IOException { FileInputStream fis = new FileInputStream(upload); String path = "D://pic/"+uploadFileName; FileOutputStream fos = new FileOutputStream(path); int flag = 0; while((flag=fis.read())!=-1) { fos.write(flag); } fis.close(); fos.close(); return SUCCESS; } public File getUpload() { return upload; } public void setUpload(File upload) { this.upload = upload; } public String getUploadFileName() { return uploadFileName; } public void setUploadFileName(String uploadFileName) { this.uploadFileName = uploadFileName; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } }
成功接收页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>Insert title here
批量上传
上传页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>Insert title here
struts.xml配置
/success.jsp /error.jsp 1500
Action类
public class UploadAction extends ActionSupport{ //上传的文件对象 private File[] upload; //上传的文件名称 private String[] uploadFileName; //上传的文件类型 private String[] uploadContentType; public String upload() { String path = "D://pic/"; for(int i=0;i
成功接收页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ taglib prefix="s" uri="/struts-tags"%>Insert title here