2011-04-22 69 views

回答

1

它不关心你放置文件的位置。它必须在服务器上,并且一个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("/"); 
    } 
} 
+0

感谢您的回复,但在那里我地方PHP代码? – Islam 2011-04-22 14:55:50

+0

在您的网络服务器上。例如我有一个web应用程序,并在战争目录中有另一个名为php的dir。在这个文件夹中我有我所有的PHP脚本。当我编译我的GWT应用程序时,我将整个war文件夹复制到一个web服务器。 – 2011-04-22 15:14:13

+0

P.S我也使用谷歌应用程序引擎进行部署... – Islam 2011-04-22 15:19:23