如何使用uploadify上传文件

时间:2013-05-14 08:44:05

标签: java struts2 upload uploadify

我正在使用uploadify上传文件

有Jsp代码

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/tags.jsp"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN">
<html>
    <head>
        <link href="${path }/css/uploadify.css" rel="stylesheet" />
        <script type="text/javascript" src="${path }/js/jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="${path }/js/swfobject.js"></script>
        <script type="text/javascript" src="${path }/js/jquery.uploadify.min.js"></script>
        <script>
            $("#uploadify").uploadify( {
                'swf' : '${path }/js/uploadify.swf',
                'uploader' : '${path }/js/uploadify.swf',
                'script' : '${path }/sys/addImage',
                'queueID' : 'fileQueue',
                'queueSizeLimit' : 5,
                'fileTypeDesc' : 'exts',
                'fileTypeExts' : '*.bmp;*.jpg;*.jpeg;*.png', 
                'method' : 'post',
                'fileSizeLimit' : 10000,
                'auto' : false,
                'multi' : true,
                'uploadLimit' : 5,
                'buttonText' : 'browse',
                'onUploadError' : function (file, errorCode, errorMsg, errorString) {
                    alert("errorCode:" + errorCode + "\n" + "errorMsg:" + errorMsg + "\n" + "errorString:" + errorString);
                },
                'onUploadSuccess' : function (file, data, response) {
                    $('#sendDialog').dialog('close');
                    $('#listTable').datagrid('reload');
                }
            });
        </script>
    </head>
    <body>
        <div id="fileQueue"></div>
        <input type="file" name="fileupload" id="uploadify" />
    </body>
</html>

和Struts Action代码

@Namespace("/sys")
@Controller
public class ImageAction extends BaseAction {

    private File fileupload;

    private String fileuploadFileName;

    public File getFileupload() {
        return fileupload;
    }

    public void setFileupload(File fileupload) {
        this.fileupload = fileupload;
    }

    public String getFileuploadFileName() {
        return fileuploadFileName;
    }

    public void setFileuploadFileName(String fileuploadFileName) {
        this.fileuploadFileName = fileuploadFileName;
    }

    @Action(value = "addImage")
    public void addImage() {
        String newFileName = "", extName = "";

        String savePath = request.getSession().getServletContext().getRealPath("/"); 
        savePath = savePath + getImgFloder();

        if (fileuploadFileName.lastIndexOf(".") >= 0) {
            extName = fileuploadFileName.substring(fileuploadFileName.lastIndexOf("."));
        }

        newFileName = savePath + UUID.randomUUID().toString() + extName;
        fileupload.renameTo(new File(newFileName));
    }
}

我在addImage()

的顶行设置了一个断点

当我选择一些文件并执行$("#uploadify").uploadify('upload','*');

事件onUploadSuccess是触发器,但断点不是触发器

如何解决?

0 个答案:

没有答案