我認爲我的GTW項目的XML文件配置錯誤,因爲當我嘗試聯繫遠程服務時,出現此錯誤:「訪問/ myresults/compress時出現問題。原因:NOT_FOUND「。如果有人可以幫助我,請在下面找到我的代碼的重要部分,我認爲它與RemoteServiceRelativePath和我的XML有關。無法使RemoteServiceRelativePath和XML工作(GWT)
UPDATE:當我在web.xml中更改URL-PATTERN的內容時,我仍然使用path/myresults/compress得到完全相同的消息。
CompressionService.java
package myProject.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
/* The client side stub for the RPC service. */
@RemoteServiceRelativePath("compress")
public interface CompressionService extends RemoteService {
String compress(String name) throws IllegalArgumentException;
}
CompressionServiceImpl.java
package myProject.server;
import myProject.client.CompressionService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/* The server side implementation of the RPC service. */
public class CompressionServiceImpl extends RemoteServiceServlet implements
CompressionService {
public String compress(String input) throws IllegalArgumentException {
String output = "aaaa";
return output;
}
}
CompressionService.java
package myProject.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
/* The async counterpart of <code>CompressService</code> */
public interface CompressionServiceAsync {
void compress(String input, AsyncCallback<String> callback)
throws IllegalArgumentException;
}
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>compressionService</servlet-name>
<servlet-class>myProject.server.CompressionServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>compressionService</servlet-name>
<url-pattern>/myresults/compress</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>MyResults.html</welcome-file>
</welcome-file-list>
</web-app>
MyResults.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='myresults'>
<inherits name='com.google.gwt.user.User'/>
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<entry-point class='myProject.client.MyResults'/>
<source path='client'/>
<source path='shared'/>
</module>
MyResults.java
private final CompressionServiceAsync compressionService = GWT.create(CompressionService.class);
compressionService.compress(text, new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
// Show the RPC error message to the user
download.setText(caught.getMessage()));
}
public void onSuccess(String result) {
download.setText(result);
}
});
我有這個問題。在我的情況下,網絡服務器使用了錯誤的'web.xml',而不是使用[gwt-maven-plugin:mergewebxml]處理的網頁服務器(https://gwt-maven-plugin.github.io/gwt-maven-plugin/用戶指南/ remoteservicerelativepath-annotation.html)maven目標。 –