[英]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
的窗口对象中分配一个变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.