2011-04-22 68 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