Goahead 嵌入式 Webserver 的一些demo [此博文包含图片]

来源:互联网 发布:台词拼长图什么软件 编辑:程序博客网 时间:2024/05/19 23:11

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/formTest method=POST>

<table>

<tr>
  <td>Name:</td><td><input type=text name=name size=50 value=""></td>
</tr>
<tr>
  <td>Addr:</td><td><input type=text name=addr size=50 value=""></td>
</tr>
<tr>
  <td></td>
   <tdALIGN="CENTER">
    <input type=submit name=ok value="OK"><input type=submit name=ok value="CANCEL"></td>
</tr>
</table>

</form>

</body>
</html>

 

 

在 goahead 中增加如下内容:

websFormDefine(T("formTest"),formtest);    // 注册

 

static voidformtest(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);
}

 

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

<divid="view">
 <h4>串口状态</h4>
 <table id="viewTab"class="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;

static voidgetPortA(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 %d\n",argc);

 while(i <argc)
 {
  printf("Parameter%d %s\n",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>

int main(void)
{
 char *data;
 int i;
 long m=0,n=0;
 printf("Content-type: text/html\n\n");
 printf("<TITLE>Multi S</TITLE>");
 printf("<H3>MultiS</H3>");
 data getenv("QUERY_STRING");

 printf("<P>%s\n",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);

 return 0;
}

编译后把可执行文档 cgitest 保存到 /cgi-bin/ 目录。



 

0 0
原创粉丝点击