| 网站首页 | 资讯 | 影音 | 图片 | 论坛 | 模拟驾考 | 免费取名算命 | 瓷都工具 | 留言本 | 域名 | 瓷都商城 | 汇款 | 
|
鐠у嫯顔嗘#鏍€�
|
閻$兘鍏樺宄板
|
缁旀瑥鍞撮弬浼存
|
瑜拌精顫嬮崜褎鍎�
|
濮瑰€熸簠娑撴牜鏅�
|
缂冩垹绮堕弬鍥ㄦ喅
|
閸涖劍妲楅崗顐㈠捶
|
閺佹瑧鈻奸幎鈧锟�
|
閹村じ楠囨穱鈩冧紖
|
您现在的位置: 瓷都热线|诚信中国:“一就是一”(1941.CN) >> 资讯 >> 教程技巧0 >> 网络编程 >> 正文 登录 注册
专 题 栏 目
  • 閸ユ稑绐涘Ч璺虹獩8.0缁狙冨繁闂囷拷
  • 閺堝搫濮╂潪锕傗敋妞硅泛鎲抽懓鍐槸鐠у嫭鏋�
  • 妤傛ǹ鈧啳鐦0妯哄挤缁涙梹顢�
  • 最 新 热 门
    最 新 推 荐
    相 关 文 章
    没有相关资讯
    [组图]校园网中CGI环境的建立和应用         ★★★
    校园网中CGI环境的建立和应用
    作者:傅叔平 文章来源:成都教育学院 更新时间:2006-7-2 11:41:14
    【声明:转载此信息在于传递更多信息,其内容表达的观点并不代表本站立场,由这些信息所产生的一切后果本站不负任何责任。如果您对本信息有什么意见,欢迎和本站联系,谢谢!】http://CiDu.Net

    八     应用实例

      最后,举一个在校园网中实际应用的例子。任务是针对学院将要对教职员工举办的《电子备课》和《校园网应用基础》两个培训班实现网上报名。
      程序一是用HTML写的表单程序,它的任务是在客户端的浏览器窗口中显示一个报名表,让报名者填写并提交。如图6。注意它的form的action为“/cgi_perl/baoming.pl”,即为表单提交后调用的CGI程序。程序一的源代码应存放在默认Web站点存放主页的目录中(参见《CGI软件环境的建立》一节)。 


    图6

      程序二是用Perl语言写的CGI程序,它的任务是检验用户从客户端提交的“培训类别”、“系处室”、“姓名”和“E-mail地址”四个数据,如果正确则将它们写入服务器上的“baomingbiao.txt”文件之中并返回报名成功的信息;否则返回报名失败的信息。它的源代码应存放在Perl的可执行文件目录中(参见《CGI软件环境的建立》一节),文件的扩展名应为“.pl”,本例中的文件名为“baoming.pl”

      请注意,在程序一和程序二中都有对用户的输入进行检验的程序段。程序一中是用JavaScript写的函数“function CheckValid(form)”;程序二中是用如下的语句:

    if(length($cname)==0 || length($email)!=0 && index($email,"@")==-1)
       print"     报名失败,请返回重新填报!!!<cr>";

      其实,既然客户端程序已进行了检验,服务器端的CGI程序就不必再作检验了。此处只是为了示例,说明此检验工作既可在客房端进行,也可在服务器端进行。那么,在哪里进行更好呢?由于在客房端运行程序比在服务器端运行快得多,所以像这种既可在客户端又可在服务器端完成的工作就最好在客户端进行。//by http://CiDu.Net/

      程序一与程序二的源代码附后。它们均在Windows 2000 Server+IIS(服务器端)、Windows 98+Internet Explorer 5环境中实际使用。
     
    程序一(HTML程序源代码)
    <html>
    <head>
    <meta http-equiv=Content-Type content=text/html; charset=gb2312>
    <title>培训报名</title>
    <style type=text/css>
      <!--
       body{font-size:11pt;}
       .p{font-size:12pt;color:red;}
       .p1{font-size:10pt;}
      -->
    </style>
    <script language="JavaScript">
    <!--
       function CheckValid()
       {
          if(document.cidu_net.name.value=="")
          {
             alert("未填姓名!");
             document.cidu_net.name.focus();
     return false;
          }
          else
             if(document.cidu_net.email.value!="
    " && document.cidu_net.email.value.indexOf("@")==-1)
             {
                alert("错误的 E-mail 地址!");
                document.cidu_net.email.focus(); 
      return false;
             } 

    return true;
       }
    // -->
    </script>
    </head>
    <body bgColor=#ffe4c4 text=#000000>
    <center>
    <form action="/cidu.net/cgi_perl/baoming.pl" name=cidu_net method="post" onsubmit="return CheckValid();">
       <table class="p1" border="1" cellpadding="1" width="463">
          <caption class=p>
             <p style="line-height: 150%">
             <b><font color="#0000FF"><span style="letter-spacing: 8pt"><big>培训报名表</big></span></font></b><br>
             <font size="2">
             (有**的为必填项)</font>
          </caption>
          <tr>
             <td align="right" width="229">** 培训类别:</td>  
             <td width="226">  
                <input type="radio" name="class" value="校园网应用基础" checked>校园网应用基础 
                 <input type="radio" name="class" value="电子备课">电子备课
             </td>
          </tr>
          <tr>
             <td align="right" width="229">** 系处室:</td>   
             <td width="377"><select size="1" name="department">
                <option>院办</option>
                <option>党办</option>
                <option>招生就业处</option>
                <!--  其它行政单位略  -->
                <option>计算机系</option>
                <option>经管系</option>
                <!--  其它系略  -->
              </select></td>  
          </tr>  
          <tr>  
             <td align="right" width="229">** 姓名:</td>   
             <td width="226"><input type="text" name="name" size="15"></td>   
          </tr>   
          <tr> 
             <td align="right" width="229"> 你的E-mail地址:</td>   
             <td width="226"><input type="text" name="email" size="32"></td>   
          </tr>   
       </table>    
       <br>   
       <input type="submit" value="提交">   
         <input type="reset" value="重填">
    </form> 
    </center> 
    </body> 
    </html>

     
    程序二(CGI程序源代码)
    #! e:\perl\bin\
    sub ToChnString
    {
       my($i)=0;
       my($chnstring)="";
       my($code0)=0; my($code1)=0;
       my($string)=@_;
       for($i=0;$i<length($string);)
       {
           if(substr($string,$i,1) eq ’%’)
           {
              $temp=(substr($string,$i+1,1).substr($string,$i+2,1));
              $chnstring.=chr(hex($temp));
              $i+=3;
           }
           else
           {
              $chnstring.=substr($string,$i,1);
              $i++;
           }
        }
        return($chnstring);
    }
     
    print"Content-type:text/html\n\n";
    print”<html>”;
    print”<head>”;
    print"<title>报名结果</title>";
    print”</head>”;
    print”<body>”;
     
    $string=$ENV{’QUERY_STRING’};
    @temp = split(/&/,$string); 
    @temp1=split(/=/,@temp[0]); 
    @temp2=split(/=/,@temp[1]); @temp3=split(/=/,@temp[2]); 
    @temp4=split(/=/,@temp[3]); 
    $class=@temp1[1]; $dep=@temp2[1]; $name=@temp3[1]; $email=@temp4[1];
    $cclass=ToChnString($class);
    $cdep=ToChnString($dep);
    $cname=ToChnString($name);
    if(length($cname)==0 || length($email)!=0 && index($email,"@")==-1)
       print"     报名失败,请返回重新填报!!!<cr>";
    else
    {
       if (open(fp,">>baomingbiao.txt"))
       {
          # here’s what to do if the file opened successfully
          print fp ("$cclass,$cdep,$cname,$email\n");
          close(fp);
          print"     <u>报名结果</u>:<br><br>";
          print"     <b>类 别</b>:$cclass<br>";
          print"     <b>部 门</b>:$cdep<br>";
          print"     <b>姓 名</b>:$cname<br>";
          print"     <b>E-mail</b>:$email<br>";
          print"<br><br>     报名成功!<br>"
       }
       else
       {
          print"\a\a\a     写报名结果失败,请重新填报!!!<br>";
          die();
       }
    }
    print"<br><br>";
    print"     <A href=javascript:history.back()>返 回</a>";
    print"</body>";
    print"</html>";

    上一页  [1] [2] [3] [4] [5] 


    声明:以上信息资料大都是网上搜集而来,版权归作者,如有版权问题请留言告知我将马上改正。
    文中所提到的各种观点只是原文观点,各种说法未经一一确认。并不代表本站认可此观点!!
    资讯录入:admin    责任编辑:admin 
  • 上一篇资讯:

  • 下一篇资讯:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    点击数:2849
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
        没有任何评论