我写了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页面... 请帮帮我......
答案 0 :(得分: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);
}