亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch05_03.htm

?? 用perl編寫CGI的好書。本書從解釋CGI和底層HTTP協議如何工作開始
?? HTM
?? 第 1 頁 / 共 2 頁
字號:
<?label 5.3. Generating Output with CGI.pm?><html><head><title>Generating Output with CGI.pm (CGI Programming with Perl)</title><link href="../style/style1.css" type="text/css" rel="stylesheet" /><meta name="DC.Creator" content="Scott Guelich, Gunther Birznieks and Shishir Gundavaram" /><meta scheme="MIME" content="text/xml" name="DC.Format" /><meta content="en-US" name="DC.Language" /><meta content="O'Reilly & Associates, Inc." name="DC.Publisher" /><meta scheme="ISBN" name="DC.Source" content="1565924193L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="CGI Programming with Perl" /><meta content="Text.Monograph" name="DC.Type" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" alt="Book Home" usemap="#banner-map" border="0" /><map name="banner-map"><area alt="CGI Programming with Perl" href="index.htm" coords="0,0,466,65" shape="rect" /><area alt="Search this book" href="jobjects/fsearch.htm" coords="467,0,514,18" shape="rect" /></map><div class="navbar"><table border="0" width="515"><tr><td width="172" valign="top" align="left"><a href="ch05_02.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td width="171" valign="top" align="center"><a href="index.htm">CGI Programming with Perl</a></td><td width="172" valign="top" align="right"><a href="ch05_04.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><hr align="left" width="515" /><h2 class="sect1">5.3. Generating Output with CGI.pm</h2><p><a name="INDEX-1079" /> <a name="INDEX-1,080" /> <a name="INDEX-1,081" />CGI.pm provides a veryelegant solution for outputting both headers and HTML with Perl. Itallows you to embed HTML in your code, but it makes this more naturalby turning the HTML into code. Every<a name="INDEX-1082" />HTML element can begenerated via a corresponding method in <a name="INDEX-1083" /> <a name="INDEX-1,084" />CGI.pm. We have already seensome examples of this already, but here's another:</p><blockquote><pre class="code">#!/usr/bin/perl -wTuse strict;use CGI;my $q = new CGI;my $timestamp = localtime;print $q-&gt;header( "text/html" ),      $q-&gt;start_html( -title =&gt; "The Time", -bgcolor =&gt; "#ffffff" ),      $q-&gt;h2( "Current Time" ),      $q-&gt;hr,      $q-&gt;p( "The current time according to this system is: ",             $q-&gt;b( $timestamp ) ),      $q-&gt;end_html;</pre></blockquote><p>The resulting output looks like this (the indentation is added tomake it easier to read):</p><blockquote><pre class="code">Content-type: text/html&lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"&gt;&lt;HTML&gt;  &lt;HEAD&gt;&lt;TITLE&gt;The Time&lt;/TITLE&gt;&lt;/HEAD&gt;  &lt;BODY BGCOLOR="#ffffff"&gt;    &lt;H2&gt;Current Time&lt;/H2&gt;    &lt;HR&gt;    &lt;P&gt;The current time according to this system is:      &lt;B&gt;Mon May 29 16:48:14 2000&lt;/B&gt;&lt;/P&gt;  &lt;/BODY&gt;&lt;/HTML&gt;</pre></blockquote><p>As you can see, the code looks a lot like Perl and a lot less likeHTML. It is also shorter than the corresponding HTML because CGI.pmmanages some common tags for us. Another benefit is that it isimpossible to forget to <a name="INDEX-1085" />close a tag because the methodsautomatically generate closing tags (except for those elements thatCGI.pm knows do not need them, like &lt;HR&gt;).</p><p>We'll look at all of these output methods in this section,starting with the first method, <tt class="function">header</tt>.</p><a name="ch05-14-fm2xml" /><div class="sect2"><h3 class="sect2">5.3.1. Controlling HTTP Headers with CGI.pm</h3><p>CGI.pm has two methods for returning<a name="INDEX-1086" /><a name="INDEX-1087" />HTTP headers:<tt class="function">header</tt> and <tt class="function">redirect</tt>. They correspondto the two ways you can return data from CGI scripts: you can returna document, or you can redirect to another document.</p><a name="ch05-15-fm2xml" /><div class="sect3"><h3 class="sect3">5.3.1.1. Media type</h3><p>The <tt class="function">header</tt> method handles<a name="INDEX-1088" />multiple HTTP headers for you. If youpass it one argument, it returns the<em class="emphasis">Content-type</em><a name="INDEX-1089" /> header with that value. If you do notsupply a media type, it defaults to "text/html". AlthoughCGI.pm makes outputting HTML much easier, you can of course print anycontent type with it. Simply use the <tt class="function">header</tt>method to specify the <a name="INDEX-1090" />media type and then print your content,whether it be text, XML, Adobe PDF, etc.:</p><blockquote><pre class="code">print $q-&gt;header( "text/plain" );print "This is just some boring text.\n";</pre></blockquote><p>If you want to set other headers, then you need to pass<a name="INDEX-1091" />name-value pairs for each header. Usethe <tt class="literal">-type</tt> argument to specify the media type (seethe example under <a href="ch05_03.htm#ch05-79140">Section 5.3.1.2, "Status"</a> later in thischapter).</p></div><a name="ch05-79140" /><div class="sect3"><h3 class="sect3">5.3.1.2. Status</h3><p>You can specify a <a name="INDEX-1092" />status other than "200 OK" byusing the <tt class="literal">-status</tt> argument:</p><blockquote><pre class="code">print $q-&gt;header( -type =&gt; "text/html", -status =&gt; "404 Not Found" );</pre></blockquote></div><a name="ch05-16-fm2xml" /><div class="sect3"><h3 class="sect3">5.3.1.3. Caching</h3><p>Browsers <a name="INDEX-1093" /> <a name="INDEX-1,094" /><a name="INDEX-1095" />can't always tell if<a name="INDEX-1096" /> <a name="INDEX-1,097" />content isbeing dynamically generated by CGI or if it is coming from a staticsource, and they may try to cache the output of your script. You candisable this or <a name="INDEX-1098" /><a name="INDEX-1099" />request caching if you want it, byusing the <tt class="literal">-expires</tt> argument. You can supply eithera full time stamp with this argument or a<a name="INDEX-1100" /><a name="INDEX-1101" />relative time. Relative timesare created by supplying a plus or minus sign for forward orbackward, an integer number, and a one letter abbreviation forsecond, minute, hour, day, month, or year (each of theseabbreviations is lowercase except for month, which is an uppercaseM). You can also use "now" to indicate that a documentshould expire immediately. Specifying a negative value also has thiseffect.</p><p>This example tells the browser that this document is good for thenext 30 minutes:</p><blockquote><pre class="code">print $q-&gt;header( -type =&gt; "text/html", -expires =&gt; "+30m" );</pre></blockquote></div><a name="ch05-17-fm2xml" /><div class="sect3"><h3 class="sect3">5.3.1.4. Specifying an alternative target</h3><p>If you are using frames or have multiple windows, you may want<a name="INDEX-1102" /> <a name="INDEX-1,103" /> <a name="INDEX-1,104" />links in one document toupdate another document. You can use the<tt class="literal">-target</tt><a name="INDEX-1105" /> <a name="INDEX-1,106" />argument along with the name of the other document (as set by a<a name="INDEX-1107" /><a name="INDEX-1108" />&lt;FRAMESET&gt;tag or by JavaScript) to specify that clicking on a link in thisdocument should cause the new resource to load in the other frame (orwindow):</p><blockquote><pre class="code">print $q-&gt;header( -type =&gt; "text/html", -target =&gt; "main_frame" );</pre></blockquote><p>This argument is only meaningful for HTML documents.</p></div><a name="ch05-18-fm2xml" /><div class="sect3"><h3 class="sect3">5.3.1.5. Redirection</h3><p>If you need to redirect to another URL, you can use the<tt class="function">redirect</tt><a name="INDEX-1109" /> <a name="INDEX-1,110" /> method instead of printing the<em class="emphasis">Location</em> HTTP header:</p><blockquote><pre class="code">print $q-&gt;redirect( "http://localhost/survey/thanks.html" );</pre></blockquote><p>Although the term "redirect" is an action, this methoddoes not perform a redirect for you; it simply returns thecorresponding header. So don't forget you still need to printthe result!</p></div><a name="ch05-19-fm2xml" /><div class="sect3"><h3 class="sect3">5.3.1.6. Other headers</h3><p>If you need to generate other <a name="INDEX-1111" />HTTP headers, you can simplypass the name-value pair to <tt class="function">header</tt> and it willreturn the header with the appropriate formatting. Underscores areconverted to hyphens for you.</p><p>Thus, the following statement:</p><blockquote><pre class="code">print $q-&gt;header( -content_encoding  =&gt; "gzip" );</pre></blockquote><p>produces the following <a name="INDEX-1112" /> <a name="INDEX-1,113" /> <a name="INDEX-1,114" />output:</p><blockquote><pre class="code">Content-encoding: gzip</pre></blockquote></div></div><a name="ch05-20-fm2xml" /><div class="sect2"><h3 class="sect2">5.3.2. Starting and Ending Documents</h3><p>Now let's look <a name="INDEX-1115" /> <a name="INDEX-1,116" /><a name="INDEX-1117" />at the methods that you can use togenerate HTML. We'll start by looking at the methods forstarting and ending documents.</p><a name="ch05-21-fm2xml" /><div class="sect3"><h3 class="sect3">5.3.2.1. start_html</h3><p>The <tt class="function">start_html</tt> method returns the HTML DTD, the&lt;HTML&gt; tag, the &lt;HEAD&gt; section including &lt;TITLE&gt;,and the &lt;BODY&gt; tag. In the previous example, it generates HTMLlike the following:</p><blockquote><pre class="code">&lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"&gt;&lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;The Time&lt;/TITLE&gt;&lt;/HEAD&gt;&lt;BODY BGCOLOR="#ffffff"&gt;</pre></blockquote><p>The most common arguments <tt class="function">start_html</tt> recognizesare as follows:</p><ul><li><p>Setting the <tt class="literal">-base</tt> argument to a true value tellsCGI.pm to include a <a name="INDEX-1118" /><a name="INDEX-1119" /><a name="INDEX-1120" />&lt;BASEHREF="url"&gt; tag in the head of your document that points to theURL of your script.</p></li><li><p>The <tt class="literal">-meta</tt> argument accepts a reference to a hashcontaining the name and content of <a name="INDEX-1121" /><a name="INDEX-1122" /><a name="INDEX-1123" />meta tags that appear in the head of yourdocument.</p></li><li><p>The <tt class="literal">-script</tt><a name="INDEX-1124" /><a name="INDEX-1125" /> argument allows you to addJavaScript to the head of your document. You can either provide astring containing the JavaScript code or a reference to a<a name="INDEX-1126" />hash containing<tt class="literal">-language</tt>, <tt class="literal">-src</tt>, and<tt class="literal">-code</tt> as possible keys. This allows you to specifythe language and source attributes of the<a name="INDEX-1127" /><a name="INDEX-1128" />&lt;SCRIPT&gt; tag too. CGI.pmautomatically provides comment tags around the code to protect itfrom browsers that do not recognize JavaScript.</p></li><li><p>The <tt class="literal">-noscript</tt><a name="INDEX-1129" /><a name="INDEX-1130" /> argument allows you tospecify HTML display if the <a name="INDEX-1131" />browser does not supportJavaScript. It is inserted into the head of your document.</p></li><li><p>The <tt class="literal">-style</tt> argument allows you to define a<a name="INDEX-1132" />style sheet for the document.Like <tt class="literal">-script</tt>, you may either specify a string or areference to a hash. The keys that <tt class="literal">-style</tt> acceptsin the hash are <tt class="literal">-code</tt> and <tt class="literal">-src</tt>.The value of <tt class="literal">-code</tt> will be inserted into thedocument as style sheet information. The value of<tt class="literal">-src</tt> will be a URL to a <em class="filename">.css</em>file. CGI.pm automatically provides<a name="INDEX-1133" />comment tagsaround the code to protect cascading style sheets from browsers thatdo not recognize them.</p></li><li><p>The <tt class="literal">-title</tt> argument sets the<a name="INDEX-1134" />title of the HTML document.</p></li><li><p>The <tt class="literal">-xbase</tt><a name="INDEX-1135" /> <a name="INDEX-1,136" /><a name="INDEX-1137" /> argument lets youspecify a URL to use in the &lt;BASE HREF="url"&gt; tag. This isdifferent from the <tt class="literal">-base</tt> argument that alsogenerates this tag but sets it to the URL of the current CGI script.</p></li></ul><p>Any other arguments, like <tt class="literal">-bgcolor</tt>, are passed asattributes to the &lt;BODY&gt; tag.</p></div><a name="ch05-22-fm2xml" /><div class="sect3"><h3 class="sect3">5.3.2.2. end_html</h3><p>The <em class="emphasis">end_html</em><a name="INDEX-1138" /><a name="INDEX-1139" /><a name="INDEX-1140" /> method returnsthe &lt;/BODY&gt; and &lt;/HTML&gt; tags.</p></div></div><a name="ch05-23-fm2xml" /><div class="sect2"><h3 class="sect2">5.3.3. Standard HTML Elements</h3><p><a name="INDEX-1141" />HTML elements can begenerated by <a name="INDEX-1142" /> <a name="INDEX-1,143" />using the lowercase name of the element asa method, with the following exceptions: <tt class="function">Accept</tt>,<tt class="function">Delete</tt>, <tt class="function">Link</tt>,<tt class="function">Param</tt>, <tt class="function">Select</tt>,<tt class="function">Sub</tt>, and <tt class="function">Tr</tt>. These methodshave an initial cap to avoid conflicting with built-in Perl functionsand other CGI.pm methods.</p><p>The following rules apply to basic <a name="INDEX-1144" /><a name="INDEX-1145" />HTML tags:</p><ul><li><p>CGI.pm recognizes that some elements, like &lt;HR&gt; and &lt;BR&gt;,do not have <a name="INDEX-1146" />closing tags. Thesemethods take no arguments and return the single tag:</p><blockquote><pre class="code">print $q-&gt;hr;</pre></blockquote><p>This outputs:</p><blockquote><pre class="code">&lt;HR&gt;</pre></blockquote></li><li><p>If you provide one argument, it creates an opening and closing tag toenclose the text of your argument. Tags are capitalized:</p><blockquote><pre class="code">print $q-&gt;p( "This is a paragraph." );</pre></blockquote><p>This prints the text:</p><blockquote><pre class="code">&lt;P&gt;This is a paragraph.&lt;/P&gt;</pre></blockquote></li><li><p>If you provide multiple arguments, these are simply joined with thetags at the beginning and the end:</p><blockquote><pre class="code">print $q-&gt;p( "The server name is:", $q-&gt;server_name );</pre></blockquote><p>This prints the text:</p><blockquote><pre class="code"><a name="INDEX-1147" />&lt;P&gt;The server name is: localhost&lt;/P&gt;</pre></blockquote>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲一区视频在线观看视频| 国产激情视频一区二区三区欧美| 日韩制服丝袜av| 国产成人丝袜美腿| 欧美猛男男办公室激情| 国产精品蜜臀在线观看| 日韩一区精品字幕| 欧美性一二三区| 国产精品久久久久久久久搜平片| 久久精品国产99国产精品| 色8久久人人97超碰香蕉987| 亚洲国产成人午夜在线一区 | 亚洲影院在线观看| 国产高清在线精品| 精品福利av导航| 日本欧美肥老太交大片| 欧美美女一区二区在线观看| 中文字幕在线观看不卡视频| 国产成人啪午夜精品网站男同| 欧美一级久久久久久久大片| 亚洲国产精品自拍| 在线日韩一区二区| 亚洲综合av网| 在线观看国产日韩| 亚洲一区二区免费视频| 欧美色偷偷大香| 午夜伊人狠狠久久| 欧美日韩国产一区二区三区地区| 亚洲一二三四区| 欧美日韩一区二区三区视频| 亚洲第一av色| 日韩午夜中文字幕| 黄色小说综合网站| 2023国产精华国产精品| 国内精品久久久久影院一蜜桃| 精品剧情在线观看| 国产精品资源网| 日本一区二区免费在线观看视频| 国产成人午夜高潮毛片| 国产精品福利av| 欧美在线播放高清精品| 午夜av一区二区| 欧美sm美女调教| 国产精品资源在线观看| 国产精品久久久久久久久久久免费看 | 在线综合亚洲欧美在线视频| 丝袜亚洲精品中文字幕一区| 欧美一区二区国产| 国产一区二区三区| 国产精品久久久久久久久免费桃花| 日产精品久久久久久久性色| 欧美少妇一区二区| 久久精品国产免费| 国产目拍亚洲精品99久久精品| 波多野结衣中文字幕一区| 亚洲人成亚洲人成在线观看图片| 在线免费观看日本一区| 日韩成人一区二区三区在线观看| 欧美v国产在线一区二区三区| 国产黄色精品网站| 亚洲精品欧美专区| 日韩欧美一区二区在线视频| 国产福利不卡视频| 一区二区视频在线| 日韩欧美一区二区久久婷婷| 懂色av一区二区三区免费看| 一区二区三区中文字幕在线观看| 欧美va在线播放| 色妞www精品视频| 精品一二线国产| 亚洲一区二区三区四区中文字幕 | 国产午夜久久久久| 91久久精品午夜一区二区| 久草在线在线精品观看| 亚洲三级久久久| 日韩免费成人网| 日本道免费精品一区二区三区| 久久99精品国产| 一区二区三区精品视频| 久久精品亚洲精品国产欧美kt∨| 欧美日韩亚洲国产综合| 成人h动漫精品一区二区| 麻豆精品视频在线观看| 亚洲综合色成人| 国产精品美女一区二区在线观看| 日韩欧美在线综合网| 91女人视频在线观看| 国产成人午夜精品影院观看视频 | 97久久精品人人做人人爽| 老汉av免费一区二区三区| 亚洲男人的天堂在线aⅴ视频| 欧美大片顶级少妇| 欧美日韩视频一区二区| 91视频91自| 成人18视频在线播放| 国产一区二三区好的| 日本成人在线电影网| 亚洲精品国产高清久久伦理二区| 国产欧美精品一区aⅴ影院| 欧美成va人片在线观看| 91精品中文字幕一区二区三区| 99精品欧美一区| 成人成人成人在线视频| 成人免费视频app| 成人免费看的视频| 成人免费精品视频| 不卡一区二区中文字幕| 国产白丝网站精品污在线入口 | 亚洲影视在线播放| 亚洲欧洲日韩综合一区二区| 欧美国产日韩精品免费观看| 国产视频一区二区三区在线观看| 欧美一级久久久| 日韩欧美中文字幕精品| 精品国产污网站| 精品国产a毛片| 国产欧美一区二区精品仙草咪| 久久久久国产精品麻豆ai换脸| 久久免费精品国产久精品久久久久| 欧美成va人片在线观看| 久久亚洲捆绑美女| 中文字幕精品三区| 亚洲欧美自拍偷拍色图| 一区二区三区久久| 午夜在线电影亚洲一区| 日本欧洲一区二区| 黄色小说综合网站| 99精品欧美一区二区蜜桃免费| 日本韩国欧美一区| 制服丝袜在线91| 国产亚洲欧美激情| 一区二区三区日韩精品视频| 偷拍日韩校园综合在线| 狠狠色丁香婷婷综合久久片| 成人亚洲精品久久久久软件| 91行情网站电视在线观看高清版| 欧美日韩国产一区二区三区地区| 欧美一级艳片视频免费观看| 久久久99久久| 一区二区三区av电影 | 一区二区三区欧美日| 亚洲一区二区三区在线| 久久99久久精品| 97se亚洲国产综合自在线不卡 | 国产欧美日韩不卡免费| 亚洲精品视频一区| 日本欧美在线观看| 99视频精品全部免费在线| 欧美军同video69gay| 中文字幕第一区二区| 亚洲香蕉伊在人在线观| 久久99久久精品| 欧美色电影在线| 日本一二三不卡| 麻豆国产精品777777在线| 99精品欧美一区二区蜜桃免费 | 欧美伦理影视网| 中文字幕高清一区| 免费一级片91| 日本道色综合久久| 国产欧美视频一区二区| 热久久免费视频| 91网址在线看| 国产欧美日韩不卡免费| 麻豆成人免费电影| 欧美在线观看一二区| 国产精品视频一区二区三区不卡| 五月激情综合色| 色综合婷婷久久| 中日韩免费视频中文字幕| 日韩不卡一区二区三区| 色噜噜偷拍精品综合在线| 精品久久国产97色综合| 国产综合色精品一区二区三区| 欧美日韩一区二区在线观看| 国产精品久久久久7777按摩| 另类专区欧美蜜桃臀第一页| 欧美日韩高清在线播放| 伊人夜夜躁av伊人久久| 成人av资源在线观看| 国产欧美一区二区精品性| 九九九久久久精品| 欧美成人精品1314www| 轻轻草成人在线| 91精品国产综合久久香蕉麻豆| 一区二区三区精品在线观看| 91丨九色丨国产丨porny| 国产精品久久久久久久久久久免费看 | 国产色产综合色产在线视频| 麻豆精品一区二区综合av| 日韩欧美一区二区免费| 美女性感视频久久| 日韩欧美电影在线| 免费观看在线综合色| 日韩精品一区二区三区视频| 日韩极品在线观看| 欧美一区二区视频网站| 奇米一区二区三区av| 日韩写真欧美这视频| 久久电影网电视剧免费观看|