2

我写了 2 页,一个在 php 中,接收到 HTTP Post 变量并保存在文件中

<?php
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData =$_POST['var'];
fwrite($fh, $stringData);
fclose($fh);
?>

以及带有此代码的 vaadin 页面:

package com.example.primovaadin;

import org.vaadin.risto.formsender.FormSender;
import com.vaadin.Application;
import com.vaadin.ui.*;
import com.vaadin.ui.Button.ClickEvent;

public class PrimovaadinApplication extends Application {

private static final long serialVersionUID = 1L;
FormSender formSender = new FormSender();

@Override
public void init() {
    Window mainWindow = new Window("Primovaadin Application");

    formSender.setFormMethod(FormSender.Method.POST);
    formSender.setFormTarget("http://127.0.0.1/writer.php");

    Button sendVariable = new Button("Send");
    sendVariable.addListener(new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            // TODO Auto-generated method stub
            formSender.addValue("var", "vaadin");
            formSender.submit();
        }
    });

    mainWindow.addComponent(sendVariable);
    setMainWindow(mainWindow);
  }
}

但是当我单击 vaadin 应用程序上的 bottun 时,变量不会发送到 php 页面...请帮助我...

4

1 回答 1

0

我认为这个问题的答案是:

private void runReport(HashMap<String, String> params) {
        // TODO Enviar post ao BIRT
        final FormSender formSender = new FormSender();
        Window mainWindow = new Window();
        formSender.setFormMethod(FormSender.Method.POST);
        formSender.setFormTarget("http://localhost:8080/birt/frameset");

        formSender.addValue("", "");

        for (Entry<String, String> entry : params.entrySet()) {
            formSender.addValue(entry.getKey(), entry.getValue());
        }

        mainWindow.setImmediate(true);
        mainWindow.addComponent(formSender); << You just forgot to add the component to the screen.
        formSender.submit();

        getMainWindow().setContent(mainWindow);
    }
于 2012-10-24T17:11:31.760 回答