2014-01-07 96 views
0

我有這個JavaScript代碼正在與服務連接併發回結果。從GWT撥打一些在線服務

現在需求是從Pure Java調用相同的服務。

以下是調用服務的JavaScript代碼。

如果有人能指導我此Javascript到Java轉換在我的GWT應用

感謝

  function verifyValidationSyntax(textToValidate) 

     { 
     var url = "https://validation-grammar.example.com/validation_grammar_service/rest/validation_step_validation"; 
     var client = new XMLHttpRequest(); 
     client.open("POST", url, false); 
     client.setRequestHeader("Content-Type", "text/plain"); 
     client.send(textToValidate); 
     if (client.responseText==='true') { 
     return "true"; 
     } else { 
     return "false"; 
     } 

     } 

回答

2

我不會將您的代碼,但在這裏是從docs

String url = "http://www.myserver.com/getData?type=3"; 
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url)); 

try { 
    Request request = builder.sendRequest(null, new RequestCallback() { 
    public void onError(Request request, Throwable exception) { 
     // Couldn't connect to server (could be timeout, SOP violation, etc.) 
    } 

    public void onResponseReceived(Request request, Response response) { 
     if (200 == response.getStatusCode()) { 
      // Process the response in response.getText() 
     } else { 
     // Handle the error. Can get the status text from response.getStatusText() 
     } 
    } 
    }); 
} catch (RequestException e) { 
    // Couldn't connect to server 
} 
最甜蜜的例子

您可能會錯過這篇文檔

To use the HTTP types in your application, you'll need to first inherit the GWT HTTP module by adding the following tag to your module XML file:

<inherits name="com.google.gwt.http.HTTP" /> 
+0

感謝,反應不能被解析爲type.Dont查看該進口任何建議,請指導 – junaidp

+0

http://www.gwtproject.org/javadoc/latest/com/google/gwt/http/client/ Response.html –

+0

謝謝..當我運行我得到這個錯誤:java.lang.UnsatisfiedLinkError:com.google.gwt.http.client.URL.encodeImpl(Ljava/lang/String;)Ljava/lang/String; – junaidp