goahead php 例子,[转载]Goahead的一些参考例子

1、Form

建立一个form.asp,并保存到项目/web/目录下,内容如下:

Rights Reserved.->

Goahead Form Test

type="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

a4c26d1e5885305701be709a3d33442f.png

输入信息,确认后显示:

a4c26d1e5885305701be709a3d33442f.png

2、ASP

建立一个asp.asp,并保存到项目/web/目录下,内容如下:

id="view">

串口状态

cellspacing="0" cellpadding="0">

width="">串口

width="">线路协议

width="">波特率(bps)

width="">数据位

width="">起始位

width="">停止位

width="">奇偶校验

width="">流控

"Lanj"); %>

在 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;

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;

}

运行结果如下:

a4c26d1e5885305701be709a3d33442f.png

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("

Multi

S

");

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/ 目录。

运行如下:

a4c26d1e5885305701be709a3d33442f.png

输入信息,结果如下:

a4c26d1e5885305701be709a3d33442f.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值