uploadify与struts2

2014-11-24 08:20:11 · 作者: · 浏览: 0
我使用的uploadify版本为3.2.1,整合SSH+uploadify
需要的文件有:
jquery-1.7.2.js(注意:这个文件是我自己单独 下载的,uploadify文件夹里没有)
jquery.uploadify.js
jquery.uploadify.min.js
uploadify-cancel.png
uploadify.css
uploadify.swf
前台 html代码:
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>  
   
  
  
<script type="text/java script" src="js/jquery-1.7.2.js">  
<script type="text/java script" src="uploadify/jquery.uploadify.js">  
<script type="text/java script" src="uploadify/jquery.uploadify.min.js">  
      
  
  
<script type="text/java script">  
$(function () {  
    $('#uploadify').uploadify({  
        uploader: 'upload!uploadFile',           // 服务器端处理地址  
        swf: '/uploadify/uploadify.swf',    // 上传使用的 Flash  
        width: 60,                          // 按钮的宽度  
        height: 23,                         // 按钮的高度  
        buttonText: "上传",                 // 按钮上的文字  
        buttonCursor: 'hand',                // 按钮的鼠标图标  
        fileObjName: 'uploadify',            // 上传参数名称 后台action里面的属性uploadify  
        // 两个配套使用  
        fileTypeExts: "*.jpg;*.png;*.txt",             // 扩展名  
        fileTypeDesc: "请选择 jpg png txt 文件",     // 文件说明  
        auto: false,                // 选择之后,自动开始上传  
        multi: true,               // 是否支持同时上传多个文件  
        queueSizeLimit: 5          // 允许多文件上传的时候,同时上传文件的个数  
    });  
});  
  
  
          
        
清除第一个文件
清除所有文件 上传所有文件

后台action代码
package com.action;  
  
import java.io.File;  
import java.io.FileInputStream;  
import java.io.FileOutputStream;  
import java.io.IOException;  
import org.apache.commons.io.IOUtils;  
import org.apache.struts2.ServletActionContext;  
import org.apache.struts2.convention.annotation.ParentPackage;  
import com.hhkj.tjsjbz.util.PublicOPCode;  
import com.opensymphony.xwork2.ActionSupport;  
  
@ParentPackage("framework-package")  
public class UploadAction extends ActionSupport{  
      
    private File uploadify;  
    private String uploadifyFileName;  
  
    public String uploadFile() throws IOException{  
        String savePath = ServletActionContext.getServletContext().getRealPath("/uploads/");//上传完后文件存放位置  
        System.out.println(savePath);  
        String newsuffix = "";  
        String current=PublicOPCode.getcurrentdate();  
        if((uploadifyFileName != null)&&(uploadifyFileName.length()>0))  
        {  
            int dot = uploadifyFileName.lastIndexOf(".");  
            if((dot >-1) && (dot < (uploadifyFileName.length() - 1)))  
            {  
                 newsuffix = uploadifyFileName.substring(dot + 1);  
            }  
        }  
        FileInputStream fis = new FileInputStream(uploadify);  
        FileOutputStream fos = new FileOutputStream(savePath+"/"+ current + "." + newsuffix);  
        IOUtils.copy(fis, fos);  
        fos.flush();  
        fos.close();  
        fis.close();  
        return null;  
    }  
      
    public File getUploadify() {  
        return uploadify;  
    }  
    public void setUploadify(File uploadify) {  
        this.uploadify = uploadify;  
    }  
    public String getUploadifyFileName() {  
        return uploadifyFileName;  
    }  
    public void setUploadifyFileName(String uploadifyFileName) {  
        this.uploadifyFileName = uploadifyFileName;  
    }  
      
}