Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 29.92 KB | None | 0 0
  1. 1. Develop and demonstrate a XHTML file that includes JavaScript script for  the following problems:
  2. a) Input : A number n obtained using prompt
  3.    Output: The first n Fibonacci numbers
  4. /************************* Program1a.html *************************/
  5. <?xml version="1.0" encoding="UTF-8"?>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  7. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  8. <html xmlns="http://www.w3.org/1999/xhtml">
  9. <head>
  10.     <title>Program to generate Fibonacci numbers</title>
  11. </head>
  12. <body>
  13.     <script type="text/javascript">
  14.     var f1=0;
  15.     var f2=1;
  16.     var f3=0;
  17.     var limit=prompt("Enter the Limits\n","");
  18.     if(limit!=null&&limit>0)
  19.     {
  20.         document.write("<h2><b/><i/>The Fibonacci Series for "+limit+"</h2>\n");
  21.         if(limit==1)
  22.         document.write(f1,"<br/>");
  23.         else
  24.         document.write(""+f1+"<br>"+f2+"<br/>");
  25.         for(i=3;i<=limit;i++)
  26.         {
  27.             f3=f1+f2;
  28.             document.write(""+f3+"<br/>");
  29.             f1=f2;
  30.             f2=f3;
  31.         }      
  32.     }  
  33.     else
  34.     alert("Please enter a valid number");
  35. </script>
  36. </body>
  37. </html>
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. /*************************Output*************************/
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91. 1. b) Input : A number n obtained using prompt
  92.    Output: a table of numbers from 1 to n and their squares using alert.
  93. /*************************Program1b.html *************************/
  94. <?xml version="1.0" encoding="UTF-8"?>
  95. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  96. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  97. <html xmlns="http://www.w3.org/1999/xhtml">
  98. <html >  
  99. <body>    
  100. <script type="text/javascript">
  101. var num = prompt("Enter a number : \n", "");
  102. if(num >0 && num !=null)
  103. {
  104.     msgstr="Number and its Squares are \n";
  105.     for(i=1;i <= num; i++)
  106.     {
  107.             msgstr = msgstr +  i  + " - " + i*i + "\n";
  108.     }
  109.     alert(msgstr);
  110. }                          
  111. else                  
  112. alert("No input supplied");    
  113. </script>    
  114. </body>      
  115. </html>
  116. /*************************Output*************************/
  117.  
  118.  
  119.  
  120. 2.a) Develop and demonstrate, using JavaScript script, a XHTML document that collects the USN ( the valid format is : A digit from 1 to 4 followed by two upper-case characters followed by two digits followed by two upper-case characters followed by three digits; no embedded spaces allowed) of the user. Event handler must be included for the form element that collects this information to validate the input. Messages in the alert windows must be produced when errors are detected.
  121. /*************************Program2a.html*************************/
  122. <?xml version="1.0" encoding="UTF-8"?
  123. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  124. "http://www/w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  125. <html xmlns="http://www.w3.org/1999/xhtml">
  126. <head>
  127.     <title>Validate USN in Javascript</title>
  128.     <script type="text/javascript">
  129.     function validate_usn()
  130.     {
  131.         var str=document.getElementById("usn");
  132.         var result=str.value.search(/^[1-4]{1}[A-Z]{2}\d{2}[A-Z]{2}\d{3}$/);
  133.         if(result!=0)
  134.         {
  135.             alert("Entered usn is not in correct form");
  136.         }
  137.         else
  138.         {
  139.             alert("Entered usn ("+str.value+") is in correct form");
  140.         }
  141.     }
  142.     </script>
  143. </head>
  144. <body bgcolor="lightpink">
  145.     <form>
  146.         <h3> Enter Your USN Number: </h3>
  147.         <input type="text" id="usn">
  148.         <br/>
  149.         <br/>
  150.         <input type="submit" onclick="validate_usn();" value="submit"/>
  151.         <input type="reset" value="reset"/>
  152.     </form>
  153. </body>
  154. </html>
  155.  
  156.  
  157.  
  158.  
  159. /*************************Output*************************/
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205. 2. b) Modify the above program to get the current semester also (restricted to be a number from 1 to 8).
  206. /*************************Program2b.html*************************/
  207. <?xml version="1.0" encoding="UTF-8"?
  208. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  209. "http://www/w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  210. <html xmlns="http://www.w3.org/1999/xhtml">
  211. <head>
  212.     <title>Program to Validate USN and Semester</title>
  213.     <script type="text/javascript">
  214.     function validate_usn()
  215.     {
  216.     var str=document.getElementById("usn");
  217.     var valid_usn=str.value.search(/^[1-4]{1}[A-Z]{2}\d{2}[A-Z]{2}\d{3}$/);
  218.     var str1=document.getElementById("sem");
  219.     var valid_sem=str1.value.search(/^[1-8]{1}$/);
  220.     if(valid_usn>=0 && valid_sem>=0)
  221.     {
  222.         alert("Valid USN and Semester");
  223.     }
  224.     else if(valid_usn<0 && valid_sem >= 0)
  225.     {
  226.         alert("Invalid USN");
  227.     }
  228.     else if(valid_usn>=0 && valid_sem<0)
  229.     {
  230.         alert("Invalid Semester");
  231.     }
  232.     else
  233.     {
  234.         alert("Invalid USN and Semester");
  235.     }
  236.     }
  237.     </script>
  238. </head>
  239. <body bgcolor="lightgreen">
  240.     <form>
  241.         <table>
  242.         <tr>
  243.         <td> <br/>Enter Your USN Number: </td>
  244.         <td> <br/><input type="text" id="usn"></td>
  245.         </tr>
  246.         <tr>
  247.         <td> Enter Your Semester  : </td>
  248.         <td> <input type="text" id="sem"></td>
  249.         </tr>
  250.         <tr>
  251.         <td><input type="submit" onclick="validate_usn();" value="submit"/></td>
  252.         <td><input type="reset" value="reset"/></td>
  253.         </tr>   </table>
  254.     </form></body></html>
  255.  
  256. /*************************Output*************************/
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291. 3. a) Develop and demonstrate, using JavaScript script, a XHTML document that contains three short paragraphs of text, stacked on top of each other, with only enough of each showing so that the mouse cursor can be placed over some part of them. When the cursor is placed over the exposed part of any paragraph, it should rise to the top to become completely visible.
  292. /*************************Program3a.html*************************/
  293. <?xml version="1.0" encoding="UTF-8"?
  294. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  295. "http://www/w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  296. <html xmlns="http://www.w3.org/1999/xhtml">
  297. <head>
  298.     <title>Program to display Stacked Paragraphs</title>
  299.     <link rel="stylesheet" type="text/css" href="Program3a.css"/>
  300.     <script type="text/javascript">
  301.     var topLayer="layer3";
  302.     function stack(toTop)
  303.     {
  304.         var oldTop=document.getElementById(topLayer).style;
  305.         var newTop=document.getElementById(toTop).style;
  306.         oldTop.zIndex="0";
  307.         newTop.zIndex="10";
  308.         topLayer=document.getElementById(toTop).id;
  309.     }
  310.     </script>
  311.     <body style="background-color:orange">
  312. <h3 style="text-align:center"> Program to demonstrate the usage of stacking of Paragraphs</h3>
  313.     <div class="layer1Style" id="layer1" onmouseover="stack('layer1')">
  314. Welcome to SBMSIT. This college offers courses like computer science and engineering. Info science,Electrical and Electronics.
  315.     </div>
  316.     <div class="layer2Style" id="layer2" onmouseover="stack('layer2')">
  317. The College also offers courses like MTech - Computer science and Information Science and Master of Business Administration.
  318.     </div>
  319.     <div class="layer3Style" id="layer3" onmouseover="stack('layer3')">
  320. The college has an excellent infrastructure, beautiful ambience, separate library and admin blocks, A huge playground and a hostel facilities.
  321.     </div>
  322. </body>
  323. </html>
  324.  
  325.  
  326.  
  327. /*************************Program3a.css*************************/
  328.  
  329. .layer1Style
  330. {
  331.     border:solid thick black;
  332.     padding:1em;
  333.     width:500px;
  334.     background-color:pink;
  335.     position:absolute;
  336.     top:100px;  left:200px;
  337. }
  338.  
  339. .layer2Style
  340. {
  341.     border:solid thick black;
  342.     padding:1em;
  343.     width:500px;
  344.     background-color:yellow;
  345.     position:absolute;
  346.     top:120px;  left:220px;
  347. }
  348.  
  349. .layer3Style
  350. {
  351.     border:solid thick black;
  352.     padding:1em;
  353.     width:500px;
  354.     background-color:cyan;
  355.     position:absolute;
  356.     top:140px;
  357.     left:240px;
  358. }
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371. /*************************Output*************************/
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.    
  413.  
  414. 3. b) Modify the above document so that when a paragraph is moved from the top stacking position, it returns to its original position rather than to the bottom.
  415. /**************Program3b.html************/
  416. <?xml version="1.0" encoding="UTF-8"?
  417. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  418. "http://www/w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  419. <html xmlns="http://www.w3.org/1999/xhtml">
  420. <head>
  421.     <title>Program to display Stacked Paragraphs</title>
  422.     <link rel="stylesheet" type="text/css" href="Program3a.css"/>
  423.     <script type="text/javascript">
  424.     var topLayer="layer3";
  425.     var origPos;
  426.     function stack(toTop,pos)
  427.     {
  428.         var newTop=document.getElementById(toTop).style;
  429.         newTop.zIndex="10";
  430.         topLayer=document.getElementById(toTop).id;
  431.         origPos=pos;
  432.     }
  433.     function moveBack()
  434.     {
  435.         document.getElementById(topLayer).style.zIndex=origPos;
  436.     }
  437.     </script>
  438.     <body style="background-color:orange">
  439. <h3 style="text-align:center"> Program to demonstrate the usage of stacking of Paragraphs</h3>
  440. <div class="layer1Style" id="layer1" onmouseover="stack('layer1','1')" onmouseout="moveBack();">
  441. Welcome to SBMST. This college offers courses like computer science and engineering. Info science, Electrical and Electronics.
  442.     </div>
  443. <div class="layer2Style" id="layer2" onmouseover="stack('layer2','2')" onmouseout="moveBack();">
  444. The College also offers courses like MTech - Computer science and Information Science and Master of Business Administration.
  445.     </div>
  446. <div class="layer3Style" id="layer3" onmouseover="stack('layer3','3')" onmouseout="moveBack();">
  447. The college has an excellent infrastructure, beautiful ambience, separate library and admin blocks, A huge playground and a hostel facilities.
  448.     </div></body></html>
  449.  
  450. /*************************Output*************************/
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494. 4. a) Design an XML document to store information about a student in an engineering college affiliated to VTU. The information must include USN, Name, Name of the college, Branch, Year of Joining, and e-mail identifies. Make up sample data for 3 students. Create a CSS style sheet and use it to display the document.
  495. /*************************Program4a.xml*************************/
  496. <?xml version = "1.0"?> <?xml-stylesheet type = "text/css" href = "Program4a.css" ?>
  497.     <VTU>  
  498.     <student>
  499.         STUDENT INFO  
  500.             <USN> 1BN08CS001 </USN>                      
  501.         <name> Arun </name>
  502.             <college> SBMSIT </college>                  
  503.         <branch> CSE</branch>
  504.             <YOJ> 2008 </YOJ>                                        
  505.         <email> arun@gmail.com </email>  
  506.     </student>
  507.     <student>
  508. <USN> 1BN08CS002 </USN>                      
  509.         <name> Gopal </name>
  510.             <college> SBMSIT </college>                  
  511.         <branch> CSE</branch>
  512.             <YOJ> 2008 </YOJ>                                        
  513.         <email> gopal@gmail.com </email>
  514.           </student>
  515.     <student>
  516.         <USN> 1BN08CS003</USN>                      
  517.         <name> Sanjay </name>
  518.             <college> SBMSIT </college>                  
  519.         <branch> CSE</branch>
  520.             <YOJ> 2008 </YOJ>                                        
  521.         <email> san@gmail.com </email>
  522. </student>
  523. </VTU>  
  524. /************************* Program4a.css*************************/
  525. USN
  526. {
  527. display:block; color:blue; font-style:italic;
  528. }  
  529. college
  530. {
  531. display:block;
  532. color:green;
  533. font-style:italic;
  534. }
  535. branch
  536. {
  537. display:block; color:red; font-style:italic;
  538. }  
  539. email
  540. {
  541.  display:block; color:blue; font-style:italic;
  542. }
  543. /*************************Output*************************/
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581. 4. b) Create an XSLT style sheet for one student element of the above document and use it to create a display of that element.
  582. /*************************Program4b.xml*************************/
  583. <?xml version="1.0" encoding="ISO-8859-1"?>
  584. <?xml-stylesheet type="text/xsl" href="Program4b.xsl"?>
  585.  <vtu>
  586.     <student>
  587.         <name>Praveen</name>
  588.         <usn>1JT07IS007</usn>
  589.         <college>JIT</college>
  590.         <branch>Computer Science</branch>
  591.         <year>2007</year>
  592.         <email>praveen@jit.org</email>
  593.     </student>
  594.      <student>
  595.         <name>Pradeep</name>
  596.         <usn>1JT06IS045</usn>
  597.         <college>JIT</college>
  598.         <branch>Computer Science</branch>
  599.         <year>2006</year>
  600.         <email>pradeep@jit.edu</email>
  601.     </student>
  602.      <student>
  603.         <name>Prakash</name>
  604.         <usn>1JT05IS067</usn>
  605.         <college>JIT</college>
  606.         <branch>Computer Science</branch>
  607.         <year>2005</year>
  608.         <email>prakash@jit.in</email>
  609.     </student>
  610. </vtu>
  611. /************************* Program4b.xsl *************************/
  612. <?xml version="1.0" encoding="ISO-8859-1"?>
  613. <xsl:stylesheet version="1.0"
  614. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  615. <xsl:template match="/">
  616.     <html>
  617.     <body>
  618.         <h2> VTU Student Information</h2>
  619.         <table border="1">
  620.             <tr bgcolor="#99cd32">
  621.                 <th>name</th>
  622.                 <th>usn</th>
  623.                 <th>collegeName</th>
  624.                 <th>branch</th>
  625.                 <th>year</th>
  626.                 <th>email</th>
  627.             </tr>
  628.         <xsl:for-each select="vtu/student">
  629.        
  630.         <xsl:choose>
  631.             <xsl:when test="name = 'Praveen'">
  632.             <tr bgcolor="#ff00ff">
  633.                 <td><xsl:value-of select="name"/></td>
  634.                 <td><xsl:value-of select="usn"/></td>
  635.                 <td><xsl:value-of select="collegeName"/></td>
  636.                 <td><xsl:value-of select="branch"/></td>
  637.                 <td><xsl:value-of select="year"/></td>
  638.                 <td><xsl:value-of select="email"/></td>
  639.             </tr>
  640.             </xsl:when>
  641.             <xsl:otherwise>
  642.             <tr>
  643.                 <td><xsl:value-of select="name"/></td>
  644.                 <td><xsl:value-of select="usn"/></td>
  645.                 <td><xsl:value-of select="collegeName"/></td>
  646.                 <td><xsl:value-of select="branch"/></td>
  647.                 <td><xsl:value-of select="year"/></td>
  648.                 <td><xsl:value-of select="email"/></td>
  649.             </tr>
  650.             </xsl:otherwise>
  651.         </xsl:choose>
  652.         </xsl:for-each>
  653.     </table>
  654.     <h2> Selected Student is highlighted</h2>
  655.     </body>
  656.     </html>
  657. </xsl:template>
  658. </xsl:stylesheet>
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668. /*************************Output*************************/
  669.  
  670.  
  671.  
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711. 5. a) Write a Perl program to display various Server Information like Server Name, Server Software, Server protocol, CGI Revision etc.
  712.    Note:
  713.     1. Save the program /var/www/cgi-bin/ directory.
  714. 2.Set the cgi file permission before run the program  (Change path in terminal  :
  715. cd  var/www/cgi-bin/ then :chmod 777 filename.cgi)
  716. /************************* Program5a.cgi *************************/
  717. #! /usr/bin/perl
  718. use CGI':standard';
  719. print "content-type:text/html\n\n";
  720. print "<html><head><title>Server Info<</title></head><body>";
  721. print "SERVER INFORMATION <br/><br/>";
  722. print "Server Name : $ENV{'SERVER_NAME'} <br/><br/>";
  723. print "Server Protocol : $ENV{'SERVER_PROTOCOL'} <br/><br/>";
  724. print "Server Software : $ENV{'SERVER_SOFTWARE'} <br/><br/>";
  725. print "CGI Version : $ENV{'GATEWAY_INTERFACE'} <br/><br/>";
  726. print "</body></html>";
  727. exit(0);
  728. /*************************Output*************************/
  729.  
  730.  
  731.  
  732.  
  733.  
  734.  
  735.  
  736.  
  737.  
  738.  
  739.  
  740.  
  741.  
  742.  
  743.  
  744.  
  745.  
  746.  
  747.  
  748.  
  749.  
  750.  
  751.  
  752.  
  753.  
  754. 5. b) Write a Perl program to accept UNIX command from a HTML form and to display the output of the command executed.
  755. /************************* Program5b.html*************************/
  756. <?xml version="1.0" encoding="UTF-8"?
  757. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  758. "http://www/w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  759. <html xmlns="http://www.w3.org/1999/xhtml">
  760. <body>
  761. <form action="http://localhost/cgi-bin/Program5b.cgi" method="post">
  762. <h3> Enter the Unix Command! </h3>
  763. <input type="text" name="cmd">
  764. <input type="submit" value="Execute">
  765. </form>
  766. </body>
  767. </html>
  768.  
  769. /*************************Program5b.cgi*************************/
  770. #! /usr/bin/perl
  771. use CGI':standard';
  772. print "Content-type:text/html\n\n";
  773. $cmd1=param('cmd');
  774. system($cmd1);
  775. exit(0);
  776.  
  777. /*************************Output*************************/
  778. :
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796. 6. a) Write a Perl program to accept the User Name and display a greeting message randomly chosen from a list of 4 greeting messages.
  797. /*************************Program6a.html*************************/
  798. <html>    
  799. <head><title> name </title></head>
  800. <body bgcolor="aabbcc">
  801. <h3> Enter name and receive the greetings </h3>
  802. <form action="/cgi-bin/Program6a.pl" method="get">
  803.     Name:<input type="text"  name="name"><br/><br/>
  804.     <input type="submit"  value="Submit">
  805.     <input type="reset"  value="Reset">
  806.     </form>      
  807. </body>                  
  808. </html>
  809. /*************************Program6a.pl*************************/
  810. #! /usr/bin/perl
  811. use CGI':standard';
  812. print "content-type:text/html","\n\n";
  813. $input=param(name);
  814. print "<html><body bgcolor=aabbcc><h3>Hi,$input</h3>";
  815. my @msgs=("Welcome to Web Programming","Welcome to Computer science","Thank you for visiting web page","Hello");
  816. print "<h3>The message received is: ";
  817. print $msgs[int rand scalar @msgs];
  818. print "</h3>   </body>   </html>";
  819. /*************************Output*************************/
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837. 6. b) Write a Perl program to keep track of the number of visitors visiting the web page and to display this count of visitors, with proper headings.
  838.  
  839. please Change permissions going to System->Administration->SElinux management->Password “fedora” Change disabled to enforcing
  840. /************************* Program6b.    *************************/
  841.  
  842. #! /usr/bin/perl
  843. print "Content-type:text/html\n\n";
  844. $count_file="/var/www/cgi-bin/count.txt";
  845. if(open(FILE,'<'.$count_file))
  846. {
  847.     $no_accesses=<FILE>;
  848.     close(FILE);
  849.     if(open(FILE,'>'.$count_file))
  850.     {
  851.         $no_accesses++;
  852.         print FILE $no_accesses;
  853.         close(FILE);
  854.         print "no of visitors:",$no_accesses;
  855.     }
  856.     else
  857.     {
  858.         print "[cant write to data file]";
  859.     }
  860. }
  861. else
  862. {
  863.     print "[sorry]";
  864. }
  865. exit(0);
  866.  
  867. *************************Output*************************/
  868.  
  869.  
  870.  
  871.  
  872.  
  873.  
  874.  
  875.  
  876.  
  877.  
  878. 7. Write a Perl Program to display a digital clock which displays the current time of the server.
  879.  
  880. /*************************Program7.pl*************************/
  881.  
  882. #!/usr/bin/perl
  883. $delay = 1;
  884.  ($seconds,$minutes,$hour) = localtime (time);
  885. print "Refresh: ", $delay, "\n";
  886. print "Content-type: text/plain", "\n\n";
  887. print "Digital clock:\t";
  888. print "$hour:$minutes:$seconds";      exit(0);
  889.  
  890.  
  891.  
  892. /*************************Output*************************/
  893.  
  894.  
  895.  
  896.  
  897.  
  898.  
  899.  
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920. 8. Write a Perl Program to insert name and age information entered by the user into a table created using MySQL and to display the current contents of this table.
  921.  
  922. Creating database and  table in MYSQL:
  923. Go to  terminal and type:
  924. #mysql
  925. mysql>create database DB_name;         // To create Database
  926. mysql>use DB_name;             //To use databse
  927. mysql>create table TB_name(name varchar(20),age int(2)); //To create
  928.                                    table  in the above Database.
  929. mysql>select * from TB_name;
  930. /************************* Program8.html*************************/
  931. <?xml version="1.0" encoding="UTF-8"?
  932. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  933. "http://www/w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  934. <html xmlns="http://www.w3.org/1999/xhtml">
  935. <body>
  936. <form action="http://localhost/cgi-bin/Program8.pl" method="post">
  937. <table>
  938. <tr>
  939. <td>Enter your name </td> <td><input type="text" name="name"></td>
  940. </tr>
  941. <td>Enter your age </td> <td><input type="text" name="age"></td>
  942. </tr>
  943. <tr>
  944. <td>Click here to send </td> <td><input type="submit" value="Send"></td>
  945. </tr>
  946. </table>
  947. </form>
  948. </body>
  949. </html>
  950. /************************* Program8.pl*************************/
  951. #! /usr/bin/perl
  952. print "Content-type: text/html\n\n";
  953. print "<HTML><TITLE>Result of the insert operation </TITLE>";
  954. use CGI ':standard';
  955. use DBI;
  956. $dbh=DBI->connect("DBI:mysql:test","root","");
  957. $name=param("name");
  958. $age=param("age");
  959. $qh=$dbh->prepare("insert into stud values('$name','$age')");
  960. $qh->execute();
  961. $qh=$dbh->prepare("select * from stud");
  962. $qh->execute();
  963. print "<table border size=1><tr><th>Name</th><th>Age</th></tr>";
  964. while ( ($name,$age)=$qh->fetchrow())
  965. {
  966.        print "<tr><td>$name</td><td>$age</td></tr>";
  967. }
  968. print "</table>";
  969. $qh->finish();
  970. $dbh->disconnect();
  971. print"</HTML>";
  972.  
  973. /*************************Output*************************/
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006. 9. Write a PHP program to store current date-time in a COOKIE and display the Last visited on data-time on the web page upon reopening of the same page.
  1007. /*************************Program9.php*************************/
  1008. <?php
  1009. $inTwoMonths = 60*60*24*60+time();
  1010. setcookie('lastVisit',date("h:i:s A - m/d/y"), $inTwoMonths);
  1011. if(isset($_COOKIE['lastVisit']))
  1012.     $visit=$_COOKIE['lastVisit'];
  1013. else
  1014.     echo "You've got some expired cookies!";
  1015. echo "Your last visit was - ". $visit;
  1016. ?>
  1017. /*************************Output*************************/
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048. 10. Write a PHP program to store page views count in SESSION, to increment the count on each refresh, and to show the count on web page.
  1049. /*************************Program10.php*************************/
  1050. <?php
  1051. session_start();
  1052. if(isset($_SESSION['views']))
  1053.     $_SESSION['views']=$_SESSION['views']+1;
  1054. else
  1055.     $_SESSION['views']=1;
  1056. echo "Page views = ".$_SESSION['views'];
  1057. ?>
  1058. /*************************Output*************************/
  1059.  
  1060.  
  1061.  
  1062.  
  1063.  
  1064.  
  1065.  
  1066.  
  1067.  
  1068.  
  1069.  
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.  
  1088.  
  1089.  
  1090.  
  1091. 11. Create a XHTML form with the Name, Address Line 1, Address Line 2, and E-mail text fields. On submitting, store the values in MYSQL table. Retrieve and display the data based on Name.
  1092. /*************************Program11.html*************************/
  1093. <?xml version="1.0" encoding="UTF-8"?>
  1094. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML1 1.1//EN"
  1095. "http://www.w3.org/TR/xhtml1/DTD/xhtml1.dtdi">
  1096. <html xmlns="http://www.w3.org/1999/xhtml">
  1097.     <head>
  1098.     <title>Create of User Information</title>
  1099.     </head>
  1100.     <body>
  1101.     <form action="http://localhost/P11a.php" method="post">
  1102.     <pre> <center>
  1103.     <h1> ENTER THE USER DETAILS </h1>
  1104.     <table>
  1105.     <tr>
  1106.         <th>ENTER THE NAME</th>
  1107.         <td><input type="text" name="name1"/></td>
  1108.     </tr>
  1109.     <tr>
  1110.         <th>ENTER THE ADDRESS LINE 1</th>
  1111.         <td><input type="text" name="addline1"/></td>
  1112.     </tr>
  1113.     <tr>
  1114.         <th>ENTER THE ADDRESS LINE 2</th>
  1115.         <td><input type="text" name="addline2"/></td>
  1116.     </tr>
  1117.     <tr>
  1118.         <th>ENTER THE E-MAIL ADDRESS</th>
  1119.         <td><input type="text" name="email1"/></td>
  1120.     </tr>
  1121.     <tr>
  1122.         <td><input type="submit" value="submit"/>
  1123.         <td><input type="reset" value="reset"/>
  1124.     </tr>
  1125.     </table> </centre> </pre>
  1126.     </form>
  1127.     <form action="http://localhost/P11b.php" method="post">
  1128.     <pre>
  1129.     <center>
  1130.         <h1>TO VIEW THE USER DETAILS</h1><br/>
  1131.     <table>
  1132.     <tr>
  1133.         <th>ENTER THE NAME : </th>
  1134.         <td><input type="text" name="name1"/></td>
  1135.     </tr>
  1136.     <tr>
  1137.         <td><input type="submit" value="submit"/></td>
  1138.         <td><input type="reset" value="reset"/></td>
  1139.     </tr>
  1140.     </table> </center> </pre> </form>
  1141. </body>
  1142. </html>
  1143. /*************************P11a.php*************************/
  1144. <html>              
  1145. <body>
  1146. <?php
  1147.     $con = mysql_connect("localhost","root","");
  1148.     if (!$con)
  1149.     {
  1150.         die('Could not connect: ' . mysql_error());
  1151.     }
  1152.     mysql_select_db("userinfo");
  1153.     $sql="INSERT INTO user (name, addr1, addr2, email)
  1154.     VALUES ('$_POST[name1]','$_POST[addline1]','$_POST[addline2]','$_POST[email1]')";
  1155.     if (!mysql_query($sql,$con))
  1156.     {
  1157.         die('Error: ' . mysql_error());
  1158.     }
  1159.     echo "Database has been Updated";
  1160.     mysql_close($con)
  1161. ?>
  1162. </body>              
  1163. </html>
  1164. /*************************P11b.php*************************/
  1165. <html>
  1166.     <head>
  1167.         <title>User information searching</title>
  1168.     </head>
  1169.     <body>
  1170. <?php
  1171. mysql_connect("localhost","root","") or die(mysql_error());
  1172. mysql_select_db("userinfo") or die(mysql_error());
  1173. $name1=$_POST['name1'];
  1174. $res=mysql_query("select * from user where name like '$name1%'") or die(mysql_error());
  1175. ?>
  1176. <table border="2">
  1177.     <tr>    <th>Name</th>
  1178.         <th>Address Line 1</th>
  1179.         <th>Address Line 2</th>
  1180.         <th>E-Mail Address</th>
  1181.     </tr>
  1182. <?php
  1183. while($array=mysql_fetch_row($res))
  1184. {
  1185. echo "<tr> <td>$array[0]</td>
  1186.          <td>$array[1]</td>
  1187.          <td>$array[2]</td>
  1188.          <td>$array[3]</td>
  1189.       </tr>";
  1190. }
  1191. ?>
  1192. </table> </body>
  1193. </html>
  1194. /*************************Output*************************/
  1195.  
  1196.  
  1197.  
  1198.  
  1199.  
  1200.  
  1201.  
  1202.  
  1203.  
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219. s
  1220.  
  1221. 12. Build a Rails Application to accept book information viz. Accession number, title, authors, edition and publisher from a web page and store the information in a database and to search for a book with the title specified by the user and to display the search results with proper headings.
  1222.  
  1223.  
  1224. IN windows only:
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230. Following will open :
  1231.  
  1232.  
  1233. Select following :
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239. Following will open :
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246. START typing the following in rails prompt :
  1247.  
  1248.  
  1249. rails -d mysql lab12
  1250.  
  1251. it will create MVC structure
  1252.  
  1253. cd lab12
  1254.  
  1255. mysql -u root
  1256.  
  1257. create database lab12_development;
  1258. create database lab12_test;
  1259. create database lab12_production;
  1260.  
  1261. use lab12_development;
  1262.  
  1263. create table books(id int not null auto_increment,
  1264.                    accession_num varchar(100) not null,
  1265.                    authors varchar(100) not null,
  1266.              title varchar(100) not null,
  1267.              edition varchar(100) not null,
  1268.              publisher varchar(100) not null,
  1269.              primary key(id));
  1270.  
  1271. mysql> exit;
  1272.  
  1273.  
  1274.  
  1275. type the following in cmd prompt:
  1276.  
  1277. ruby script/generate scaffold Book accession_num:string authors:string title:string edition:string publisher:string
  1278.  
  1279. wait for some time …
  1280. ~~~~~~~~~~~~~~~~~~~~~
  1281.  
  1282. START SEREVER :
  1283. ruby script/server
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290. In browser type :
  1291.  
  1292. http://localhost:3000
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316. Type table name in url (paste the below url in browser):
  1317.  
  1318. http://localhost:3000/books
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.  
  1328. For NEW BOOK ENTRY : (click on New book Link in the previous page)
  1329.  
  1330. The new page appears as shown below.
  1331.  
  1332. Enter the details and click create
  1333.  
  1334. The following will display
  1335.  
  1336.  
  1337.  
  1338.  
  1339.  
  1340.  
  1341. Click on Back link:
  1342.  
  1343.  
  1344.  
  1345.  
  1346.  
  1347. For Searching a book based on name entered by the user:
  1348.  
  1349. IF everything is ok again go to the same command prompt and stop the server by using  ctrl+c:
  1350.  
  1351.  
  1352. Create a controller called Home:
  1353.  
  1354. In command prompt type: ruby script/generate controller home
  1355.  
  1356. (it will create a file named home_controller.rb in controllers subdirectory of
  1357.  
  1358.  the application directory(rails_app/lab12/app/controllers/home_controller.rb).
  1359.  
  1360. As well as it will also create folder named home within views directory of
  1361.  
  1362. application directory (rails_app/lab12/app/views/home/)
  1363.  
  1364. )
  1365.  
  1366.  
  1367. open the home_controller.rb file using Notepad or wordpad or any other editors
  1368.  
  1369. Add the following code within home_controller.rb file
  1370.  
  1371.  
  1372.  
  1373. def search
  1374. end
  1375.  
  1376. def search_res
  1377. @name=params[:search]
  1378. @search_res=Book.find(:all, :conditions=>["title=?",@name])
  1379. end
  1380.  
  1381.  
  1382. finally the home_controller.rb file should look like this:
  1383.  
  1384. class HomeController < ApplicationController
  1385. def search
  1386. end
  1387. def search_res
  1388. @name=params[:search]
  1389. @search_res=Book.find(:all, :conditions=>["title=?",@name])
  1390. end
  1391. end
  1392.  
  1393. ==============================================================================
  1394.  
  1395. Go to: rails_app/lab12/app/views/home. Folder
  1396.  
  1397. Create two files within the above folder as follows:
  1398.  
  1399. 1.Search.html.erb or Search.rhtml
  1400.  
  1401. 2.search_res.html.erb or search_res.rhtml
  1402.  
  1403. (Notice the extension of these files <filename>.html.erb)
  1404.  
  1405. Open the Search.html.erb or Search.rhtml using notepad or any other editor:
  1406.  
  1407. Paste the following code within the file:
  1408.  
  1409.  
  1410. <?xml version="1.0" encoding='utf-8'?>
  1411. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1.dtd">
  1412. <html xmlns="http://www.w3.org/1999/xhtml">
  1413. <head>
  1414. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  1415. <title>Untitled Document</title>
  1416. </head>
  1417. <body>
  1418. <% form_tag :action => 'search_res'  do %>
  1419. <h2>Search for books</h2>
  1420. <table>
  1421. <tr>
  1422. <td>Book Name:</td>
  1423. <td><input type="text" name="search" size="30" /></td>
  1424. </tr>
  1425. </tr>
  1426. </table>
  1427. <input type="submit" value="Search" />
  1428. <input type="reset" value="Clear" />
  1429. </p>
  1430. <% end  %>
  1431. <a href="http://localhost:3000/books">back</a>
  1432. </body>
  1433. </html>
  1434.  
  1435. Save the Search.html.erb or Search.rhtml file.
  1436.  
  1437. ===========================================================================
  1438.  
  1439. Open the Search_res.html.erb or Search_res.rhtml using notepad or any other editor:
  1440.  
  1441. Paste the following code within the file:
  1442.  
  1443.  
  1444. <?xml version="1.0" encoding='utf-8'?>
  1445. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1.dtd">
  1446. <html xmlns="http://www.w3.org/1999/xhtml">
  1447. <head>
  1448. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  1449. <title>Untitled Document</title>
  1450. </head>
  1451. <body>
  1452. <h2>Book search Result </h2>
  1453. <table border= "1">
  1454. <% if @search_res.blank? %>
  1455. <p>There are no books currently by the given name .</p>
  1456. <% else %>
  1457. <tr><td>Accession No</td><td>Book Title</td><td>Authors</td><td>Edition</td><td>publisher</td></tr>
  1458. <% @search_res.each do |book1|
  1459. @bookasn=book1.accession_num
  1460. @booktitle=book1.title
  1461. @bookauthor=book1.authors
  1462. @bookedition=book1.edition
  1463. @bookpublisher=book1.publisher
  1464. %>
  1465.  <tr> <td><%= @bookasn %></td> <td><%= @booktitle %></td> <td><%= @bookauthor%></td> <td><%= @bookedition%></td> <td><%= @bookpublisher%></td></tr>
  1466.  <% end %>
  1467.  <% end %>
  1468.  </table>
  1469.  <p />
  1470.  <a href="http://localhost:3000/home/search">Back</a>
  1471. </body>
  1472. </html>
  1473.  
  1474.  Save the Search_res.html.erb or Search_res.rhtml file.
  1475.  
  1476.  
  1477.  
  1478.  
  1479. Finally open the index.html.erb file: (rails_apps/lab12/app/views/books/index.html.erb)
  1480.  
  1481.  
  1482. Add the following code at the last line of the index.html.erb file:
  1483.  
  1484. <a href="http://localhost:3000/home/search" style="color:red;text-transform:uppercase;">search book</a>
  1485.  
  1486. It will create a link to search.
  1487.  
  1488. -------------------------------------------------------------------------------
  1489.                         ----------------------
  1490.  
  1491.  
  1492. START SEREVER : (In command prompt)
  1493. ruby script/server
  1494.  
  1495.  
  1496.  
  1497. URL :  (In browser)
  1498.  
  1499. http://localhost:3000/books (you can see the link in red color SEARCH BOOK)
  1500.  
  1501.  
  1502.  
  1503. Click on on the SEARCH BOOK link the following will display:
  1504.  
  1505.  
  1506.  
  1507. Type computer graphics(title of book which is all ready inserted) and click search link:
  1508.  
  1509.  
  1510.  
  1511. It will display the following result page:
  1512.  
  1513.  
  1514.  
  1515.  
  1516. Now click back link in the page:
  1517.  
  1518. Type noname(title of the book which is not in the database)in the edit box and click search.
  1519.  
  1520.  
  1521.  
  1522. The following will display:
  1523.  
  1524.  
  1525.  
  1526.  
  1527.                                     THE END
  1528. ===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement