1、Form
建立一个form.asp,并保存到项目/web/目录下,内容如下:
<html>
<!-Copyright(c) Go Ahead software Inc.,2012-2012.AllRights Reserved.->
<head>
<title>Goahead Form Test</title>
<link rel="stylesheet" href="style/normal_ws.css"type="text/css">
</head>
<body>
<h1>Goahead Form Test1</h1>
<form action=/goform/formTestmethod=POST>
<table>
<tr>
<td>Name:</td><td><inputtype=text name=name size=50value=""></td>
</tr>
<tr>
<td>Addr:</td><td><inputtype=text name=addr size=50value=""></td>
</tr>
<tr>
<td></td>
<tdALIGN="CENTER">
<inputtype=submit name=ok value="OK"><input type=submit name=okvalue="CANCEL"></td>
</tr>
</table>
</form>
</body>
</html>
在 goahead 中增加如下内容:
websFormDefine(T("formTest"),formtest);// 注册
staticvoidformtest(webs_t wp, char_t *path, char_t*query) // 原型
{
char_t*name, *addr;
name = websGetVar(wp, T("name"), T(""));
addr = websGetVar(wp, T("addr"), T(""));
websHeader(wp);
websWrite(wp,T("<body><h2>Name:%s, Addr: %s</h2>n"),name,addr);
websFooter(wp);
websDone(wp, 200);
}
运行如下:
ip/form.asp
输入信息,确认后显示:
2、ASP
建立一个asp.asp,并保存到项目/web/目录下,内容如下:
<divid="view">
<h4>串口状态</h4>
<table id="viewTab" cellspacing="0"cellpadding="0">
<tr>
<thwidth="">串口</th>
<thwidth="">线路协议</th>
<thwidth="">波特率(bps)</th>
<thwidth="">数据位</th>
<thwidth="">起始位</th>
<thwidth="">停止位</th>
<thwidth="">奇偶校验</th>
<thwidth="">流控</th>
</tr>
<%MakePortAttributeList("1", "Test", "Lanj"); %>
</table>
</div>
在 goahead中增加如下内容:
websAspDefine(T("MakePortAttributeList"),getPortAttrib);// 注册
typedef struct PortAttributeList{
char_t *port;
char_t *agreement;
char_t *bandrate;
char_t *figure;
char_t *outset;
char_t *termination;
char_t *parityCheck;
char_t *flowControl;
}STPortAttributeList;
staticvoidgetPortA(webs_t wp, STPortAttributeList *PortAttributeList)
{
PortAttributeList[0].port="1";
PortAttributeList[0].agreement="RS232";
PortAttributeList[0].bandrate="1200";
PortAttributeList[0].figure="8";
PortAttributeList[0].outset="1";
PortAttributeList[0].termination="1";
PortAttributeList[0].parityCheck="ODD";
PortAttributeList[0].flowControl="Hardware";
PortAttributeList[1].port="2";
PortAttributeList[1].agreement="RS485";
PortAttributeList[1].bandrate="9600";
PortAttributeList[1].figure="8";
PortAttributeList[1].outset="1";
PortAttributeList[1].termination="1";
PortAttributeList[1].parityCheck="EVEN";
PortAttributeList[1].flowControl="NO";
}
staticint getPortAttrib(int eid, webs_t wp, int argc, char_t**argv)// 原型
{
int i=0;
int SerialNum = 2;
STPortAttributeListPortAttributeList[SerialNum];
printf("Parameter=%dn",argc);
while(i <argc)
{
printf("Parameter%d=%sn",i,*(argv+i));
i++;
}
i = 0;
getPortA(wp,PortAttributeList);
while(i<SerialNum)
{
websWrite(wp,T("<tr>"));
websWrite(wp,T("<td>%s</td>"),PortAttributeList[i].port);
websWrite(wp,T("<td>%s</td>"),PortAttributeList[i].agreement);
websWrite(wp,T("<td>%s</td>"),PortAttributeList[i].bandrate);
websWrite(wp,T("<td>%s</td>"),PortAttributeList[i].figure);
websWrite(wp,T("<td>%s</td>"),PortAttributeList[i].outset);
websWrite(wp,T("<td>%s</td>"),PortAttributeList[i].termination);
websWrite(wp,T("<td>%s</td>"),PortAttributeList[i].parityCheck);
websWrite(wp,T("<td>%s</td>"),PortAttributeList[i].flowControl);
websWrite(wp,T("</tr>"));
i++;
}
return 0;
}
运行结果如下:
参考:http://www.docin.com/p-253322636.html
http://www.docin.com/p-308398551.html
3、CGI
建立一个cgi.asp,并保存到项目/web/目录下,内容如下:
<formaction="/cgi-bin/cgitest">
<input name="m"SIZE="5">
<input name="n"size="5"><BR>
<input type="submit"value="OK">
</form>
新建 cgitest.c,程序如下:
#include<stdio.h>
#include<stdlib.h>
intmain(void)
{
char*data;
inti;
longm=0,n=0;
printf("Content-type: text/htmlnn");
printf("<TITLE>Multi S</TITLE>");
printf("<H3>MultiS</H3>");
data=getenv("QUERY_STRING");
printf("<P>%sn",data);
if(data == NULL)
printf("<P>ERROR! DATA NO INPUT");
elseif(sscanf(data,"m=%ld&n=%ld",&m,&n)!=2)
printf("<P>ERROR! DATA GET ERROR");
else
printf("<P>%ld * %ld = %ld.", m, n, m*n);
return0;
}
编译后把可执行文档 cgitest 保存到 /cgi-bin/ 目录。
运行如下:
输入信息,结果如下: