注意:我在实际工作中并不适用的cgic,而是用cgicc。因为上传文件cgic特别慢!
html的表单:<form id="myform" action="./cgi-bin/mycfg.cgi" method = "post" enctype="x-www-form-urlencoded">
<form name="upgradeFrom" οnsubmit="return validInputDetect()" ACTION="../cgi-bin/login.cgi" method="post" enctype="multipart/form-data">
其中提交的参数是"name=值"形式:<input type="file" id="updateDeviceFile" name="updateDeviceFile" multiple="true" />
jsquery 请求解析json数据:
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$.getJSON("/example/jquery/demo_ajax_json.js",function(result){
$.each(result, function(i, field){
$("p").append(field + " ");
});
$("p").append(": " + result.firstName + "," + result.lastName + "," + result.age)
});
});
});
</script>
</head>
<body>
<button>获得 JSON 数据</button>
<p></p>
</body>
</html>
jsquery动态加载一个表格:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>动态创建表格</title>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script>
function CreateTable(rowCount,cellCount)
{
var table=$("<table border=\"1\" cellspacing=\"0\">");
table.appendTo($("#createtable"));
for(var i=0;i<rowCount;i++)
{
var tr=$("<tr></tr>");
tr.appendTo(table);
for(var j=0;j<cellCount;j++)
{
var td=$("<td>"+i*j+"</td>");
td.appendTo(tr);
}
}
//trend.appendTo(table);
$("#createtable").append("</table>")
}
</script>
</head>
<body>
<input type="button" value="添加表格" onClick="CreateTable(5,6)" >
<input type="button" value="添加行">
<div id="createtable"></div>
<div id="createrow"></div>
</body>
</html>
1.网页请求时, #?&的意义:
#是用来指导浏览器动作的,就是在网页内部跳转位置参考(https://www.runoob.com/js/js-void.html),对服务器端完全无用,不会发送给服务器。所以,HTTP请求中不包括#。
比如,访问下面的网址,http://www.example.com/index.html#print,浏览器实际发出的请求是这样的:
?&是请求网络时添加的参数,其中?表示GET方法跟的参数,可以用cgiFormString("id", idbuf, sizeof(idbuf));方法获取:
&是不同参数的间隔符
http://www.xxx.com/Show.cgi?id=77&nameid=2905210001&page=1
2.
CGI页面跳转: CGI实现HTML页面跳转的几种方式
https://blog.csdn.net/qq_31776303/article/details/91986751
CGI操作Session:
https://blog.csdn.net/marysa/article/details/24252407
https://blog.csdn.net/gerryzhu/article/details/5417023
上面链接方法个人总结:登录成功,生成一个临时文件:/tmp/cgi-$(ip)-$(随机值),保存当前时间。
每次提交时查看是否超时,没有超时更新临时文件的时间;如果超时,则退出登录。
CSS关于margin、border、padding区别:
https://www.cnblogs.com/dongh/p/9584962.html
3.设置了cookie,不能直接使用脚本跳转页面,参考如下:
cgiHeaderCookieSetString(CGI_WEB_SESSION_NAME, tmpbuf,
CGI_WEB_SESSION_MAX_SAVE_TIME, cgiScriptName, SERVER_NAME);
cgiHeaderContentType("text/html");
fprintf(cgiOut, "<HTML><HEAD>\n");
fprintf(cgiOut, "<TITLE>cgic test</TITLE></HEAD>\n");
fprintf(cgiOut, "<BODY>\n");
fprintf(cgiOut, "<script>window.location.href = '../Main.html';</script>");
fprintf(cgiOut, "</BODY></HTML>\n");
4.cgi传入参数参考。
[2020-10-12 9:59:19.762]dbg[cgiMain,45]cgiServerSoftware:lighttpd/1.4.55
[2020-10-12 9:59:19.762]dbg[cgiMain,46]cgiServerName:192.168.5.196
[2020-10-12 9:59:19.762]dbg[cgiMain,47]cgiGatewayInterface:CGI/1.1
[2020-10-12 9:59:19.762]dbg[cgiMain,48]cgiServerProtocol:HTTP/1.1
[2020-10-12 9:59:19.762]dbg[cgiMain,49]cgiServerPort:80
[2020-10-12 9:59:19.762]dbg[cgiMain,50]cgiRequestMethod:GET
[2020-10-12 9:59:19.762]dbg[cgiMain,51]cgiPathInfo:
[2020-10-12 9:59:19.762]dbg[cgiMain,52]cgiScriptName:/cgi-bin/lzLogin.cgi
[2020-10-12 9:59:19.762]dbg[cgiMain,53]cgiQueryString:menuId=3
[2020-10-12 9:59:19.762]dbg[cgiMain,54]cgiRemoteHost:
[2020-10-12 9:59:19.762]dbg[cgiMain,55]cgiRemoteAddr:192.168.5.196
[2020-10-12 9:59:19.762]dbg[cgiMain,56]cgiAuthType:
[2020-10-12 9:59:19.762]dbg[cgiMain,57]cgiRemoteUser:
[2020-10-12 9:59:19.762]dbg[cgiMain,58]cgiRemoteIdent:
[2020-10-12 9:59:19.762]dbg[cgiMain,59]cgiContentType:
[2020-10-12 9:59:19.762]dbg[cgiMain,61]cgiCookie:LZ_SESSION_ID=cgi-192.168.5.1961602467958264
[2020-10-12 9:59:19.762]dbg[cgiMain,62]cgiAccept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
[2020-10-12 9:59:19.762]dbg[cgiMain,63]cgiUserAgent:Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0
[2020-10-12 9:59:19.762]dbg[cgiMain,64]cgiReferrer:http://192.168.5.196/Main.html
[2020-10-12 9:59:19.762]dbg[cgiMain,66]tmppwd:3//备注:获得的时GET(?)方法带入的参数:cgiFormString("getval", tmppwd, sizeof(tmppwd));
[2020-10-12 9:59:19.762][dbg][removeCookies,105]cgi-192.168.5.1961602467958264//备注:这个是得到的cookie值
<script>window.location.href = '../Login.html';</script
5.在表单中,如果用get,参数将显示在url中,post不会:
<form ACTION="/cgi-bin/lzLogin.cgi" method = "get" enctype="x-www-form-urlencoded"></form>
6.关于cgi中cookie的注意点:
通过cgiHeaderCookieSet设置cookie,当options配置了Secure且domain设置为空""时,才可以使用https获得cookie。且这个时候http访问是不能收到cookie的!
参考:cout << HTTPHTMLHeader().setCookie(HTTPCookie(CGI_WEB_SESSION_NAME, sessionval, "", "", CGI_WEB_SESSION_MAX_SAVE_TIME, cenv.getScriptName(), true));
我的lighttpd配置成了都支持,但是http只有在没有Secure情况获得cookie,https需要设置了Secure才能获得cookie。我也做过这样一个实验:如果请求url时http,我使用设置没有Secure的cookie,请求https时则设置Secure;但是这种情况只要浏览器使用https访问过一次后,http就不能获取到cookie了。应该他们两有冲突。
"cgi-bin/lzLogin.cgi"请求数据时,浏览器不发送cookie!当使用表单(submit)时,有参数,则会发送cookie。或者url带有参数,也会发送cookie,如:cgi-bin/lzLogin.cgi?menuId=1
例如:
<script>
function Exit() {
//TODO:清空Session信息
window.location.href = '../cgi-bin/lzLogin.cgi?menuId=1';
}
</script>