zoukankan      html  css  js  c++  java
  • Struts2 多文件上传

    Struts2多文件上传只需要将 单文件上传中的File变成File[]  即可,上篇文章:单文件上传

    <form action="${pageContext.request.contextPath}/hello/upload_uploadImage.do" 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/>
       			图片4:<input type="file" name="image"  /><br/>
       			<input type="submit" value="上传" />
       		</form> 


    action:

    public class UploadAction {
    	private File[] image;
    	private String[] imageFileName;
    	private String[] imageContentType;
    	private String message;
    
    	public String uploadImage() {
    		try {
    			String realPath = ServletActionContext.getServletContext().getRealPath("/images");
    			File filePath = new File(realPath);
    			if (!filePath.exists()) {
    				filePath.mkdirs();
    			}
    			System.out.println("文件存放路径:" + realPath);
    			for(int i=0;i<image.length;i++){
    				if (image[i] != null) {
    					System.out.println("文件名:" + imageFileName[i] + ",文件类型:" + imageContentType[i]);
    					File saveFile = new File(filePath, imageFileName[i]);
    					FileUtils.copyFile(image[i], saveFile);
    				}
    			}
    			message="文件上传成功!";
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		catch (Exception e) {
    			e.printStackTrace();
    		}
    		return "message";
    	}
    
    	
    	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[] getImageContentType() {
    		return imageContentType;
    	}
    	public void setImageContentType(String[] imageContentType) {
    		this.imageContentType = imageContentType;
    	}
    	
    	public String getMessage() {
    		return message;
    	}
    	public void setMessage(String message) {
    		this.message = message;
    	}
    
    }
    


  • 相关阅读:
    WebService出错 Maximum message size quota for incoming messages (65536) has been exceeded.已超过传入消息(65536)的最大消息大小配额
    php 获取系统时间
    JavaSctipt 控制网页 前进,后退
    放A片的文件夹的名字
    玩玩独轮车
    3月18日周六骑行三水大旗头村——广东名镇之一
    叫春的猫
    抓紧锻炼身体噢!
    使用Zend Framework中的 Zend_Pdf来创建pdf文档
    虚拟主机示例
  • 原文地址:https://www.cnblogs.com/raphael5200/p/5114766.html
Copyright © 2011-2022 走看看