1

从http://localhost:8080/myapp运行时,我的 GWT 应用程序运行良好。

我需要在本质上是代理的后面托管 gwt 应用程序。当在代理后面时,url 变为http://localhost:8080/foo/bar/00_00_00/myapp 之类的东西。

当我尝试在代理后面访问时,Gwt 抛出错误:

myAppServlet:错误:请求的模块路径 /foo/bar/00_00_00/myapp/MyApp/ 与此 servlet /myapp 不在同一个 Web 应用程序中。您的模块可能未正确配置,或者您的客户端和服务器代码可能已过时。

当 gwt 尝试序列化 java 对象并将它们发送回客户端时,该错误似乎发生在 rpc 请求之后。

有什么方法可以通知 GWT 该应用程序位于代理后面?

更新:

第一个请求似乎工作正常。但是对于所有其他请求它都​​失败了??!!我发现错误来自 RemoteServiceServlet.loadSerializationPolicy。不幸的是,我无法覆盖,因为它是静态的。

也许可以以编程方式设置 servlet 上下文路径?

4

1 回答 1

1

我不确定这是否会解决整个问题,因为您说,它在您第一次拨打电话时已经有效 - 但是当您在客户端创建 serviceAsync 时,您可以尝试以下操作:

MyServiceAsync service = GWT.create(MyService.class);
ServiceDefTarget serviceDefTarget = (ServiceDefTarget) service;
serviceDefTarget.setServiceEntryPoint(
     "http://localhost:8080/foo/bar/00_00_00/myapp/MyApp/");
   /* ^^ Use your full servlet path here ^^ */

如果您想知道,为什么必须将其显式转换为ServiceDefTarget- 这是来自 ServiceDefTarget 的 Javadoc 的解释:

/**
 * An interface implemented by client-side RPC proxy objects. Cast the object
 * returned from {@link com.google.gwt.core.client.GWT#create(Class)} on a
 * {@link RemoteService} to this interface to initialize the target URL for the
 * remote service.
 */

(我假设您正在从“ http://localhost:8080 ”加载您的 html 主机页面,否则这会因为同源策略而失败。)

我可以想象的另一个问题可能与您的代理中的缓存有关 - 所以可能先尝试关闭任何缓存,然后仅为具有"*.cache.*"文件名的资源重新启用它(另请参阅:Ideal HTTP cache control headers for different types of resources) .

于 2011-04-05T18:44:58.277 回答