2012-06-27 4 views
6

Non connettersi al server ... si tratta di un progetto in ultima eclissi GWTGWT ATTENZIONE: Nessun file trovati per: /com.mycompany.project.ImageViewer/GreetingService

al clic sul pulsante in GWT:

greetServer(textToServer, 
         new AsyncCallback<String>() { 
          public void onFailure(Throwable caught) { 
           // Show the RPC error message to the user 
           dialogBox 
             .setText("Remote Procedure Call - Failure"); 
           serverResponseLabel 
             .addStyleName("serverResponseLabelError"); 
           serverResponseLabel.setHTML(SERVER_ERROR); 
           dialogBox.center(); 
           closeButton.setFocus(true); 
          } 

          public void onSuccess(String result) { 
           dialogBox.setText("Remote Procedure Call"); 
           serverResponseLabel 
             .removeStyleName("serverResponseLabelError"); 
           serverResponseLabel.setHTML(result); 
           dialogBox.center(); 
           closeButton.setFocus(true); 
          } 
         }); 

mio server GWT:

public String greetServer(String input) throws IllegalArgumentException { 
     // Verify that the input is valid. 
     if (!FieldVerifier.isValidName(input)) { 
      // If the input is not valid, throw an IllegalArgumentException back to 
      // the client. 
      throw new IllegalArgumentException(
        "Name must be at least 4 characters long"); 
     } 

     String serverInfo = getServletContext().getServerInfo(); 
     String userAgent = getThreadLocalRequest().getHeader("User-Agent"); 

     // Escape data from the client to avoid cross-site script vulnerabilities. 
     input = escapeHtml(input); 
     userAgent = escapeHtml(userAgent); 

     return "Hello, " + input + "!<br><br>I am running " + serverInfo 
       + ".<br><br>It looks like you are using:<br>" + userAgent; 
    } 

è il mio GWT servise:

@RemoteServiceRelativePath("greet") 
public interface GreetingService extends RemoteService { 
    String greetServer(String name) throws IllegalArgumentException; 
} 
file di

GWT serviseAsyn:

public interface GreetingServiceAsync { 
    void greetServer(String input, AsyncCallback<String> callback) 
      throws IllegalArgumentException; 
} 


web xml 

    <!-- Servlets --> 
    <servlet> 
    <servlet-name>greetServlet</servlet-name> 
    <servlet-class>kill.server.GreetingServiceImpl</servlet-class> 
    </servlet> 

    <servlet-mapping> 
    <servlet-name>greetServlet</servlet-name> 
    <url-pattern>/hello123/greet</url-pattern> 
    </servlet-mapping> 

    <!-- Default page to serve --> 
    <welcome-file-list> 
    <welcome-file>Hello123.html</welcome-file> 
    </welcome-file-list> 

sul pulsante di scatto - il server non restituisce il valore, perché non trovare il file - perché?

Jun 27, 2012 11:12:13 AM com.google.appengine.tools.development.LocalResourceFileServlet doGet 
WARNING: No file found for: /com.mycompany.project.ImageViewer/GreetingService 

cosa fare?

risposta

6

Nel file web.xml mappare il servizio come /hello123/greet:

<servlet-mapping> 
    <servlet-name>greetServlet</servlet-name> 
    <url-pattern>/hello123/greet</url-pattern> 
</servlet-mapping> 

mentre l'errore mostra che sta cercando di caricare il valore predefinito di /modulename/serviceinterfacename o/com.mycompany.project.ImageViewer/GreetingService. Sono disponibili due opzioni:

  1. Modificare la voce web.xml per utilizzare l'URL di default che l'interfaccia RPC si aspetta
  2. Configurare il servizio remoto per caricare dal proprio percorso personalizzato
  3. brevemente

Entrambe le tesi sono discussi a https://developers.google.com/web-toolkit/doc/latest/DevGuideServerCommunication, insieme ad altri dettagli di configurazione RPC.

Per la seconda opzione, questo di solito si presenta come segue:

MyServiceAsync service = GWT.create(MyService.class); 
((ServiceDefTarget)service).setServiceEntryPoint("/hello123/greet"); 
service.methodName(... 
Problemi correlati