读取表单文件并将其内容发送到GWT中的clinet

发布于 2024-11-03 10:21:04 字数 92 浏览 1 评论 0原文

我需要在服务器端读取表单 TXT 文件并将其内容发送到客户端以在标签或任何东西中打印,我需要知道我将 TXT 文件放在服务器包上还是在 WAR 中,以及如何编码吗??谢谢

I need to read form TXT file on the server side and send its contents to the client side to print in a label or any thing, i need to know where i place the TXT file is it on the server package or in WAR and how to code it?? thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独行侠 2024-11-10 10:21:04

文件放在哪里并不重要。它必须位于服务器上,并且 php 脚本必须能够打开该文件。您可以使用 php 按以下方式准备文本文件。
然后使用 GWT 向该文件发出 http 请求。

读取文件:

<?php
// get contents of a file into a string
$filename = "/usr/local/something.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
echo $contents;
?>

发出 http 请求:

public class GetExample implements EntryPoint {
  public static final int STATUS_CODE_OK = 200;

  public static void doGet(String url) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);

    try {
      Request response = builder.sendRequest(null, new RequestCallback() {
        public void onError(Request request, Throwable exception) {
          // Code omitted for clarity
        }

        public void onResponseReceived(Request request, Response response) {
          String content = response.getText();
        }
      });
    } catch (RequestException e) {
      // Code omitted for clarity
    }
  }

  public void onModuleLoad() {
    doGet("/");
  }
}

It doens't really matter where you place the file. It must be on the server and a php script must be able to open the file. You can ready the text file the following way with php.
Then make a http request with GWT to that file.

Read the file:

<?php
// get contents of a file into a string
$filename = "/usr/local/something.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
echo $contents;
?>

Make http request:

public class GetExample implements EntryPoint {
  public static final int STATUS_CODE_OK = 200;

  public static void doGet(String url) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);

    try {
      Request response = builder.sendRequest(null, new RequestCallback() {
        public void onError(Request request, Throwable exception) {
          // Code omitted for clarity
        }

        public void onResponseReceived(Request request, Response response) {
          String content = response.getText();
        }
      });
    } catch (RequestException e) {
      // Code omitted for clarity
    }
  }

  public void onModuleLoad() {
    doGet("/");
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文