




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、browsers and serverscgi processing model(common gateway interface) norman white, 2013www and client server computingforms & cgi programmingwriting a cgi programserver computers are located all around the world and respond to requests (messages) from computers running browser software (netscape,
2、ie)browser applications understand html, (and now javascript, java etc.)web server sends a header in front of each file identifying the file type (html,gif,jpeg etc.)most browsers understand html, gif and textbrowsers can be configured to call external programs to handle new types of filesthese prog
3、rams are called helper applications and dramatically extend the capabilities of the browser, since they can be developed independently of the client softwareexamples - quicktime viewers, sound players, vrml viewers etc.to see the currently configured viewers go to options on the browser title barbro
4、wser functionality can also be extended by adding plugins.plugins are not standalone applications, but executable code that is dynamically linked into the browser when necessary.html provides an easy to use form capability, which allows a wide variety of input forms to be easily generated.form data
5、types include text input - one line of texttextarea - multiple lines of textcheck boxes (on/off)radio boxes (1 of n)etc.output of form is formatted and sent to server, along with the name of a program to process the contents of the form.the web server takes information from form, and passes it on as
6、 input to a common gateway interface program (cgi)output of cgi program is sent back to client browser as an html (or other) file.cgi programs can do an almost unlimited set of activities .look up info in a database and send it to browser.take input from user and add to a file.take input and send to
7、 a standard business applicationcgi program can be in any language that runs on the server, including a shell language like sh or bash.develop form to collect information from userswrite and test cgi program to handle form informationput the name of the cgi program in the “action” statement of the f
8、orm.note: program can be on another server.two types of form processing options, get and postget - parameters sent as additions to url string. each individual parameter separated by &post - data sent in message body. this is a more general method and can handle more input data.server sends form
9、(in html document) to clientclient displays form, and user fills in fieldsclient sends form info to server (submit button)server runs the cgi program named in the action section of the formcgi program parses data as inputoutput of cgi program is sent by the server to the client (i.e. it should be ht
10、ml)advantagesvery general model, easy to do really neat things like front end existing applications, databases etc.many toolkits available to do common thingsdisadvantagesall processing is done on server. may overload serverinteraction is all through formslots of data traffic back and forthsolutionh
11、tml5 and its featurescgi program needs to parse form inputprocess the inputgenerate html outputget formatinformation is passed as a series of variable=value pairs separated by “&” to program named in action statement by adding them on to the url (after a “?”)simple example one line form with a f
12、ield named “userid” and “action=mycgiprog.cgi”user enters “nwhite”browser sends the following to the web server/nwhite/mycgiprog.cgi?userid=nwhiteweb server takes the information after the “?” and creates an environment variable named “query_string”, then executes the program
13、“mycgiprog.cgi”query_string contains userid=nwhitecgi program retrieves value of query_string, does appropriate processing, and (optionally) sends an html response backboth windows and unix support environment variables. these are user session variables which contain character strings. many are auto
14、matically created when the user logs in, like path, prompt etc. any program can create or retrieve the value of environment variables, so they are often used to pass small amounts of information from one application to another. different operating systems have different methods for setting and retri
15、eving environment variables. for example, in unix, you can retrieve an environment variables value by putting a $ in front of it i.e. $path. in windows, you put % around it. i.e. %path%try this in unixecho $pathor windowsecho %path%what if we want have more than one field?no problem query_string can
16、 contain many variable=value pairs separated by “&” i.e. userid=nwhite&password=junk&fname=normanpossible problem, how big can environment variables be (how many characters)get only useful for limited inputpost method is more general since it can handle lots of inputinput is passed as a
17、sequence of characters (stdin)variable1=value1&variable2=value2.environment variable content_length is set to the number of characters of input.environment variable request_method is set to post (instead of get)input processing logic needs to be (slightly) different for get and post methodscgi o
18、utput is passed back to the browser, hence has to be something (html) the browser can understand likecontent-type: text/html output of html from cgi script sample output what do you think of this? list the contents of your “websys” directorycreate a shell script named lister.cgi which contains#! /bi
19、n/sh#echo “content-type: text/html”echo “ “echo listingecho ls altecho list the contents of your “websys” directorywith options passed as part of url (type=xxx)create a shell script named lister.cgi which contains#! /bin/sh#eval qs=echo $query_stringeval echo $qs|sed e “s/&/ /g” echo “content-ty
20、pe: text/html”echo echo listing echo ls *.$typeecho to run it, put it in your websys directorychmod +rx lister.cgitype the following as a url/userid/websys/lister.cgi?type=htmlyour useridin the post method, form data is not passed as part of the url, instead it is passed to the “standard input” of the cgi program.advantagesnot limited by max size of environment variablesusers cant see the input fieldsdisadvantagesa little harder to handleuser
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 畜牧业疫病防控合作项目合同
- 2025综合承包施工合同
- 2025届高考政治一轮复习专题四发展社会主义市抄济23围绕主题抓住主线精练含解析
- 自考行政管理视野拓展试题及答案
- 2025年度合作协议 个人加盟外贸企业代理合同
- 2025如何编写租赁合同
- 行政决策科学化的路径试题及答案
- 2025城市更新项目房屋征收补偿合同范本
- 2025版终止解除租赁合同协议书模板
- 行政管理创新与市政学试题及答案
- 四川省绵阳市高中2022级第三次诊断性考试地理试题及答案(A卷)
- 压疮引起的疼痛护理
- 上海市静安区2025年高三二模英语试卷(含答案)
- 车间卫生打扫管理制度
- 造价风险防范管理制度
- 护理管理学中的化学性伤害
- 供暖项目可行性研究报告
- 《浙江省中药饮片炮制规范》 2015年版
- 辅导员考试基础知识考题盘点
- 阀门技术协议合同
- 2025江苏省安全员B证考试题库
评论
0/150
提交评论