简体   繁体   English

GWT:如何从纯js访问其Web服务?

[英]GWT: How can I access its webservice from pure js?

Does anyone have an example of accessing a GWT web service from pure js code? 有没有人有从纯js代码访问GWT Web服务的示例?

Part of our site is GWT and part is straight html/css/js. 我们网站的一部分是GWT,另一部分是纯html / css / js。 I need to access the GWT web service from the js side. 我需要从js端访问GWT Web服务。

Thanks for the help! 谢谢您的帮助!

Well, compiled GWT is also "straight html/css/js"... If you are looking for a library that will decode the GWT-RPC protocol (I'm assuming you mean that by "GWT web service"), then... just write a small application that will communicate with the webservice using standard Java/GWT interfaces and methods. 好吧,编译后的GWT也是“直接html / css / js” ...如果您正在寻找一个可以解码GWT-RPC协议的库(我假设您的意思是“ GWT Web服务”),那么。 ..只需编写一个小型应用程序,即可使用标准Java / GWT接口和方法与网络服务进行通信。 Export that to a JavaScript library (for example, using gwt-exporter ) that you can use on your site. 将其导出到可以在您的站点上使用的JavaScript库(例如,使用gwt-exporter )。

Another approach would be to write your GWT application with the required RPC-calls and then make them accessible from your JavaScript with something like this: 另一种方法是使用所需的RPC调用编写GWT应用程序,然后使用如下代码从JavaScript对其进行访问:

public MyClass
{

    public static void doRPCCall() { 
        rpcservice.getInstance.doSomething(new AsyncCallback<Void>() {...}   
    }

    public static native void exportStaticMethod() /*-{
       $wnd.doRPCCall =
          $entry(@mypackage.MyClass::doRPCCall());
    }-*/;
}

just call the exportStaticMethod() at application initialization to assign a variable in the window object called doRPCCall . 只需在应用程序初始化时调用exportStaticMethod()在名为doRPCCall的窗口对象中分配一个变量。

more explanation on JSNI 有关JSNI的更多说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Node js-如何访问SOAP WebService? - Node js - How can I access to a SOAP WebService? 如何使用纯JavaScript(没有JS框架)从表单中选择所有复选框? - How can I select all checkboxes from a form using pure JavaScript (without JS frameworks)? 如何从左到右制作圆形进度条的动画? (纯js) - How I can animate circular progress bar from left to right? ( js pure) 如何从子组件访问主组件? reactjs - How can i access the main component from not its child? reactjs 如何从其值访问无序列表项? - How can I access an unordered list item from its value? 如何在浏览器控制台上使用纯 javascript 访问 GPT 数据? - How can I access GPT data with pure javascript on browser console? 如何将FormsAuthentication.SetAuthCookie从数据访问层类传递到WebService到Javascript? - How can I pass FormsAuthentication.SetAuthCookie from Data Access Layer Class to WebService to Javascript? 如何使用纯JS在img上设置data-src? - How can I set the data-src on an img with pure JS? 如何将 jQuery &#39;:not(:has(*)):not(a *):not(a)&#39; 转换为 TreeWalker 的纯 js? - How can I translate jQuery ':not(:has(*)):not(a *):not(a)' to pure js for the TreeWalker? 如何更改纯 js 中单击按钮的选定属性? - How can I change the the selected attribute on clicking buttons in pure js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM