开发者

Call Java Function using JSNI from servlet

I have created JSNI methods i am registering 'createCallbackFunction' method from another method using

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 = f开发者_运维问答unction(fileName){        
            obj.@com.nextenders.client.ui.util.NTFileUploadUtil::uploadComplete(Ljava/lang/String;)( fileName);
    };
    alert("NTFileUploadUtil-- createCallbackFunction:\n " + tmpcallback);
    $wnd.uploadComplete=tmpcallback;
}-*/;

I am getting

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

in alert as output .

I am trying to call this from a struts action class

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>");

But Javascript is not getting executed. Neither alert is working nor upload method is getting called.


    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>");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜