【问题标题】:Access HttpServlet response from GWT client从 GWT 客户端访问 HttpServlet 响应
【发布时间】:2014-05-28 14:46:02
【问题描述】:

我们有以下场景:

我们希望在 gwt 客户端中显示来自我们的报告框架的 html 输出。 我们可以通过 HttpServlet 访问生成的 html 内容,并将其输出写入

HttpServletResponse.getOutputStream()

我们已经了解了 RequestBuilder。但是响应看起来不像来自 HttpServlet 的响应。

是否有机会从 GWT 中的 HttpServlet 响应中访问数据?

问候 本

【问题讨论】:

    标签: servlets gwt


    【解决方案1】:

    如果您不介意在项目中引入GQuery,您可以使用 Ajax 功能轻松完成。

    查看官方文档:

    https://code.google.com/p/gwtquery/wiki/Ajax

    但基本上是这样的:

    Settings settings = Ajax.createSettings()
        .setUrl("my/url")
        .setDataType("txt") // txt, json, jsonp, xml
        .setType("get")     // post, get
        .setData(GQuery.$$("param1: 1, param2: 2")) // parameters for the query-string
        .setTimeout(3000);
    
    Ajax.ajax(settings)
      .done(new Function(){ public void f() {
        for (int i=0; i<getArguments().length; i++) {
          Object arg = getArgument(i);
          Window.alert("Argument["+i+"] - "+arg.toString());
        }
      }}).fail(new Function(){ public void f() {
        Window.alert("There was an error doing Ajax call");
      }});
    

    如果这不起作用,请检查请求是否已正确完成(Chrome 上的 F12 > 网络),我的响应是假设 Servlet 中的请求已正确处理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-17
      • 1970-01-01
      • 1970-01-01
      • 2018-02-21
      相关资源
      最近更新 更多