# include <stdlib.h>
int main()
{
char *data
long m,n
printf("Content-Type:text/html \r\n\r\n")
printf("<html><head>\n")
printf("<title>hello world </title>\n")
printf("</head>\n")
printf("<body>\n")
printf("<h1>hello world </h1>\n")
data = getenv("QUERY_STRING")
if(sscanf(data,"m=%ld&n=%ld",&m,&n)!=2)
printf("<P >错误!输入数据非法。表单中输入的必须是数字。</p>")
else
printf("<P >%ld和%ld的成绩是:%ld。",m,n,m*n)
printf("</body></html>\n")
return 0
}
只用过cgic,内部跳转在cgiMain函数中使用类似fprintf(cgiOut, "<script type=\"text/javascript\">window.location.href='mfgtool.cgi'</script>\n</HEAD>\n")这样可以跳转到你想到的页面。和Web服务器软件没关系,不管是apache还是其他,都是一样跳转,只要路径一致。处理表单,在cgic中提供了函数接口,可以调用,比如的到客户端传过来的字符串:
//enter flag
cgiFormString("flag", flag, 32)
其中"flag"为客户端post过来的data键值对的键,flag是cgi中定义的char数组,用于接收post过来的键值对的值。这样就得到了客户端传递过来的值。
cgi输出到浏览器其实是加载静态html格式文件,然后读到特定字符,然后将cgi得到的值替换掉特定字符,然后出去到浏览器,进行显示。
至于调用postgreSQL数据库,我不太清楚,但是用C/C++链接数据库是肯定没问题的,这个帮不到你了。