Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 是否可以在GWT的服务器端呈现html?_Java_Gwt - Fatal编程技术网

Java 是否可以在GWT的服务器端呈现html?

Java 是否可以在GWT的服务器端呈现html?,java,gwt,Java,Gwt,我在GWT中有无法移动到客户端的服务器端对象(即:not@GwtCompatible)。我想在页面上使用它们。我可以使用gwt将它们呈现为html并发送到客户端吗?当然,您可以在服务器上构建html代码段,例如: 服务器端: public class MyServiceImpl extends RemoteServiceServlet implements MyService { public String getHtmlSnippet(String param) { Strin

我在GWT中有无法移动到客户端的服务器端对象(即:not@GwtCompatible)。我想在页面上使用它们。我可以使用gwt将它们呈现为html并发送到客户端吗?

当然,您可以在服务器上构建html代码段,例如:

服务器端:

public class MyServiceImpl extends RemoteServiceServlet implements MyService {

  public String getHtmlSnippet(String param) {

    String html = buildHtmlSnippetInASafeWay(param); // Use any (safe) HTML
                                                     // builder you like. (this
                                                     // is not GWT related!)
    return html;
  }
}
客户端:

myService.getHtmlSnippet(myParam, new AsyncCallback<String>() {

  @Override
  public void onSuccess(String result) {
    myParent.add(new HTML(result));
    // or: myElem.setInnerHTML(result);
  }

  @Override
  public void onFailure(Throwable caught) {
    // ...
  }
});
myService.getHtmlSnippet(myParam,新的AsyncCallback(){
@凌驾
成功时的公共void(字符串结果){
添加(新的HTML(结果));
//或者:myElem.setInnerHTML(结果);
}
@凌驾
失败时的公共无效(可丢弃){
// ...
}
});

但是更好的解决方案可能是创建一个简单的数据对象,将您需要的数据从非GWT兼容类复制到该对象中,将其传输到客户端,然后像往常一样在那里使用。

当然,您可以在服务器上构建一个HTML片段,例如:

服务器端:

public class MyServiceImpl extends RemoteServiceServlet implements MyService {

  public String getHtmlSnippet(String param) {

    String html = buildHtmlSnippetInASafeWay(param); // Use any (safe) HTML
                                                     // builder you like. (this
                                                     // is not GWT related!)
    return html;
  }
}
客户端:

myService.getHtmlSnippet(myParam, new AsyncCallback<String>() {

  @Override
  public void onSuccess(String result) {
    myParent.add(new HTML(result));
    // or: myElem.setInnerHTML(result);
  }

  @Override
  public void onFailure(Throwable caught) {
    // ...
  }
});
myService.getHtmlSnippet(myParam,新的AsyncCallback(){
@凌驾
成功时的公共void(字符串结果){
添加(新的HTML(结果));
//或者:myElem.setInnerHTML(结果);
}
@凌驾
失败时的公共无效(可丢弃){
// ...
}
});
但更好的解决方案可能是创建一个简单的数据对象,将您需要的数据从非GwtCompatible类复制到该对象中,将其传输到客户端,然后像往常一样在那里使用