注:完成goahead將前台表單內容輸出到后台,需要文件配置提及的對route.txt做出修改,否則便會報錯。
1.首先找到goahead-4.0.2/src目錄下的goahead.c文件
在它的mian之前聲明一個static int test(Webs *wp);
在main中的websServiceEvents(&finished);之前加上
websDefineAction("test", test);
在main部分的后面定義
static int test(Webs *wp)
{
int i=0;
char *u,*p;
u=websGetVar(wp,"username","");
p=websGetVar(wp,"pwd","");
printf("username :%s\npwd :%s\n",u,p);
websWrite(wp,"UserName:%s\n",u);
websWrite(wp,"Pwd:%s\n",p);
websSetStatus(wp, 200);
websWriteHeaders(wp, 0, 0);
websWriteEndHeaders(wp);
websDone(wp);
return 0;
}
保存,重新編譯goahead
./congfigure make sudo make install
2.編寫前端文件,這里給的文件名是formtest.asp
在goahead-3.6.5/bliud/linux-x86/bin下新建一個web目錄來存放它
<!DOSTYPE html>
<html>
<head>
<title>formtest</title>
<meta charset="UTF-8">
</head>
<body>
<form action=/goform/test method="post">
<table><tr><td>賬號:</td><td><input type="text" name="username"></td></tr>
<tr><td>密碼:</td><td><input type="password" name="pwd"></td></tr>
<tr><td><input type="submit" value="submit"></td>
<td><input type="reset" value="reset"></td></tr></table>
</form>
</body>
</html>
然后回到bin目錄下輸入sudo goahead -v --home /etc/goahead /home/tbs/goahead-4.0.2/bliud/linux-x86.../bin/web 0.0.0.0:8080
在瀏覽器中輸入http://0.0.0.0:8080/formtest.asp