dongtao9095 2011-10-19 05:00
浏览 32
已采纳

将GWT输入发布到PHP页面

I have a GWT app with inputs (let's say Name, Address, Email). After user input all the required fields and press submit button, a PHP page will display the inputs from the GWT app. How can I connect my GWT app to php? I'm using Request Builder now. Do I still have to use XML to pass the GWT inputs to PHP? Please help. I'm just starting to learn GWT here.

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • duanmu5641 2011-10-19 11:05
    关注

    You actually don't need RequestBuilder for something like that.
    It would be sufficient if you redirect to the PHP url and append your inputs as GET parameters. So for example in the click handler you can do something like that:

    submitButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            String linkURL = "somePage.php?name="+name+"&address="+address+"&email="+email;
             Window.Location.assign(linkURL);
        }
    });
    

    and then in the PHP page you can retrieve the parameters in this way:

    $name = $_GET['name'];
    $address = $_GET['address'];
    $email = $_GET['email'];
    

    Update

    If you want to use RequetBuilder you have to do something like that:

    submitButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            RequestBuilder request = new RequestBuilder(POST,PHP_URL);
            JSONObject jsonValue = new JSONObject();
            jsonValue.put("name", new JSONString(name));
            jsonValue.put("address", new JSONString(address));
            jsonValue.put("email", new JSONString(email));
            request.setHeader("Content-Type", "application/json");
            request.sendRequest(jsonValue.toString(),new RequestCallback() {
                @Override
                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                         //retrieve a uniqueid or so and redirect to the PHP page which displays the infos
                    } else {
                       // displayError("Couldn't retrieve 
    
                    }
                }
    
                @Override
                public void onError(Request request, Throwable exception) {
                     //displayError("Couldn't retrieve JSON");
                }
             });
    
        }
    });
    

    On the server you just access the global $_POST variable to get the values:

    $name = @_POST['name']
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度