2012-12-12 12 views
0

我想熟悉使用GWT API來創建基於Web的應用程序。我一直在關注GWT的一些教程,並且還沒有能夠進行RPC調用。從廣泛的角度來看問題,我的目標是做一個服務器調用來運行一系列我知道工作的數據庫測試(我測試過這個代碼)。GWT rpc失敗 - 基地址不是我所期望的

---編輯---

我覺得這裏的問題是,資源正在尋找在這裏: /MatesWeb/org.matesweb.Main/peopleService

時,我認爲這應該看這裏: /MatesWeb/peopleService

--- END_EDIT ---

這裏是信息和代碼,我覺得是相關的:

- 使用NetBeans的

- 錯誤,我得到的是「/MatesWeb/org.matesweb.Main/PeopleService - 描述 - 請求的資源不可用。」

-GWT.getModuleBaseURL()返回:8080/MatesWeb/org.matesweb.Main/

在瀏覽器-URL是:8080/MatesWeb/

從web.xml文件

<servlet> 
    <servlet-name>peopleService</servlet-name> 
    <servlet-class>org.matesweb.server.PeopleServiceImpl</servlet-class> 
</servlet> 
<servlet-mapping> 
    <servlet-name>peopleService</servlet-name> 
    <url-pattern>/peopleService</url-pattern> 
</servlet-mapping> 

From PeopleService Service package org.matesweb.client;

import com.google.gwt.user.client.rpc.RemoteService; 
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; 

@RemoteServiceRelativePath("PeopleService") 
public interface PeopleService extends RemoteService { 

String[] saveGetPerson(String[] persInfo); 
int runTests(); 

} 

從PeopleServiceImpl 包org.matesweb.server;

import com.google.gwt.user.server.rpc.RemoteServiceServlet; 
import org.matesweb.client.PeopleService; 

import org.matesweb.server.tests.DbTest; 

class PeopleServiceImpl extends RemoteServiceServlet implements PeopleService { 

    @Override 
    public String[] saveGetPerson(String[] persInfo) { 
     throw new UnsupportedOperationException("Not supported yet."); 
    } 

    @Override 
    public int runTests() 
    { 
     int retInt; 

     DbTest dbTest = new DbTest(); 
     retInt = dbTest.runTests(); 
     return retInt; 
    } 

} 

從PeopleServiceAsync

package org.matesweb.client; 

import com.google.gwt.user.client.rpc.AsyncCallback; 

public interface PeopleServiceAsync 
{ 
    void saveGetPerson(String[] persInfo, AsyncCallback<String[]> persInformation); 
    void runTests(AsyncCallback<Integer> retInt); 
} 

的任何想法什麼怎麼回事?

乾杯, 尼克

回答

1
@RemoteServiceRelativePath("PeopleService") 

@RemoteServiceRelativePath註解是用來決定打什麼網址。這路徑服務器是相對來編譯模塊本身 - 從路徑/MatesWeb/org.matesweb.Main/加載的GWT應用程序,因此該服務在/MatesWeb/org.matesweb.Main/PeopleService被找到了。我假設這意味着你在MatesWeb/目錄中有一個html文件(可能.war文件被稱爲MatesWeb?),並且裏面存在編譯的應用程序org.matesweb.Main/,包括最初的JS文件org.matesweb.Main.nocache.js

如果你想告訴服務在/MatesWeb/peopleService找到,你有兩種選擇。首先是修改註釋備份目錄,是這樣的:

@RemoteServiceRelativePath("../peopleService") 

使用..,我指示父目錄,我也改變了路徑的一部分「peopleService」的情況下 - 這可能或可能無關緊要。第二個選擇是通過編程設置的網址:

PeopleServiceAsync service = GWT.create(PeopleService.class); 
((ServiceDefTarget)service).setServiceEntryPoint("/MatesWeb/peopleService"); 

正如@RemoteServiceRelativePath的javadoc http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/rpc/RemoteServiceRelativePath.html引用。

如果您想讓客戶端保持原樣並告訴服務器該服務應該位於客戶端期望的路徑上,則可以修改web.xml以使servlet在當前客戶端的路徑上可用期待找到它:

<servlet-mapping> 
    <servlet-name>peopleService</servlet-name> 
    <url-pattern>/MatesWeb/org.matesweb.Main/PeopleService</url-pattern> 
</servlet-mapping> 

再次請注意,我已經改變了案件 - 它可能並不重要,但我通常喜歡是一致的。

0

第一直覺是PeopleService必須在@RemoteServiceRelativePath peopleService。請使用螢火蟲監控您的RPC請求。您可以輕鬆地觀察並驗證這些請求url問題。

更新在web.xml中的URL模式在這裏

<url-pattern>/org.matesweb.Main/greet</url-pattern> 
+0

我試着改變它,它似乎沒有任何幫助。我認爲這裏的問題是這裏的資源正在尋找: /MatesWeb/org.matesweb.Main/peopleService 當我認爲它應該在這裏尋找: /MatesWeb/peopleService – nmio