2011-07-27 51 views
1

我認爲我的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); 
       } 
}); 
+0

我有這個問題。在我的情況下,網絡服務器使用了錯誤的'web.xml',而不是使用[gwt-maven-plugin:mergewebxml]處理的網頁服務器(https://gwt-maven-plugin.github.io/gwt-maven-plugin/用戶指南/ remoteservicerelativepath-annotation.html)maven目標。 –

回答

2

我猜你已經在考慮在右邊線。這個問題似乎是你的@RemoteServiceRelativePath和web.xml url-mapping不同意彼此。

可能改變servlet的映射在web.xml中以下將解決您的問題:

<servlet-mapping> 
    <servlet-name>compressionService</servlet-name> 
    <url-pattern>/compress</url-pattern> 
    </servlet-mapping> 
+1

謝謝你的回答,塔希爾。我會在3小時內測試它......但我認爲URL-PATTERN內容應該是MODULE-RENAME-TO/RELATIVE PATH的文本。這就是爲什麼我有/我的結果/壓縮。我錯了嗎? – Arturo

+0

嗨,我已經測試過,它很奇怪。我可以用url-pattern寫任何東西,但是錯誤信息「Problem access/myresults/compress。Reason:NOT_FOUND」是完全一樣的。我已經清理,重新編譯,甚至刪除了web.xml並重新創建了它,但是我得到了相同的結果。發生什麼事???謝謝 – Arturo

+0

你有異常的堆棧跟蹤嗎?您使用什麼網址訪問您的gwt頁面? –