日期:2014-05-16  浏览次数:20637 次

Uploadify上传onComplete事件问题 - Web 开发 / Ajax
用的是struts2+query1.4+uploadify2.1
上传都没什么问题
struts2返回json

就是在处理上传成功事件时
JScript code
 
onComplete: function (event, queueID, fileObj, response, data) {
alert(response);//此处得到结果为  {"message","上传OK"}
alert(response.message);// 此处是null....为什么
     alert("文件:" + fileObj.name + "上传成功");
   }





以下是action代码
Java code

public class UpLoadAction extends ActionSupport{
    private File file;
    private String fileFileName;
    private String message;
    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }
    public String execute(){
        System.out.println("文件名是"+fileFileName+file);
        String root=ServletActionContext.getServletContext().getRealPath("/upload");
        try {
            byte[]b=new byte[1024];
            int length;
            InputStream read=new FileInputStream(file);
            OutputStream write=new FileOutputStream(new File(root,fileFileName));//文件名保存为例 
            while((length=read.read(b))!=-1){
                write.write(b, 0, length);
            }
            read.close();
            write.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        message="我是服务器";
        return SUCCESS;
    }
    public void setFile(File file) {
        this.file = file;
    }

    public void setFileFileName(String fileFileName) {
        this.fileFileName = fileFileName;
    }
}






------解决方案--------------------
scriptData
http://www.uploadify.com/documentation/

An object containing name/value pairs of additional information you would like sent to the upload script. {‘name’: ‘value’}