1.a(cgi)#!/usr/bin/perlprint”content-type: text/html”,”nn”;print”<html>”,”n”;print”<head><title>ABOUT THE SERVER</head></t...
Evening"; } print "Welcome User !!!n",$greeting."n";$qstr=$ENV{"QUERY_STRING"}; ($field,$cmd)=split(/=/,$qstr); $webmaster...
$querytxt="insert into ravitab1 values($name,$age,$addr)";$query=$db->prepare($querytxt);$query->execute;$query->finish;$d...
8(php)<?$accid=$_GET[txtaccid];$title=$_GET[txttitle];$authors=$_GET[txtauthors];$edition=$_GET[txtedition];$pub=$_GET[txt...
$query="SELECT * FROM books where title=$title";$result=mysql_query($query);$num=mysql_numrows($result);mysql_close();$i=0...
{response.setContentType("text/html");PrintWriter out=response.getWriter();//String co=request.getParameter("cn");out.prin...
<form action="http://localhost:8080/servlet/pro2b" method="GET"><h1> welcome </h1><select name="cn"><option value="indigo"...
out.println("Cookies Stored!!!");int i;for(i=0;i<cookies_list.length;i++)out.println(cookies_list[i].getName() + ":" + coo...
out.println("request method is "+request.getMethod());out.println("uri is "+request.getRequestURI());out.println("protocol...
{PrintWriter out=res.getWriter();String username=req.getParameter("username");String address=req.getParameter("address");o...
Upcoming SlideShare
Loading in...5
×

Ip lab

1,430

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,430
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Ip lab

  1. 1. 1.a(cgi)#!/usr/bin/perlprint”content-type: text/html”,”nn”;print”<html>”,”n”;print”<head><title>ABOUT THE SERVER</head></title>”,”n”;print”<body><h1>ABOUT THIS SERVER</h1>”,”n”;print”<hr><pre>”;print”Server Name:”,$ENV{”SERVER_NAME”},”<br>”,”n”;print”Running on Port:”,$ENV{”SERVER_PORT”},”<br>”,”n”;print”Server Software:”,$ENV{”SERVER_SOFTWARE”},”<br>”,”n”;print”Server Protocol:”,$ENV{”SERVER_PROTOCOL”},”<br>”,”n”;print”CGI Revision:”,$ENV{”GATEWAY_INTERFACE”},”<br>”,”n”;print”</body></html>”,”n”;exit(0);1.b(Cgi)#!/usr/bin/perluse strict;use CGI:standard;print"content-type: text/html","nn";my$v1=param(unixcom);print"command: $v1","n";print"Result:n";my$res=system("$v1");if($res!=0){print"INVALID COMMAND KINDLY ENTER A VALID CMD!!!n";}1b(html)<html><head><title>enter the unix command</title></head><body><hr><form action="/ cgi-bin/1bprg.cgi"method="get"><h3>enter the unix command</h3><INPUT type= "text" name="unixcom"><br><br><INPUT type="submit" value="submit"><INPUT type="reset" value="reset"></form></body></html>2.a(cgi)#! /usr/bin/perl print "content-type: text/htmlnn";$qstr=$ENV{"QUERY_STRING"}; ($field,$cmd)=split(/=/,$qstr); $cmd=~ s/+/ /g;print "Hello ",$cmd; print "nnWelcome to CSE Lab, Dept of CSE,UVCEnn"; print"nnHave a nice day!!!";2.b(cgi)#! /usr/bin/perl print "content-type : text/htmlnn"; $filename="counter.txt";if(open(FILE1,"<",$filename)) { $counter=<FILE1>; } else { $counter=0; }close(FILE1); $counter++; print "Total number of page hits : ",$counter."n";if( open(FILE1,">",$filename) ) { print FILE1 $counter; } else { print "Filedoes not exist..."; } close(FILE1);3(cgi)#! /usr/bin/perl print "content-type : text/htmlnn"; ($seconds, $minutes,$hour) = localtime (time); if ( ($hour >= 23) || ($hour <= 6) ){ $greeting = "Wow, you are up late"; } elsif ( ($hour > 6) && ($hour <12) ) { $greeting = "Good Morning"; } elsif ( ($hour >= 12) && ($hour <=18) ) { $greeting = "Good Afternoon"; } else { $greeting = "Good
  2. 2. Evening"; } print "Welcome User !!!n",$greeting."n";$qstr=$ENV{"QUERY_STRING"}; ($field,$cmd)=split(/=/,$qstr); $webmaster=$cmd;#$webmaster="asd"; open(FILE1, "/usr/bin/w -h -s $webmaster |"); if (<FILE1>=~ /$webmaster/) { $in_out = "The webmaster is currently loggedin!!!n"; } else { $in_out = "The webmaster is not currently loggedin!!!n"; } print <FILE1>; close(FILE1); print "n".$in_out."n";3(html)<html><body><form action ="/cgi-bin/h.pl" method="GET">enter the webmasters name:<input type ="text" name="t1" size=20><input type ="submit" value ="submit"></form></body></html>4(cgi)#!/usr/bin/perlprint "content-type:text/html nn";print "<html> <head> <meta http-equiv=refresh content=1 www.goole.com> </head></html>";print "current time is ";($seconds, $minutes, $hour) = localtime(time);print "$hour:$minutes:$seconds";if($hour<12){$var=AM;}else{$hour=12-$hour;$var=PM;}print "nncurrent time is :";print "$hour:$minutes:$seconds:$var";5(cgi)#!/opt/lampp/bin/perlprint "content-type:text/html nn";use DBI;use CGI :standard;$db=DBI->connect("DBI:mysql:rajeev1","root","");$query=$db->prepare("select * from student");$query->execute;while(@row=$query->fetchrow){print "$row[0] $row[1] $row[2] <br>";}$query->finish;$db->disconnect;6(cgi)#! /opt/lampp/bin/perluse DBI;use CGI :standard;$db=DBI->connect("DBI:mysql:ravidb1","root","");$name=param("txtname");$age=param("txtage");$addr=param("txtaddr");
  3. 3. $querytxt="insert into ravitab1 values($name,$age,$addr)";$query=$db->prepare($querytxt);$query->execute;$query->finish;$db->disconnect;print "content-type:text/html nn";print "<br><b>The record was successfully inserted...";6(html)<html> <body> <form action="/cgi-bin/r6.pl" method="get"> name <inputtype="text" name="txtname" size=10> <br> age: <input type="text" name="txtage"size=2> <br> addr <input type="text" name="txtaddr" size=15> <br> <inputtype="submit" value="submit"> </form> </body> </html>7(PHP)<html><body><table border=1> <tr> <td><b>NAME</td> <td><b>AGE</td> <td><b>ADDRESS</td> </tr><?$username="root";$password="";$database="ravidb1";mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select database");$query="SELECT * FROM ravitb1";$result=mysql_query($query);$num=mysql_numrows($result);mysql_close();$i=0;while ($i < $num){echo "<tr>";$name=mysql_result($result,$i,"name");$age=mysql_result($result,$i,"age");$addr=mysql_result($result,$i,"addr");echo "<td>";echo $name;echo "</td>";echo "<td>";echo $age;echo "</td>";echo "<td>";echo $addr;echo "</td>";echo "</tr>";$i++;}?></table>
  4. 4. 8(php)<?$accid=$_GET[txtaccid];$title=$_GET[txttitle];$authors=$_GET[txtauthors];$edition=$_GET[txtedition];$pub=$_GET[txtpub];$username="root";$password="";$database="ravidb1";mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select database");$query="insert into books values ($accid,$title,$authors,$edition,$pub)";$result=mysql_query($query);mysql_close();?><b>The record was inserted successfully...</b>8(html)<html><body><b> Welcome to the Books database.</b> <br><b> To enter a record, fill in the details and click submit...</b><br><br><form action="r8.php" method="get"><b>Enter the books accession Id ==> </b><input type="text" name="txtaccid"><br><br><b>Enter the books title ==> </b><input type="text" name="txttitle"><br><br><b>Enter the books authors ==> </b><input type="text" name="txtauthors"><br><br><b>Enter the books edition ==> </b><input type="text" name="txtedition"><br><br><b>Enter the books publication ==> </b><input type="text" name="txtpub"><br><br><input type="submit" value="Insert"><input type="reset" value="Reset"></form>9(PHP)<html><body><table border=1><tr> <td><b>Accession Number</td> <td><b>Title</td> <td><b>Authors</td><td><b>Edition</td><td><b>Publication</td> </tr><?$username="root";$password="";$database="ravidb1";$title=$_GET[txttitle];mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select database");
  5. 5. $query="SELECT * FROM books where title=$title";$result=mysql_query($query);$num=mysql_numrows($result);mysql_close();$i=0;while ($i < $num){echo "<tr>";$accid=mysql_result($result,$i,"accno");$title=mysql_result($result,$i,"title");$authors=mysql_result($result,$i,"authors");$edition=mysql_result($result,$i,"edition");$pub=mysql_result($result,$i,"publication");echo "<td>";echo $accid;echo "</td>";echo "<td>";echo $title;echo "</td>";echo "<td>";echo $authors;echo "</td>";echo "<td>";echo $edition;echo "</td>";echo "<td>";echo $pub;echo "</td>";echo "</tr>";$i++;}?></table></body></html>9(html)<html><body><b> Welcome to the Books database.</b> <br><b> To search for a book, fill in its title and click search...</b><br><br><form action="r9.php" method="get"><b>Enter the books Title ==> </b><input type="text" name="txttitle"><br><br><input type="submit" value="Search"><input type="reset" value="Reset"></form>10.a(jsp)import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class pro22a extends HttpServlet{public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
  6. 6. {response.setContentType("text/html");PrintWriter out=response.getWriter();//String co=request.getParameter("cn");out.println("<html>");out.println("<head>");out.println("<title>hello world</title>");out.println("</head>");out.println("<body>");out.println("<h1>hello</h1>"+request.getParameter("cn"));out.println("request method is "+request.getMethod());out.println("uri is "+request.getRequestURI());out.println("protocol is "+request.getProtocol());out.println("remote addr is"+request.getRemoteAddr());out.println("</body>");out.println("</html>");}}10.a(html)<html><body><form action="http://localhost:8080/servlet/pro22a" method="GET"><h1> welcome </h1>enter username:<input name="cn" type="text"><input type="submit" value="submit"></form></body></html>10.b(jsp)import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class pro2b extends HttpServlet{public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException{response.setContentType("text/html");PrintWriter out=response.getWriter();String co=request.getParameter("cn");out.println("<html>");out.println("<head>");out.println("<title>hello world</title>");out.println("</head>");out.println("<body bgcolor="+co+">");out.println("<h1>hello</h1>");out.println("request method is "+request.getMethod());out.println("uri is "+request.getRequestURI());out.println("protocol is "+request.getProtocol());out.println("remote addr is"+request.getRemoteAddr());out.println("</body>");out.println("</html>");}}10.b(html)<html<body>
  7. 7. <form action="http://localhost:8080/servlet/pro2b" method="GET"><h1> welcome </h1><select name="cn"><option value="indigo">indigo</option><option value="green">green</option><option value="blue" selected="selected">blue</option></select><input type="submit" value="submit"></form></body></html>11(jsp)import java.io.*;import javax.servlet.*;import java.util.*;import javax.servlet.http.*;public class prog11 extends HttpServlet{public void doGet(HttpServletRequest req, HttpServletResponse res) throwsIOException{res.setContentType("text/html");PrintWriter out=res.getWriter();String str=new String();Calendar cl=Calendar.getInstance();int hr=cl.get(Calendar.HOUR_OF_DAY);if(hr>=0 && hr<12){out.println("Good Morning.....");}if(hr>=12 && hr<16){out.println("Good Afternoon...");}if(hr>=16 && hr<20){out.println("Good Evening...");}if(hr>=20){out.println("GO to Sleep.....");}}}12(jsp)import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class newcookies extends HttpServlet{public void doGet(HttpServletRequest req, HttpServletResponse res) throwsIOException, ServletException{PrintWriter out=res.getWriter();Cookie[] cookies_list = req.getCookies();String name=req.getParameter("txtname");String val=req.getParameter("txtval");res.setContentType("text/html");out.println("<html>");if(name==null){if(cookies_list!=null){
  8. 8. out.println("Cookies Stored!!!");int i;for(i=0;i<cookies_list.length;i++)out.println(cookies_list[i].getName() + ":" + cookies_list[i].getValue() +"<br>");}out.println("<form action=http://localhost:8080/servlet/newcookiesmethod=get>");out.println("Enter the name ... <input name=txtname>");out.println("Enter the value ... <input name=txtval>");out.println("<input type=submit value=submit>");out.println("</form> </html>");}else if(name!=null){Cookie cookName=new Cookie(name,val);res.addCookie(cookName);out.println("Cookies submitted successfully!!!");}}}13(jsp)import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;public class prog13 extends HttpServlet{public void doGet(HttpServletRequest req, HttpServletResponse res) throwsIOException{res.setContentType("text/html");PrintWriter out=res.getWriter();HttpSession hs=req.getSession(true);out.println("Session ID:"+hs.getId());Date d1=new Date(hs.getCreationTime());out.println("<br>Creation Time:"+d1);Date d2=new Date(hs.getLastAccessedTime());out.println("<br>Last Access Time:"+d2);}}14(jsp)import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class pro14 extends HttpServlet{public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException{response.setContentType("text/html");PrintWriter out=response.getWriter();out.println("<html>");out.println("<head>");out.println("<title>hello world</title>");out.println("</head>");out.println("<body>");out.println("<h1>hello</h1>");
  9. 9. out.println("request method is "+request.getMethod());out.println("uri is "+request.getRequestURI());out.println("protocol is "+request.getProtocol());out.println("remote addr is"+request.getRemoteAddr());out.println("</body>");out.println("</html>");}}15(jsp)/* 15. Program to accept username and address and display them in a webpage by passing parameters. */import java.lang.*;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class prg15 extends HttpServlet{public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException{PrintWriter out=res.getWriter();out.println("<html>");out.println("<head><title>Program 15 </title></head>");out.println("<body>");out.println("<h1>User Information</h1>");out.println("<br><hr><br>");out.println("<form method=post action=/servlet/prg15");out.println("Dear User.<br>");out.println("Please Enter the following Information.<br><br>");out.println("UserName: <input type=text name=usernamevalue=""><br><br>");out.println("Address: <input type=text name=addressvalue=""><br><br>");out.println("<input type=submit value=Submit><input type=resetvalue=Clear>");out.println("</form>");out.println("</body></html>");}public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException
  10. 10. {PrintWriter out=res.getWriter();String username=req.getParameter("username");String address=req.getParameter("address");out.println("<html>");out.println("<head><title>Program 15 </title></head>");out.println("<body>");out.println("<h1>User Information</h1>");out.println("<br><hr><br>");out.println("Dear User.<br>");out.println("Your Information.<br><br>");out.println("UserName: "+username+"<br>");out.println("Address :"+address+"<br>");out.println("<br><center><ahref=/servlet/prg15>Back</a></center>");out.println("</body>");out.println("</html>");}}

×