我写了 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 页面...请帮助我...