【问题标题】:My GWT RPC AsyncCallback doesn’t work: InvocationException我的 GWT RPC AsyncCallback 不起作用:InvocationException
【发布时间】:2014-03-21 18:04:49
【问题描述】:

我开发了一个 GWT 应用程序并将 AsyncCallback 制作为在服务器端生成的 jfreechart。但是返回 InvocationException 时出错。 详细的错误信息在这里 404 html com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:209) callback.onResponseReceived(this, response);

我使用了 GWT 2.5.1 和 jre7 以及 eclipse juno 4.2 我的服务接口、异步接口和实现服务代码和这个例子一样 http://www.jfree.org/phpBB2/viewtopic.php?t=19080&sid=f627bee2b70f0f512009d737957b8eee

我在 web.xml 中添加了 servlet

<servlet>
<servlet-name>ChartGenerator</servlet-name>
<servlet-class>com.test.server.ChartGeneratorImpl</servlet-class>
</servlet>

<servlet>
    <servlet-name>DisplayChart</servlet-name>
    <servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>ChartGenerator</servlet-name>
    <url-pattern>/comp/ChartGenerator</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>DisplayChart</servlet-name>
    <url-pattern>/comp/DisplayChart</url-pattern>
</servlet-mapping>

我检查了 RPC 的文档,它说 发生 InvocationException 的原因有很多:网络可能断开连接,DNS 服务器可能不可用,HTTP 服务器可能没有监听,等等。 我的互联网运行良好。 有什么建议吗?
非常感谢! 海伦

【问题讨论】:

  • 您的 RPC 实现是否在您的 web.xml 文件中注册为 servlet?
  • 是的,我已经在web.xml中添加了它们
  • ... 而你的 RPC 接口包含 @RemoteServiceRelativePath("comp/ChartGenerator") 注释? (注意:根据您的 Web 服务器配置,您可能需要改用 @RemoteServiceRelativePath("../comp/ChartGenerator")。)
  • 谢谢吉尔伯托。我没有在我的 RPC 接口中使用 @RemoteServiceRelativePath("comp/ChartGenerator") 。刚才我添加了这个相对路径并再次测试我的应用程序,错误仍然是一样的。有什么建议吗?
  • 我已经尝试了@RemoteServiceRelativePath("../comp/ChartGenerator") 和@RemoteServiceRelativePath("comp/ChartGenerator") 两个版本。调用者中的相同错误消息。如何检查我的 Web 服务器配置?我在开发模式下测试我的应用程序。所以它是 127.0.0.1:8888/comp/chartGenerator 。看起来正常吗?非常感谢!

标签: java gwt rpc asynccallback


【解决方案1】:
  1. 在 web.xml 中定义的 url 模式中添加前缀“/context_root”。在您的情况下,url 模式将是“/comp/ChartGenerator”。
  2. 在RemoteService接口中使用注解@RemoteServiceRelativePath("ChartGenerator")。

【讨论】:

  • 非常感谢!如何知道我的 context_path?应该是 /C:/SERVERS/x/y/x/yourApp/WEB-INF/classes 之类的吗?
  • 通常上下文路径是您的应用程序的名称。请根据您的 Web 容器阅读它。尝试此链接以了解 tomcat 的上下文路径。 [链接] (mulesoft.com/tcat/tomcat-context)
  • 您好 Braj,非常感谢您的及时帮助!我的应用程序名称是 comp。我在我的 RemoteService 界面中添加了 @RemoteServiceRelativePath("comp/ChartGenerator") 。对于 web.xml 中的 url 模式,我在 url 模式中尝试了 3 个不同版本的上下文路径 (1) /C:/*/workspace/comp/war/WEB-INF/classes/comp/ChartGenerator url-pattern> (2) /C:/*/workspace/comp/ChartGenerator (3) /C:/*/workspace/comp/war/WEB -INF/classes/com/test/client/ChartGenerator 但它们都不起作用。我收到了同样的错误信息。
  • 详细的错误信息是 com.google.gwt.user.client.rpc.StatusCodeException: 404

    HTTP ERROR: 404

    NOT_FOUND

    RequestURI=/comp/chartGenerator

    jetty.mortbay.org/">Powered by Jetty://


    有什么建议吗?非常感谢!
  • 上下文路径不代表应用程序的绝对路径。在 tomcat 中,它是战争文件的名称。请再读一遍 [Link] tomcat.apache.org/tomcat-5.5-doc/config/context.html 现在从错误消息中可以清楚地看到请求 URI 是“/comp/chartGenerator”,并且根据您的 cmets,“comp”是您的应用程序名称。 URL 模式区分大小写。根据错误消息和 web.xml “chartGenerator”在 url 模式和注释中的大小写可能不同。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多