0

我创建了 JSNI 方法,我正在使用另一个方法注册“createCallbackFunction”方法

createCallbackFunction(new NTFileUploadUtil());


public void uploadComplete(String fileId){
    SC.say("I am back...with fileId:" + fileId);
    System.out.println("I am back...with fileId: " + fileId);
}


private native static void createCallbackFunction(NTFileUploadUtil obj ) /*-{
    //$wnd.alert(fileName); 
    var tmpcallback = function(fileName){        
            obj.@com.nextenders.client.ui.util.NTFileUploadUtil::uploadComplete(Ljava/lang/String;)( fileName);
    };
    alert("NTFileUploadUtil-- createCallbackFunction:\n " + tmpcallback);
    $wnd.uploadComplete=tmpcallback;
}-*/;

我正进入(状态

function (fileName) {
    __gwt_makeJavaInvoke(1)(obj, 83361821, fileName);
}

在警报中作为输出。

我试图从一个 struts 动作类中调用它

response.setContentType("text/html");

out.println("<html>");
                    out.println("<head>");
                    out.println("<script type=\"text/javascript\">");
                    out.println("function foo() { ");
                    out.println("alert('From Servlet');");
                    out.println("window.top.uploadComplete('"+ft.getId()+"');");
                    out.println("}");
                    out.println("</script>");
                    out.println("</head>");
                    out.println("<body onload=\"foo();\">");
                    out.println("</body>");
                    out.println("</html>");

但是Javascript没有被执行。警报都不起作用,上传方法也没有被调用。

4

1 回答 1

0
    PrintWriter out;
    out = response.getWriter();
    response.setContentType("text/html");       
    out.println("<html>");
    out.println("<head>");
    out.println("<script type=\"text/javascript\">");
    out.println("function foo() { ");
    //out.println("alert('From Servlet');");
    out.println("window.top.uploadComplete('"+transId+"');");
    out.println("}");
    out.println("</script>");
    out.println("</head>");
    out.println("<body onload=\"foo();\">");
    out.println("</body>");
    out.println("</html>");
于 2011-03-15T06:36:50.293 回答