RPC上的GWT 404错误

时间:2013-01-05 13:54:29

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

我有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) {
       ....
    }
}

这些是回调所需的类。不要怀疑这两个类结果和 de.myPackage.model.Result。 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

这是什么意思?我不明白:(

1 个答案:

答案 0 :(得分:0)

您错过了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),请在您的类上应用适当的注释。 / p>