1、Form
建立一个form.asp,并保存到项目/web/目录下,内容如下:
Rights Reserved.->
Goahead Form Testtype="text/css">
Goahead Form Test
1
method=POST>
Name: | type=text name=name size=50 value=""> |
Addr: | type=text name=addr size=50 value=""> |
ALIGN="CENTER"> name=ok value="OK"> type=submit name=ok value="CANCEL"> |
在 goahead 中增加如下内容:
websFormDefine(T("formTest"),
formtest); // 注册
static void formtest(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("
Name:
%s, Addr: %sn"),name,
addr);
websFooter(wp);
websDone(wp, 200);
}
运行如下:
ip/form.asp
输入信息,确认后显示:
2、ASP
建立一个asp.asp,并保存到项目/web/目录下,内容如下:
id="view">
串口状态
cellspacing="0" cellpadding="0">
width="">串口
width="">线路协议
width="">波特率(bps)
width="">数据位
width="">起始位
width="">停止位
width="">奇偶校验
width="">流控
"Lanj"); %>
中增加如下内容:
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;
static void getPortA(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";
}
static int getPortAttrib( int eid,
webs_t wp, int argc, char_t **argv)
//
原型{
int i=0;
int SerialNum = 2;
STPortAttributeList
PortAttributeList[SerialNum];
printf("Parameter = %dn",argc);
while(i <
argc)
{
printf("Parameter %d =
%sn",i,*(argv+i));
i++;
}
i = 0;
getPortA(wp,PortAttributeList);
while(i
{
websWrite(wp,T("
"));websWrite(wp,T("
%s"),PortAttributeList[i].port);websWrite(wp,T("
%s"),PortAttributeList[i].agreement);websWrite(wp,T("
%s"),PortAttributeList[i].bandrate);websWrite(wp,T("
%s"),PortAttributeList[i].figure);websWrite(wp,T("
%s"),PortAttributeList[i].outset);websWrite(wp,T("
%s"),PortAttributeList[i].termination);websWrite(wp,T("
%s"),PortAttributeList[i].parityCheck);websWrite(wp,T("
%s"),PortAttributeList[i].flowControl);websWrite(wp,T("
"));i++;
}
return 0;
}
运行结果如下:
3、CGI
建立一个cgi.asp,并保存到项目/web/目录下,内容如下:
action="/cgi-bin/cgitest">
SIZE="5">
size="5">
value="OK">
新建 cgitest.c,程序如下:
#include
#include
int main(void)
{
char *data;
int i;
long m=0,n=0;
printf("Content-type: text/htmlnn");
printf("
MultiS
");printf("
Multi
S");
data = getenv("QUERY_STRING");
printf("
%sn",data);
if(data == NULL)
printf("
ERROR! DATA
NO INPUT");
else
if(sscanf(data,"m=%ld&n=%ld",&m,&n)!=2)
printf("
ERROR! DATA
GET ERROR");
else
printf("
%ld * %ld =
%ld.", m, n, m*n);
return 0;
}
编译后把可执行文档 cgitest 保存到 /cgi-bin/ 目录。
运行如下:
输入信息,结果如下: