Java 从GWT调用一些在线服务
我有一个JavaScript代码,它连接到服务并返回结果 现在需要从纯Java调用相同的服务 下面是调用服务的javascript代码 如果有人能指导我在GWT应用程序中将Javascript转换成Java 谢谢Java 从GWT调用一些在线服务,java,gwt,Java,Gwt,我有一个JavaScript代码,它连接到服务并返回结果 现在需要从纯Java调用相同的服务 下面是调用服务的javascript代码 如果有人能指导我在GWT应用程序中将Javascript转换成Java 谢谢 function verifyValidationSyntax(textToValidate) { var url = "https://validation-grammar.example.com/validation_g
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";
}
}
我不会转换你的代码,但这里有一个来自 在文档中您可能会错过这个 要在应用程序中使用HTTP类型,首先需要通过向模块XML文件添加以下标记来继承GWT HTTP模块:
谢谢,无法将响应解析为类型。请不要看到任何有关该类型的导入建议,谢谢。。当我运行时,我得到这个错误:java.lang.UnsatisfiedLinkError:com.google.gwt.http.client.URL.encodeImpl(Ljava/lang/String;)Ljava/lang/String;不知道它是否允许https。您是否尝试过使用http链接的其他示例?尝试此链接,给出相同的错误
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
}
<inherits name="com.google.gwt.http.HTTP" />