struts2上传多文件

public  class  UploadAction {
 
     private  static  final  long  serialVersionUID = 7738910297605127355L;
     //private News news; //注入实体对象
     private  static  final  int  BUFFER_SIZE = 16  * 1024 ; // 缓冲-上传字节数组
     private  String upfileName;
 
     private  List<File> uploads = new  ArrayList<File>();
     private  List<String> uploadFileNames = new  ArrayList<String>();
     private  List<String> uploadContentTypes = new  ArrayList<String>();
 
     public  String add() {
         int  size = uploadContentTypes.size();
         if  (size > 0 ) {
             for  ( int  i = 0 ; i < size; i++) {
                 String contentype = uploadContentTypes.get(i);
                 if  (contentype.indexOf( "image" ) > - 1 ) {
                     File imageFile = new  File(ServletActionContext.getServletContext().getRealPath( "/upload/images" )+ "/"  + uploadFileNames.get(i));
                     UploadUtil.copy(uploads.get(i), imageFile, BUFFER_SIZE);
                     String picturePath = "/upload/images"  + "/"  + uploadFileNames.get(i);
                     String picName = uploadFileNames.get(i);
                     
                     // 设置实体对象中的图片地址
                     // news.setPicturePath(picturePath);
                     // news.setPictureName(uploadFileNames.get(0));
 
                     System.out.println( "图片地址:"  + picturePath);
                     System.out.println( "图片名称:"  + picName);
                 }
                 /*否则就是上传附件,不是图片
                 else {
                     File fujianFile = new File(ServletActionContext.getServletContext().getRealPath("/upload")+ "/" + uploadFileNames.get(1));
                     UploadUtil.copy(uploads.get(1), fujianFile, BUFFER_SIZE);
                     // 设置实体对象中的图片地址
                     // news.setUpfileName(uploadFileNames.get(1));
                     String picturePath = "/upload/images" + "/"
                             + uploadFileNames.get(0);
                     String picName = uploadFileNames.get(0);
                     System.out.println("图片地址:" + picturePath);
                     System.out.println("图片名称:" + picName);
                 }
                 */
             }
         }
         return  "upload" ;
     }
 
     public  String getUpfileName() {
         return  upfileName;
     }
 
     public  void  setUpfileName(String upfileName) {
         this .upfileName = upfileName;
     }
 
     public  List<File> getUpload() {
         return  this .uploads;
     }
 
     public  void  setUpload(List<File> uploads) {
         this .uploads = uploads;
     }
 
     public  List<String> getUploadFileName() {
         return  this .uploadFileNames;
     }
 
     public  void  setUploadFileName(List<String> uploadFileNames) {
         this .uploadFileNames = uploadFileNames;
     }
 
     public  List<String> getUploadContentType() {
         return  this .uploadContentTypes;
     }
 
     public  void  setUploadContentType(List<String> contentTypes) {
         this .uploadContentTypes = contentTypes;
     }
 
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值