我对 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
这意味着什么?我不明白:(