gpt4 book ai didi

java - GWT-如何在其他项目中对一个项目进行 RPC 调用(使用服务器端)?

转载 作者:行者123 更新时间:2023-11-28 22:51:38 39 4
gpt4 key购买 nike

我们已经使用 java 在 GWT 上创建了我们的 Web 项目。完全工作正常。现在,我们正在努力制作移动网站版本,该版本也将在 gwt 上,并且肯定会有不同的 url(如 m.exam.com)。

ISSUE:-

We want to use the server side of our web project as server side of the mobile website. So that only front-end have to be changes. As gone through some tutorials got that its possible that gwt rpc call made from android app.

But we want that it should be possible in gwt to gwt RPC call.

For android app they use Syncproxy where they change the baseurl and use it to call the gwt server side methods. It will be for sure the reusability of the code.

Android 示例:-

SyncProxy.setBaseURL("http://testing.enggheads.in/enggheads/");

GreetingServiceAsync greetService = SyncProxy.create(GreetingService.class);

那么,如何通过这种方式实现GWT项目使用其他项目的服务端方法呢?


编辑新问题:导入 com.gdevelop 无法解决

我已经阅读了更多关于跨域 rpc 调用的 gwt 文档,例如 gwt 到 android 应用程序。我得到了 syncproxy 0.5 jar 文件,它和 android 的完全一样。具有相同的功能。我在项目中导入了jar文件,调用了SyncProxy的功能如下。

public void onModuleLoad() {

SyncProxy.setBaseURL("http://www.enggheads.in/CrossModuleCode/");
final GreetingServiceAsync greetService = SyncProxy.create(GreetingService.class);

final Button sendButton = new Button("Send");
final TextBox nameField = new TextBox();
nameField.setText("GWT User");
final Label errorLabel = new Label();

// We can add style names to widgets
sendButton.addStyleName("sendButton");

// Add the nameField and sendButton to the RootPanel
// Use RootPanel.get() to get the entire body element
RootPanel.get("nameFieldContainer").add(nameField);
RootPanel.get("sendButtonContainer").add(sendButton);
RootPanel.get("errorLabelContainer").add(errorLabel);

现在在编译项目时出现以下错误。 error

编辑 2:-

GWT-No 'Access-Control-Allow-Origin' header is present on the requested resource

最佳答案

尝试在您的子项目中设置服务入口点
((ServiceDefTarget) greetService).setServiceEntryPoint("http://testing.enggheads.in/enggheads/");

如果您的子项目部署在另一个域中,您可能需要一个 CORS 过滤器以允许跨站点请求

编辑:
如何设置一个简单的示例:

  1. 创建 "New Web Application project..."并选择 "generate project sample code"并将其命名为“mobileapp”
  2. 创建另一个 "New Web Application project..."并选择“生成项目示例代码”并将其命名为“webapp”
  3. Mobileapp.java将此代码复制到 onModuleLoad 的第一行: ((ServiceDefTarget) greetingService).setServiceEntryPoint("http://127.0.0.1:8080/webapp/webapp/greet"); webapp/greet<url-pattern>/webapp/greet</url-pattern>从你的 web.xml。 http://127.0.0.1:8080/webapp是你的 webapp 的 URL
  4. 编译这两个应用程序并将它们部署在同一个 tomcat 实例上。如果您将它们部署在不同的 tomcat 上,则必须为您的 webapp 使用 CORS 过滤器并允许跨域请求。
  5. 打开http://127.0.0.1:8080/mobileapp/在您的浏览器中,然后按 Send按钮。它将使用您的服务器方法 webapp
    重要提示:这仅适用于 GreetingService接口(interface)具有相同的方法...所以始终保持同步

您可以在这里下载这两个项目,如上文所述,风险自负:googledrive link

关于java - GWT-如何在其他项目中对一个项目进行 RPC 调用(使用服务器端)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38144154/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com