【问题标题】:GWT 404 Error on RPCRPC 上的 GWT 404 错误
【发布时间】:2013-01-05 13:54:28
【问题描述】:

我对 gwt 和 rpc 有疑问。我为我的 rpc 实现了一个服务:

@RemoteServiceRelativePath("search")
public interface SearchService extends RemoteService {
    List<Result> doSearch(String keyWords, Coordinate start, Coordinate end);
}

public interface SearchServiceAsync {
    void doSearch(String keyWords, Coordinate start, Coordinate end, AsyncCallback<List<Result>> callback);
}

public class SearchServiceImpl extends RemoteServiceServlet implements SearchService {
    private static final long serialVersionUID = 1L;
    private ISearch search = null; // interface to my database

    public List<Result> doSearch(String keyWords, Coordinate start, Coordinate end) {
        LonLat lowerLeft = new LonLat(start.getLongitude(), start.getLatitude());
        LonLat upperRight = new LonLat(end.getLongitude(), end.getLatitude());

        try {
            search = new SearchController(keyWords, lowerLeft, upperRight);
        } catch (ClassNotFoundException e1) {
            e1.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }

        List<de.myPackage.model.Result> temp = null;

        try {
            temp = search.doSearch();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return map(temp);
    }

    private List<Result> map(List<de.myPackage.model.Result> results) {
       ....
    }
}

这些是回调所需的类。不要怀疑这两个类 Result 和 de.myPackage.model.Result。结果类位于共享文件夹和 de.myPackage.model.Result 是同一个类,但来自另一个模块(使用 maven)。我必须让它变得如此复杂,因为在客户端代码中你不能使用任何自编码容器。为此,我的 SearchServiceImpl 中有 map() 方法。它将 de.myPackage.model.Result 映射到 Result。

这里是我的视图中丢失的电话:

AsyncCallback<List<Result>> callback = new AsyncCallback<List<Result>>() {
    public void onFailure(Throwable caught) {
        System.out.println("Fail!");    
    }

    public void onSuccess(List<Result> result) {
        addToTable(result);
    }
};
searchService.doSearch(callback);

现在的问题是,它从不调用我的 SearchServiceImpl 的 doSearch-Method,因为他说他找不到它,我不知道为什么:( 每次我按下触发回调的按钮时,它都会说:

404 - POST /myProject/search (127.0.0.1) 1412 bytes
   Request headers
      Host: 127.0.0.1:8888
      User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0
      Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
      Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
      Accept-Encoding: gzip, deflate
      Connection: keep-alive
      Referer: http://127.0.0.1:8888/index.html?gwt.codesvr=127.0.0.1:9997
      X-GWT-Permutation: HostedMode
      X-GWT-Module-Base: http://127.0.0.1:8888/myProject/
      Content-Type: text/x-gwt-rpc; charset=utf-8
      Content-Length: 334
      Pragma: no-cache
      Cache-Control: no-cache
   Response headers
      Content-Type: text/html; charset=iso-8859-1
      Content-Length: 1412

这是什么意思?没看懂:(

【问题讨论】:

  • 您的 WEB-INF/web.xml 中有什么?或者您可能正在使用带有scanRemoteServiceRelativePathAnnotation 参数的gwt-maven-plugin 的mergewebxml mojo?
  • 不,我的 web.xml 中没有任何内容,因为我认为它将由 maven 自动生成。如果没有 - 我实际上需要添加什么到我的 web.xml 中?

标签: gwt maven rpc gwt-rpc gwt-maven-plugin


【解决方案1】:

您的WEB-INF/web.xml 中缺少 servlet 映射:

<servlet>
  <servlet-name>SearchService</servlet-name>
  <servlet-class>de.myPackage.server.SearchServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>SearchService</servlet-name>
  <url-pattern>/search</url-pattern>
</servlet-mapping>

您可以将其直接放入您的 web.xml 中,使用 generated by the gwt-maven-plugin,或者如果您使用的是 Servlet 3.0 容器(即不是 DevMode 或 AppEngine),则在您的类上应用适当的注释。

【讨论】:

  • 哦,对不起,它确实 :( 在 Web 应用程序中找不到服务器类“de.myProject.server.SearchServiceImpl”。同样的错误 404。如果我使用你发布的链接中的 xml 部分pom.xml 不再可解析
  • 您的应用运行情况如何? mvn gwt:run ?还是从 Eclipse 使用 Google Plugin for Eclipse?在后一种情况下,请参阅developers.google.com/eclipse/docs/faq#gwt_with_maven
  • 我从 Eclipse 运行它。不知道如何以其他方式做到这一点^^。对于哪种情况,链接很有趣?用于自行编辑 web.xml 或通过 gwt` 生成它?
  • 在我的 pom.xml 中找到了一些东西:org.apache.maven.pluginsmaven-clean-plugin2.4。 1src/main/webapp/Application 意思是“应用”?因为我没有得到一个名为 Application 的文件或目录
  • 不好的做法。永远不要使用src/ 作为目标,这就是target/ 的用途;换句话说,永远不要将src/main/webapp 用作GWT(DevMode 或编译器)的-war。如果您以正确的方式做事,则无需在 POM 中进行此类配置。我建议您从空 POM 重新开始,或者使用更新和/或更好的原型(gwt-maven-plugin 的原型不是一个好的开始)
猜你喜欢
  • 1970-01-01
  • 2015-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多