Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1a
- <html>
- <head>
- <title>Fibonacci</title>
- </head>
- <body>
- <script type = text/javascript>
- function fibo(n)
- {
- var res;
- if(n==0)
- {
- res = 0;
- }
- else if(n==1)
- {
- res = 1;
- }
- else
- {
- res = fibo(n-1)+fibo(n-2);
- }
- return res;
- }
- function PrintFibo(num)
- {
- var i;
- document.write("<h2><b/><i/>The Fibonacci Series for "+a+"</h2>\n");
- for(i=0;i<=num;i++)
- {
- document.write(fibo(i) + "<br />");
- }
- }
- var a = prompt("Enter a number");
- PrintFibo(a);
- </script>
- </body>
- </html>
- 1b
- <html>
- <head>
- <title>Squares</title>
- </head>
- <body>
- <script type = "text/javascript">
- var msg = "The Number and it's squares are \n";
- var n = prompt("Enter a number");
- var i;
- for(i=1;i<=n;i++)
- {
- msg = msg+i+" - "+i*i+"\n";
- }
- alert(msg);
- </script>
- </body>
- </html>
- 2a
- <html>
- <head>
- <title>USN Validation</title>
- </head>
- <body bgcolor="lightblue">
- <script type="text/javascript">
- function func(USN)
- {
- var pattern1=/^[1-4][A-Z]{2}[0-9]{2}[A-Z]{2}[0-9]{3}$/
- if(!USN.value.match(pattern1)||USN.value.length==0)
- {
- alert("Invalid USN")
- return false
- }
- else
- alert("USN ("+USN.value+") is Valid")
- }
- </script>
- <form action="">
- <h3> Enter Your USN Number: </h3>
- <input type="text" name="USN">
- <br />
- <br />
- <input type="submit" value="submit" onclick="func(USN)"/>
- <input type = "reset" value="reset"/>
- </form>
- </body>
- </html>
- 2b
- <html>
- <head>
- <title>USN and Semester Validation</title>
- </head>
- <body bg color = "lightblue">
- <script type="text/javascript">
- function disp(usn,sem)
- {
- var pattern1=/^[1-4][A-Z]{2}[0-9]{2}[A-Z]{2}[0-9]{3}$/
- if(!usn.value.match(pattern1)||usn.value.length==0)
- {
- alert("Invalid USN!\nEnter a valid USN")
- return false;
- }
- else
- alert("USN valid!");
- var pattern2=/^[1-8]$/
- if(!sem.value.match(pattern2)||sem.value.length==0)
- {
- alert("Invalid Semester!\nEnter a valid Semester");
- return false;
- }
- else
- alert("Semester valid!");
- }
- </script>
- <form action="">
- <pre>
- Enter the Usn
- <input type="text" name="usn" /> <br/>
- Enter the semester
- <input type="text" name="sem" /> <br/>
- <input type="submit" value="submit" onclick="disp(usn,sem)" /> <input type="reset" value="reset" />
- </pre>
- </form>
- </body>
- </html>
- 3a
- <html>
- <head>
- <title>Program to display Stacked Paragraphs</title>
- <style type="text/css">
- .layer1Style
- {
- border:solid thick black;
- padding:1em;
- width:500px;
- background-color:pink;
- position:absolute;
- top:100px; left:200px;
- }
- .layer2Style
- {
- border:solid thick black;
- padding:1em;
- width:500px;
- background-color:yellow;
- position:absolute;
- top:120px; left:220px;
- }
- .layer3Style
- {
- border:solid thick black;
- padding:1em;
- width:500px;
- background-color:cyan;
- position:absolute;
- top:140px;
- left:240px;
- }
- </style>
- <!--<link rel="stylesheet" type="text/css" href="Program3a.css"/>-->
- <script type="text/javascript">
- var topLayer="layer3";
- function stack(toTop)
- {
- var oldTop=document.getElementById(topLayer).style;
- var newTop=document.getElementById(toTop).style;
- oldTop.zIndex="0";
- newTop.zIndex="10";
- topLayer=document.getElementById(toTop).id;
- }
- </script>
- <body style="background-color:orange">
- <h3 style="text-align:center"> Program to demonstrate the usage of stacking of Paragraphs</h3>
- <div class="layer1Style" id="layer1" onmouseover="stack('layer1')">
- Welcome to JIT. This college offers courses like computer science and engineering. Info science,Electrical and Electronics.
- </div>
- <div class="layer2Style" id="layer2" onmouseover="stack('layer2')">
- The College also offers courses like MTech - Computer science and Information Science and Master of Business Administration.
- </div>
- <div class="layer3Style" id="layer3" onmouseover="stack('layer3')">
- The college has an excellent infrastructure, beautiful ambience, separate library and admin blocks, A huge playground and a hostel facilities.
- </div>
- </body>
- </html>
- 3b
- <html>
- <head>
- <title>Program to display Stacked Paragraphs</title>
- <script type="text/javascript">
- var stack1="stack1";
- function toTop(curStack)
- {
- var oldStack=document.getElementById(stack1).style;
- oldStack.zIndex="0";
- var newStack=document.getElementById(curStack).style;
- newStack.zIndex="10";
- stack1=curStack;
- }
- </script>
- <style type="text/css">
- .para1
- {
- border:solid thick black;
- padding:1em;
- width:500px;
- background-color:pink;
- position:absolute;
- top:100px; left:200px;
- }
- .para2
- {
- border:solid thick black;
- padding:1em;
- width:500px;
- background-color:yellow;
- position:absolute;
- top:120px; left:220px;
- }
- .para3
- {
- border:solid thick black;
- padding:1em;
- width:500px;
- background-color:cyan;
- position:absolute;
- top:140px;
- left:240px;
- }
- </style>
- <body style="background-color:orange">
- <h3 style="text-align:center"> Program to demonstrate the usage of stacking of Paragraphs</h3>
- <p class="para1" id="stack1" onmouseover="toTop('stack1')" onmouseout="toTop('stack3')">
- Welcome to JIT. This college offers courses like computer science and engineering. Info science,Electrical and Electronics.
- </p>
- <p class="para2" id="stack2" onmouseover="toTop('stack2')" onmouseout="toTop('stack3')">
- The College also offers courses like MTech - Computer science and Information Science and Master of Business Administration.
- </p>
- <p class="para3" id="stack3" onmouseover="toTop('stack3')" onmouseout="toTop('stack3')">
- The college has an excellent infrastructure, beautiful ambience, separate library and admin blocks, A huge playground and a hostel facilities.
- </p>
- </body>
- </html>
- 4a.xml
- <?xml version = "1.0"?>
- <?xml-stylesheet type="text/css" href="4a.css"?>
- <VTU>
- <student>
- STUDENT INFO
- <USN>1JT15CS001</USN>
- <name>Arun</name>
- <college>JIT</college>
- <branch>CSE</branch>
- <YOJ>2015</YOJ>
- <email>arun@gmail.com</email>
- </student>
- <student>
- <USN>1JT15CS002</USN>
- <name>Gopal</name>
- <college>JIT</college>
- <branch>CSE</branch>
- <YOJ>2015</YOJ>
- <email>gopal@gmail.com</email>
- </student>
- <student>
- <USN>1JT15CS003</USN>
- <name>Sanjay</name>
- <college>JIT</college>
- <branch>CSE</branch>
- <YOJ>2015</YOJ>
- <email>san@gmail.com</email>
- </student>
- </VTU>
- 4a.css
- USN
- {
- display:block;
- color:blue;
- font-style:italic;
- }
- college
- {
- display:block;
- color:green;
- font-style:italic;
- }
- branch
- {
- display:block;
- color:red;
- font-style:italic;
- }
- email
- {
- display:block;
- color:blue;
- font-style:italic;
- }
- 4b.xml
- <?xml version = "1.0" encoding="ISO-8889-1"?>
- <?xml-stylesheet type="text/xsl" href="4b.xsl"?>
- <VTU>
- <student>
- <name>Arun</name>
- <usn>1JT15CS001</usn>
- <college>JIT</college>
- <branch>CSE</branch>
- <year>2015</year>
- <email>arun@gmail.com</email>
- </student>
- <student>
- <name>Gopal</name>
- <usn>1JT15CS002</usn>
- <college>JIT</college>
- <branch>CSE</branch>
- <year>2015</year>
- <email>gopal@gmail.com</email>
- </student>
- <student>
- <name>Sanjay</name>
- <usn>1JT15CS003</usn>
- <college>JIT</college>
- <branch>CSE</branch>
- <year>2015</year>
- <email>san@gmail.com</email>
- </student>
- </VTU>
- 4b.xsl
- <?xml version = "1.0" encoding="ISO-8889-1"?>
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:template match="/">
- <html>
- <body>
- <h2>VTU Student Information</h2>
- <table border="1">
- <tr bgcolor="#99cd32">
- <th>name</th>
- <th>usn</th>
- <th>collegeName</th>
- <th>branch</th>
- <th>year</th>
- <th>email</th>
- </tr>
- <xsl:for-each select="VTU/student">
- <xsl:choose>
- <xsl:when test="name='Gopal'">
- <tr bgcolor="#ff00ff">
- <td><xsl:value-of select="name"/></td>
- <td><xsl:value-of select="usn"/></td>
- <td><xsl:value-of select="college"/></td>
- <td><xsl:value-of select="branch"/></td>
- <td><xsl:value-of select="year"/></td>
- <td><xsl:value-of select="email"/></td>
- </tr>
- </xsl:when>
- <xsl:otherwise>
- <tr>
- <td><xsl:value-of select="name"/></td>
- <td><xsl:value-of select="usn"/></td>
- <td><xsl:value-of select="college"/></td>
- <td><xsl:value-of select="branch"/></td>
- <td><xsl:value-of select="year"/></td>
- <td><xsl:value-of select="email"/></td>
- </tr>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- </table>
- <h2>Selected student is highlighted</h2>
- </body>
- </html>
- </xsl:template>
- </xsl:stylesheet>
- 5a.pl
- #! /usr/bin/perl
- use CGI ':standard';
- print header;
- print start_html("Lab 5a");
- print "SERVER INFORMATION <br/><br/>";
- print "Server Name = $ENV{'SERVER_NAME'} <br/><br/>";
- print "Server Software = $ENV{'SERVER_SOFTWARE'}<br/><br/>";
- print "Server Protocol = $ENV{'SERVER_PROTOCOL'}<br/><br/>";
- print "CGI Revision = $ENV{'GATEWAY_INTERFACE'}<br/><br/>";
- print end_html;
- 5b.html
- <html>
- <head>
- <title>Lab 5b</title>
- </head>
- <body>
- <form action ="http://localhost/cgi-bin/5b.pl" method="POST">
- <h3>Enter the Unix command!</h3>
- <input type = "text" name = "cmd"/>
- <input type ="submit" value = "Execute"/>
- </form>
- </body>
- </html>
- 5b.pl
- #! /usr/bin/perl
- use CGI':standard';
- print header;
- print start_html("Lab 5b");
- $c=param('cmd');
- system($c);
- print end_html;
- 6a.html
- <html>
- <head>
- <title>Lab 6a</title>
- </head>
- <body>
- <form action = "http://localhost/cgi-bin/6.pl">
- <pre>
- Enter Name:
- <input type="text" name="usrname"/>
- <input type = "submit" value = "Submit!"/>
- </pre>
- </form>
- </body>
- </html>
- 6a.pl
- #! /usr/bin/perl
- use CGI':standard';
- print header;
- print start_html("Lab 6a");
- $input = param('name');
- print h2"HI $input<br/><br/>";
- my @msgs=("Welcome to Web Programming","Welcome to Computer science","Thank you for visiting web page","Hello");
- print "The message received is :";
- print $msgs[int rand scalar @msgs];
- print end_html;
- 6b.pl
- #! /usr/bin/perl
- use CGI':standard';
- print header;
- print start_html("Lab 6b");
- open(FILE,'<count.txt');
- $a = <FILE>;
- $a++;
- close(FILE);
- open(FILE,'>count.txt');
- print FILE "$a";
- close(FILE);
- print h1("Number of visiters are $a");
- print end_html;
- 7.pl
- #! /usr/bin/perl
- use CGI':standard';
- ($s,$m,$h) = localtime(time);
- $delay = 1;
- print "Refresh: ", $delay, "\n";
- print header;
- print start_html("Lab 7");
- print "Time = $h:$m:$s";
- print end_html;
- 8.html
- <html xmlns = "http://www.w3.org/1999/xhtml">
- <form action="http://localhost/cgi-bin/8.pl" method ="post">
- <pre>
- Name:<input type="text" name="name"><br>
- Age: <input type="text" name="age"><br>
- <input type="submit" value="Submit" />
- </pre>
- </form>
- </html>
- 8.pl
- #! /usr/bin/perl
- use CGI':standard';
- use DBI;
- print header;
- print start_html("8");
- $n = param('usrname');
- $a = param('usrage');
- $db = DBI -> connect("DBI:mysql:user","root","deepak");
- $st = $db -> prepare("insert into usrinfo values('$n','$a')");
- $st -> execute();
- $st = $db -> prepare("select * from usrinfo");
- $st -> execute();
- print "<table border = 1>
- <tr>
- <th> Name </th>
- <th> Age </th>
- </tr>";
- while(($name,$age) = $st->fetchrow())
- {
- print "<tr>
- <td> $name </td>
- <td> $age </td>
- </tr>";
- }
- print "</table>";
- $st -> finish();
- $db -> disconnect();
- print end_html;
- 9.php
- <?php
- $inTwoMonths = 60*60*24*60+time();
- setcookie('lastVisit',date("h:i:s A - m/d/y"), $inTwoMonths);
- if(isset($_COOKIE['lastVisit']))
- $visit=$_COOKIE['lastVisit'];
- else
- echo "You've got some expired cookies!";
- echo "Your last visit was - ". $visit;
- ?>
- 10.php
- <?php
- session_start();
- if(isset($_SESSION['views']))
- $_SESSION['views']=$_SESSION['views']+1;
- else
- $_SESSION['views']=1;
- echo "Page views = ".$_SESSION['views'];
- ?>
- 11.html
- <html>
- <head>
- <title>HTML, PHP and MySQL</title>
- </head>
- <body>
- <h3> Enter information</h3>
- <form action="http://localhost/akshay11a.php" method="POST">
- <pre>
- Name
- <input type="text" name="name" />
- Address 1
- <input type="text" name="address1" />
- Address 2
- <input type="text" name="address2" />
- E-mail
- <input type="text" name="email" />
- <input type="submit" value="Submit" /> <input type="reset" value="Clear" />
- </pre>
- </form>
- <form action="http://localhost/akshay11b.php" method="POST">
- <pre>
- Enter the name
- <input type="text" name="name" />
- <input type="submit" value="Submit" />
- </pre>
- </form>
- </body>
- </html>
- 11a.php
- <?php
- $name=htmlspecialchars($_POST['name']);
- $address1=htmlspecialchars($_POST['address1']);
- $address2=htmlspecialchars($_POST['address2']);
- $email=htmlspecialchars($_POST['email']);
- $connection = mysql_connect("localhost", "root", "jit123") or die(mysql_error());
- mysql_select_db("akshay") or die(mysql_error());
- $sql = "insert into user(name, addr1, addr2, email) values ( '$name', '$address1', '$address2', '$email');";
- mysql_query($sql) or die(mysql_error);
- echo "Values inserted";
- ?>
- 11b.php
- <html>
- <body>
- <?php
- $name=htmlspecialchars($_POST['name']);
- $connection = mysql_connect("localhost", "root", "jit123") or die(mysql_error());
- mysql_select_db("akshay") or die(mysql_error());
- $sql = "select * from user where name like '$name%';";
- $result = mysql_query($sql) or die(mysql_error);
- ?>
- <table border="1">
- <tr><th>Name</th><th>Address 1</th><th>Address 2</th><th>E-Mail</th></tr>
- <?php
- while($cols=mysql_fetch_row($result))
- {
- echo "<tr>
- <td>$cols[0]</td>
- <td>$cols[1]</td>
- <td>$cols[2]</td>
- <td>$cols[3]</td>
- </tr>";
- }
- ?>
- </table>
- </body>
- </html>
- 12
- ## Program 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.
- ***
- ### Procedure for execution:
- * Open a terminal and run `mkdir rails_app && cd $_`
- * Create a new app called books using the command `rails new books -d mysql`
- * Run the command `cd books/config` and open the database.yml file to set mysql username and password by running the command `nano database.yml`. The *username* and *password* are required to be filled at 3 sections in the file.
- * The following is a sample snippet from the database.yml file-
- adapter: mysql2
- encoding: utf8
- reconnect: false
- database: books_development
- pool: 5
- username: root
- password: pass
- socket: /var/run/mysqld/mysqld.sock
- * Save the file by `ctrl+x` and then `y`.
- * Now run `cd ..` and make sure that you are present in the `rails_app/books` directory.
- * Run the command `rake db:create`
- * Next, run `rails generate controller books index`
- * Next, run `rails generate model book access_no:integer title:string author:string edition:integer
- publisher:string`
- * Run `rake db:migrate`
- * Now, `cd app/views/books` and edit the file `nano index.html.erb` -
- * Also, edit the file `nano search.html.erb`
- * Now, `cd ../../controllers` and edit the file `nano books_controller.rb`
- * Next, run `cd ../../config` and edit `nano routes.rb` file.
- * Finally, run `cd ..` and start the rails server by running the command `rails s`
- * Open a browser and in the address bar type `localhost:3000` to check if the rails server is running. If yes, add to the URL, `localhost:3000/books/index`.
- * Enter the input & on successfully inserting data, search for the same from the browser. The output is displayed in a table on the browser.
- ###Explaination
- * The rails new command has created a Rails application in a new directory called books
- * The -d options in the rails new command allows us to specify which DBMS to use. The default is sqlite. However we use mysql
- * The database.yml file has all the cofiguration information which allows our application to connect, create and modify the database
- * You run rake db:create once and only once, and you run it first. Then you run rake db:migrate every time you add/change a migration
- * The rails generate controller command created a lot of files and directories. We are interested in two of them for now :-
- * app/controllers/books_controller.rb
- * app/views/books/index.html.erb
- * Inside Rails application, the controller file is placed inside app/controllers directory
- * ####The Controller
- * User types a URL, lets say http://localhost:3000/pages/home. If the Rails server is running, the request first reaches the Rails router.
- * ![Alt text](./l6_block_dia_vc.png)
- * The Router checks the config/routes.rb file to see if there is an entry matching the URL requested. In our case there is a route entry - get "pages/home". In short, the route matches incoming URL `/pages/home` to home action in Pages controller. So the request is forwarded to the Pages controller, home action.
- * ![Alt text](./l5_pages.png)
- * In our program the BooksController is a class. Intially there is an empty method index inside the class. The method is also called index action in the Books controller.
- class BooksController < ApplicationController
- def index
- end
- * This action serves the url /books/index when accessed. Even though the index action is an empty method, it fetches the file /apps/views/books/index.html.erb and displays it on the browser.
- * ####The Model
- * Rails interact with the database through models. In our program we have a model called Book. This ensures that the our model is independent of the DBMS
- * When you create a model, the name is singular and the name starts with capital letter. Book, instead of Books
- * In our model we have the following attributes
- * access_no:integer
- * title:string
- * author:string
- * edition:integer
- * publisher:string
- * The `rails generate model` command also creates a migration file present under db/migrate
- * The migration file is like schema which defines the database table structure
- * rake db:migrate pushes the database changes from the migration file to the actual database
- * If you end up doing a mistake you can always undo the creation of a model using
- rails destroy model Book
- * If you want to delete the database from the DBMS once the model has been migrated use
- rake db:rollback
- * ####Ruby Tags
- * RoR has the following 2 tags :
- * <% %> : The output of this tag will NOT be displayed on the browser
- * <%= %> : The output will be displayed on the browser
- ###Code:
- * **index.html.erb**
- ```erb
- <h1>Books</h1><br>
- <h3 style="text-align: center;">Add a book</h3><br>
- <%= form_tag("/books/add", :method=>"post") do %>
- <form action="/books/add" method="post"> <br>
- Access No:<%= text_field_tag(:b_access_no) %>
- //create input tags of given type and id
- <input type="text" id=":b_access_no"><br>
- <br>Title: <%= text_field_tag(:b_title) %>
- <input type="text" id=":b_title"><br>
- <br>Author: <%= text_field_tag(:b_author) %>
- <input type="text" id=":b_author"><br>
- <br>Edition: <%= text_field_tag(:b_edition) %>
- <input type="text" id=":b_edition"><br>
- <br>Publisher: <%= text_field_tag(:b_publisher) %>
- <input type="text" id=":b_publisher"><br>
- <br><br>
- <%= submit_tag("Add Book") %>
- <input type="submit" value="Add Book"><br>
- <% end %>
- <br>
- <h3 style="text-align: center;">Search for a book</h3><br>
- <%= form_tag("/books/search", :method=>"post") do %>
- <form action="/books/search" method="post"><br>
- Title: <%= text_field_tag(:bs_title) %>
- <input type="text" id=":bs_title"><br>
- <br><br>
- <%= submit_tag("Search") %>
- <input type="submit" value="Search"><br>
- <% end %>
- <br>
- ```
- * **search.html.erb**
- ```erb
- <h1>Search Result</h1><br>
- <table border=1><br>
- <% @t=Book.find_by_title(params[:bs_title]) %>
- //RoR creates a find_by_attribute method for our model. In our case we are asked to search by title hence we are using the find_by_title function. This function takes a string as parameter. Here we are using the the value in :bs_title that was passed on using post method when the button was pressed. This function returns an array. Arrays in ruby begin with the '@' symbol
- <br>
- <tr><br>
- <th>Access No.</th><br>
- <th>Title</th><br>
- <th>Author</th><br>
- <th>Edition</th><br>
- <th>Publisher</th><br>
- </tr><br>
- <tr><br>
- //Elements of an array are accessed by the "." operator followed by the attribute name.
- //In our case we are accessing the access_no that was returned to the array t.
- <td> <%= @t.access_no %> </td>
- <td> <%= @t.title %> </td>
- <td> <%= @t.author %> </td>
- <td> <%= @t.edition %> </td>
- <td> <%= @t.publisher %> </td>
- </tr><br>
- </table><br>
- <br><br><br>
- <a href="/books/index">Back</a>
- <br>
- ```
- * **books_controller.rb**
- ```ruby
- class BooksController < ApplicationController
- //auto-generated code
- def index
- //auto-generated code
- end
- //auto-generated code<br>
- def add
- //create a new action called add which performs the below action
- Book.create(:access_no=>params[:b_access_no],:title=>params[:b_title],:author=>params[:b_author],:edition=> params[:b_edition],:publisher=> params[:b_publisher])
- //the create method is used to add a vlaue to the DB. The values to be added are fetched from the post method using the param function
- redirect_to :action => 'index'
- //once the add button is clicked this specifes which page is to be displayed.Here the index page is redisplayed
- end
- def search
- //defines the search action. Just displayes search.html.erb on browser
- end
- end
- ```
- * **routes.rb**
- ```ruby
- Books::Application.routes.draw do
- //auto generated code
- match "books/index" => "books#index", :as => :index
- //use the action defined under index when request for /books/index is recieved<br>
- match "books/add" => "books#add", :via => :post
- //use action defined under add when request for books/add is recieved via post method<br>
- match "books/search" => "books#search", :via => :post
- //use action defined under search when request for books/search is recieved via post method<br>
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement