ITWD

123
Ex No:1 MATRIX TRANSPOSE USING HTML AND JAVASCRIPT AIM: To perform matrix transpose using HTML and JavaScript by dynamically getting the input depending on the order of the matrix specified by the user. ALGORITHM: 1. Design the user interface in HTML 2. Get the number of rows and columns from the user 3. The rows and columns are send to the Asp page 4. The ASP page generates the required number of text boxes dynamically based on the number of rows and columns. 5. The transformation of the matrix is performed 6. The result is displayed in matrix form. CODING: Matrix.html <html> <head></head> <body> <form action="aa.asp"> <marquee> <fontcolor="#779955"size="10"> <h3><b>MATRIX TRANSFORMATION<b></h3> </font> </marquee> <center> <table style="WIDTH: 501px; HEIGHT: 228px"> <tbody> <tr> <td><font color=Red><b>ENTER THE NUMBER OF ROWS<b></font> </td> <td><input type="text" name="t" />

Transcript of ITWD

Page 1: ITWD

Ex No:1 MATRIX TRANSPOSE USING HTML AND JAVASCRIPT

AIM:

To perform matrix transpose using HTML and JavaScript by dynamically getting the input depending on the order of the matrix specified by the user.

ALGORITHM:

1. Design the user interface in HTML2. Get the number of rows and columns from the user3. The rows and columns are send to the Asp page4. The ASP page generates the required number of text boxes dynamically based on the

number of rows and columns.5. The transformation of the matrix is performed6. The result is displayed in matrix form.

CODING:

Matrix.html

<html><head></head><body><form action="aa.asp"> <marquee> <fontcolor="#779955"size="10"> <h3><b>MATRIX TRANSFORMATION<b></h3> </font> </marquee> <center> <table style="WIDTH: 501px; HEIGHT: 228px"> <tbody> <tr> <td><font color=Red><b>ENTER THE NUMBER OF ROWS<b></font> </td> <td><input type="text" name="t" /> </td> </tr> <tr> <td><font color=Red><b>ENTER THE NUMBER OF COLUMNS<b></font> </td> <td><input type="text" name="t1" /> </td> </tr> <tr> <td colsapan="2"><center> <input type="submit" value="submit" /> </center></td>

Page 2: ITWD

</tr> </tbody> </table> </center></form></body></html>

aa.asp

<html><%dim l dim idim jdim l1Dim myDynArray() l= request("t")l1=request("t1")i=0j=0%><body><marquee><font color="#779955" size="10"> ENTER THE ELEMENTS</font></marquee><form action=a5.asp> <table style="WIDTH: 313px; HEIGHT: 251px" bordercolor="snow" align="center" bgcolor="779955"> <center> <tr> <% k=0 %> <% for i=0 to l-1 step 1 for j=0 to l1-1 step 1 %> <td><input type =text name= <%=k %>> <% k=k+1next%> <tr> <% next %> <tr> <td><input type=submit value =submit> <input type=hidden name=t3 value =<%= l%>> <input type=hidden name=t4 value =<%= l1%>> </center> </table></form></body>

Page 3: ITWD

</html>

a5.asp

<html><%dim l dim idim jdim l1dim stDim myDynArray() dim array()l= request("t3")l1=request("t4")st=l*l1i=0j=0d=0s=0redim myDynArray(st)redim array(st)for i=0 to st-1 step 1myDynArray(i)=request(i)nextfor j=0 to l1-1 step 1for i=0 to st-1 step larray(d)=myDynArray(i+j)d=d+1nextnext%><body bgcolor="Seashell"><font color="#779955" size="10"> TRANSPOSE OF THE MATRIX IS</font> <table style="WIDTH: 313px; HEIGHT: 251px" bordercolor="snow" align="center" bgcolor="779955"> <center> <tr> <% k=0 %> <% for i=0 to l1-1 step 1 for j=0 to l-1 step 1 %> <td><input type =text name= <%=k %> value= <%=array(k) %>> <% k=k+1next%> <tr> <% next %> <tr>

Page 4: ITWD

<td> </center> </table></body></html>

SAMPLE SCREENSHOTS

matrix.html

aa.asp

Page 5: ITWD

a5.asp

Page 6: ITWD

Ex No:2 USER REGISTRATION PAGE VALIDATION USING VBSCRIPT AND JAVASCRIPT

AIM:

To perform user validation for the inputs given through HTML using VBScript and JavaScript.

ALGORITHM:

1. Design the html form to get the inputs from the user.2. Specify the scripting language as either vbscript or javascript3. Check if the values are entered in the input boxes by retrieving the data using

document.formname.textboxname4. If the data is not entered alert the user with the message that the data is not entered.

Student registration.html

<html><head><title>STUDENT REGISTRATION</title><SCRIPT LANGUAGE="VBSCRIPT" src="val.vbs"></SCRIPT> </head><body><center><h2>STUDENT REGISTRATION FORM</h2></center><form name="form1" method="POST" action="validate.html"><table cellpadding=10 cellspacing=2 border=0><tr><td>First Name:</td><td><input type=text name="n1"></input></td></tr><tr><td>Middle Name:</td><td><input type=text name="n2"></input></td></tr><tr><td>Last Name:</td><td><input type=text name="n3"></input></td></tr><tr><td>Register No.:</td><td><input type=text name="r1"></input></td><tr><td>DOB(dd-mm-yyyy):</td>

Page 7: ITWD

<td><input type=text name="d1"size=2></input><input type=text name="d2"size=2></input><input type=text name="d3"size=2></input></td></tr><tr><td>Gender:</td><td><input type="radio" checked="checked" name="gender" value="Male">Male<input type="radio" checked="checked"name="gender" value="Female">Female</td><tr><td>Are you Physically Handicapped?</td><td><input type="radio" checked="checked" name="ph" value="yes">Yes<input type="radio" checked="checked" name="ph" value="no">No</td><td>Do you belong to SC/ST?</td><td><input type="radio" checked="checked" name="sc" value="yes">Yes<input type="radio" checked="checked" name="sc" value="no">No</td></tr></table><table cellpadding=4 cellspacing=5 border=0><th>Postal Address</th><tr><td>Address:</td><td><input type="text" name="a1" size=40></input></td></tr><tr><td>City:</td><td><input type="text" name="a2"></input></td><td>State:</td><td><input type="text" name="a4"></input></td></tr><tr><td>Country:</td><td><input type="text" name="a5"></input></td><td>Pincode:</td><td><input type="text" name="a3"></input></td></tr><tr><td>Phone number:</td><td><input type="text" name="a6"></input></td></tr><tr>

Page 8: ITWD

<td colspan=2><center><input type="button" name="button1" value="submit"></input><input type="reset" name="button2" value="cancel"></input></center></td></tr></table> </form> </body> </html>

val.vds

sub button1_onclickIf form1.elements(0).value<> "" Thenif NOT (isnumeric(form1.elements(0).value)) ThenIf form1.elements(3).value<> "" Thenif (isnumeric(form1.elements(3).value)) thenIf form1.elements(4).value<> "" Thenif (form1.elements(4).value)< 32 and (form1.elements(4).value) <> 0 thenIf form1.elements(5).value<> "" Thenif (form1.elements(5).value)< 13 and (form1.elements(5).value) <> 0 thenIf form1.elements(6).value<> "" Thenif (form1.elements(6).value)< 1990 and (form1.elements(6).value) > 1984 thenIf form1.a1.value<> "" Thenif form1.a2.value<> "" ThenIf NOT (isnumeric(form1.a2.value)) thenif form1.a3.value<> "" thenIf (isnumeric(form1.a3.value)) Thenif (len(form1.a3.value))=6 thenIf form1.a4.value<> "" ThenIf NOT (isnumeric(form1.a4.value)) thenIf form1.a5.value<> "" ThenIf NOT (isnumeric(form1.a5.value)) thenmsgbox "Validation Successful!!"form1.submitelsealert "Please use alphabets"form1.a5.selectform1.a5.focusend ifelsealert "Please enter your Country"form1.a5.focusend ifelsealert "Please use alphabets"

Page 9: ITWD

form1.a4.selectform1.a4.focusend ifelsealert "Please enter your State"form1.a2.focusend ifelsealert "Please enter a 6 digit Pincode"form1.a3.selectform1.a3.focusend ifelsealert "Please use digits"form1.a3.selectform1.a3.focusend ifelsealert "Please enter Pincode"form1.a3.focusend ifelsealert "Please use alphabets"form1.a2.selectform1.a2.focusend ifelsealert "Please enter your City"form1.a2.focusend ifelsealert "Please enter your Address"form1.a1.focusend ifelsealert "Please enter the year between 1985 and 1989"form1.elements(6).selectform1.elements(6).focusend ifelsealert "Please enter the year of birth"form1.elements(6).focus

Page 10: ITWD

end ifelsealert "Please enter months between 1 and 12"form1.elements(5).selectform1.elements(5).focusend ifelsealert "Please enter the month"form1.elements(5).focusend ifelsealert "Please enter dates from 1 to31 "form1.elements(4).selectform1.elements(4).focusend ifelsealert "Please enter your Birth date"form1.elements(4).focusend ifelsealert "Please use digits 0 to 9 in registration number"form1.elements(3).selectform1.elements(3).focusend ifelsealert "Please enter your Register Number"form1.elements(3).focusend ifelsealert "Please use alphabets"form1.elements(0).selectform1.elements(0).focusend ifelsealert "Please enter your First Name"form1.elements(0).focusend ifend sub

Page 11: ITWD

SAMPLE INPUT AND OUTPUT:

Page 12: ITWD

JavaScript program

Student registration.html

<html><head> <title>STUDENT REGISTRATION</title><SCRIPT LANGUAGE="JavaScript">function validate_form(thisform){with (thisform){var a=0if (n1.value==null||n1.value==""){alert("invalid name"); a=1}if (r1.value==null||r1.value==""){alert("invalid register number");a=1}if (a1.value==null||a1.value==""){alert("invalid address");a=1}if (a2.value==null||a2.value==""){alert("invalid city");a=1}if (a3.value==null||a3.value==""){alert("invalid pincode");a=1}if (a4.value==null||a4.value==""){alert("invalid state");a=1

Page 13: ITWD

}if (a5.value==null||a5.value==""){alert("invalid country");a=1}if (a==1)return false;else{alert("Validation successful!!");return true;}}}</SCRIPT></head><center><h2>STUDENT REGISTRATION</h2></center><body><form name="register" method="POST" action="validate.html" onSubmit="returnvalidate_form(this)"><table cellpadding=10 cellspacing=2 border=0><tr><td>First Name:</font></td><td><input type=text name="n1"></input></td></tr><tr><td>Middle Name:</td><td><input type=text name="n2"></input></td></tr><tr> <td>Last Name:</td><td><input type=text name="n3"></input></td></tr><tr><td>Register No.:</td><td><input type=text name="r1"></input></td></tr><tr><td>DOB(dd-mm-yy):</font></td><td><input type=text name="d1"size=2></input>-<input type=text name="d2"size=2></input>-<input type=text name="d3"size=2></input></td> </tr><tr><td>Gender:</td><td><input type="radio" name="gender" value="Male">Male<input type="radio" name="gender" value="Female">Female</td></tr><tr><td>Are you Physically Handicapped?</td>

Page 14: ITWD

<td><input type="radio" name="ph" value="yes">Yes<input type="radio" name="ph" value="no">No</td><td>Do you belong to SC/ST?</td><td><input type="radio" name="sc" value="yes">Yes<input type="radio" name="sc" value="no">No</td></tr> </table>

<table cellpadding=4 cellspacing=5 border=0><th>Postal Address</th><th colspan=2></th><tr><td>Address:</td><td><input type="text" name="a1" size=40></input></td></tr><tr><td>City:</td><td><input type="text" name="a2"></input></td><td>State:</td><td><input type="text" name="a4"></input></td></tr><tr><td>Country:</td><td><input type="text" name="a5"></input></td><td>Pincode:</td><td><input type="text" name="a3"></input></td></tr><tr><td>Phone number:</td><td><input type="text" name="a6"></input></td></tr><tr><td colspan=2><center><input type="submit" name="submit"value="submit"></input></center></td></tr> </table></form></body></html>

Page 15: ITWD

Sample input and output

Page 16: ITWD

Ex No:3 DATABASE CONNECTION WITH MS ACCESS USING ASP/JSP/PHP

AIM:

To establish database connection using ASP, JSP and PHP

DATABASECONNECTION USING ASP:

ALGORITHM:

1. Design the user interface where the necessary controls are added.2. Save the file as .asp .3. Action to be performed is written in another file and saved as .asp files.4. The files are saved in Programfiles->Inetpub->wwwroot.5. Database connectivity is established using the following code

Set DB = Server.CreateObject ("adodb.Connection")DB.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:\Inetpub\wwwroot\studreg.mdb")

6. Coding is written for operations like Insertion,Deletion,UPdation.7. Program is run and executed using the IIS server –http://localhost/(filename).asp

Header.php

<html><head><title>PHP and MS ACCESS</title></head><body bgcolor="9999ff"><br><font size="+2"><center><b>BANK MANAGEMENT SYSTEM</b></font><BR><BR><br><a href="display.php"> DISPLAY EXISTING ACC. DETAILS </a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="insinput.php"> INSERT NEW ACC. DETAILS</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="mod.php"> MODIFY ACC. DETAILS</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="update.php"> UPDATE BALANCE AMT.</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="delete.php"> DELETE ACC. </a></center>

Index.php

Page 17: ITWD

<?php include("header.php");?></body></html>

Display.php

<?phpinclude("header.php");?><br><br><table align=center width=90% border=1><tr><th>Acc. No.</th><th>Name</th><th>Address</th><th>Phone no.</th><th>Balance</th><th>Acc. Type</th><th>Last trans. date</th><th>Last trans. amount</th><th><?php$conn=odbc_connect("new","" ,"");if($conn){$sql="select * from bank";$row=odbc_exec($conn, $sql);while(odbc_fetch_row($row)){$accno=odbc_result($row,1);$name=odbc_result($row,2);$sex=odbc_result($row,3);$address=odbc_result($row,4);$pno =odbc_result($row,5);$balance =odbc_result($row,6);$ltd =odbc_result($row,7);$lta =odbc_result($row,8);print('<tr><td>'.$accno.'</td><td>'.$name.'</td><td>'.$sex.'</td><td>'.$address.'</td><td>'.$pno.'</td><td>'.$balance.'</td>');if($ltd=='' && $lta==0)echo('<td>-</td><td>-</td></tr>');elseecho('<td>'.$ltd.'</td><td>'.$lta.'</td></tr>');} }odbc_close($conn);?> </table></body></html>

Insinput.php

<?

Page 18: ITWD

include("header.php");?><font size=3><b><pre><FORM ACTION="insert.php" METHOD="post"><BR><br>ACC. NO.:<INPUT TYPE="text" NAME="acc"><BR>NAME: <INPUT TYPE="text" NAME="name"><BR>ADDRESS: <INPUT TYPE="text" NAME="add"><BR>PHONE. NO.: <INPUT TYPE="text" NAME="pno" ><BR>BALANCE: <INPUT TYPE="text" NAME="balance" ><BR>ACC. TYPE: <INPUT TYPE="text" NAME="type"><BR><INPUT TYPE="submit" VALUE="INSERT"></FORM></b></pre></font></body></html>

Insert.php

<?extract($_POST);$conn=odbc_connect("new","" ,"");$sql="insert into bank(accno,name,address,pno,balance,type) values($acc,'$name','$add',$pno,$balance,'$type');";odbc_exec($conn, $sql);odbc_close($conn);header("Location: display.php ");?>

Mod.php

<?include("header.php");?><font size=3><b><br><br><br><br><br><br><center><FORM ACTION="modify.php" METHOD="post"><BR><br>ACC. NO.: <INPUT TYPE="text" NAME="acc"><BR><br><INPUT TYPE="submit" VALUE="GO"></FORM></center></b></font></body></html>

Modify.php

<?include("header.php");?>

Page 19: ITWD

<br><br><br><br><br><font size=3><b><FORM name="inp" ACTION=<?php echo "modifydet.php?acc=$_POST[acc]"; ?> METHOD=post><table align=center width=90% border=1><tr><th>Acc. No.</th><th>Name</th><th>Address</th><th>Phone no.</th><th>Balance</th><th>Acc. Type</th></tr><?phpextract($_POST);$conn=odbc_connect("new","" ,"");if($conn){$sql="select * from bank where accno=$acc";$row=odbc_exec($conn, $sql);while(odbc_fetch_row($row)){$accno=odbc_result($row,1);$name=odbc_result($row,2);$address=odbc_result($row,3);$pno =odbc_result($row,4);$balance =odbc_result($row,5);$type=odbc_result($row,6);print('<tr><td>'.$accno.'</td><td><input name="name" type="text" value='.$name.'></td><td><input name="add" type="text" value='.$address.'></td><td><input name="pno" type="text" value='.$pno.'></td><td><input name="balance" type="text" value='.$balance.'></td><td><input name="type" type="text" value='.$type.'></td></tr>');} } odbc_close($conn);?> </table><btr><br><center><INPUT TYPE="submit" VALUE="MODIFY"></center></form></font></body></html>

Modifydet.php

<?$acc=$_GET[acc];extract($_POST);$conn=odbc_connect("new","" ,"");

Page 20: ITWD

$sql="update bank set name='$name',address='$add',pno=$pno,balance=$balance,type='$type' where accno=$acc;";odbc_exec($conn, $sql);odbc_close($conn);header("Location: display.php ");?>

Update.php

<?include("header.php");?><font size=3><b><BR><br><br><br><pre><FORM ACTION="upd.php" METHOD="post">ACC. NO.: <INPUT TYPE="text" NAME="acc"><BR>WITHDRAWAL AMT. :<INPUT TYPE="text" NAME="amt"><BR><input type="submit" value="Update"></FORM></b></pre></font></body></html>

Upd.php

<?include("header.php");?><br><br><br><font size="+2"><center><?extract($_POST);$date=date('m-d-Y');$conn=odbc_connect("new","" ,"");$sql="select * from bank where accno=$acc";$row=odbc_exec($conn, $sql);$accno=odbc_result($row,1);$bal=odbc_result($row,5);if($bal>=$amt){$bal-=$amt;$sql="update bank set balance=$bal,ltdate='$date',ltmoney=$amt where accno=$acc;";odbc_exec($conn, $sql);echo("Transaction successful!!!!");}else{echo("Your balance is less than the withdrawal amt.!!!!");}

Page 21: ITWD

odbc_close($conn);?></center> </font> </body> </html>

Delete.php

<?include("header.php");?><font size=3><b><br><br><br><br><br><br><center><FORM ACTION="del.php" METHOD="post"><BR><br>ACC. NO.: <INPUT TYPE="text" NAME="acc"><BR><br><INPUT TYPE="submit" VALUE="GO"></FORM></center></b></font></body></html>

Del.php

<?$conn=odbc_connect("new","" ,"");$sql="delete from bank where accno=$_POST[acc]";odbc_exec($conn, $sql);odbc_close($conn);header("Location: display.php ");?>

Page 22: ITWD

SAMPLE INPUT AND OUTPUT:

Page 23: ITWD
Page 24: ITWD
Page 25: ITWD

Ex. No.4 SESSION OBJECT

AIM

To check and allow the user to perform an action within a session period.

ALGORITHM:

1. Start.2. Register the form, if the form is registered before the session expires, the form is

registered and the session variables and the contents are printed.3. If one registers after his session period, then his registration cannot be accepted.4. Finally all the session variables and contents will be deleted when one user leaves the

session.

Lsucc.php

<?php include('../config.php'); echo "<head>"; echo "<title>$title</title>"; echo "<script type=\"text/javascript\">"; echo "function delayloading()"; echo "{"; echo "window.location = \"../index.php\""; echo "}"; echo "</script>"; echo "<link type=text/css rel=stylesheet href=/images/style.css />"; echo "</head>";?><body onLoad="setTimeout('delayloading()', 2000)"><div id=header></div><div id=message>Login Successful!<br><br>Please Wait While We Re-direct You To Our Home Page..</div></body></html>

Process.php

<?php include('../config.php'); echo "<head>"; echo "<title>$title</title>"; echo "<script type=\"text/javascript\">"; echo "function delayloading()"; echo "{"; echo "window.location = \"../index.php\"";

Page 26: ITWD

echo "}"; echo "</script>"; echo "<link type=text/css rel=stylesheet href=/images/style.css />"; echo "</head>";?><body onLoad="setTimeout('delayloading()', 2000)"><div id=header></div><div id=message>Your Registration Was Successful!<br><br>Please Wait While We Re-direct You To Our Home Page..</div></body></html>

Confreg.php

<?php session_start(); include('../config.php'); include('../source.php'); extract($_POST);

$con=mysql_connect($host, $dbuser, $dbpass) or die(mysql_error()); mysql_select_db($dbname, $con) or die(mysql_error());

$phno=$phno1.$phno2.$phno3; $sql="insert into members values('', '$fname', '$lname', '$uname', '$upass', '$email', '$addrs', '$phno', '$ctype');"; mysql_query($sql, $con) or die(mysql_error());

//upon successful insertion, we will set the cookie and re-direct the user to the home page $sql="select * from members where uname='$uname'"; $res=mysql_query($sql); while($newArray=mysql_fetch_array($res)) { $uid=$newArray[slno]; $fname=$newArray[fname]; } $_SESSION[user]=$uname; $_SESSION[fname]=$fname; $_SESSION[uid]=$uid; header("Location: ../del/process.php"); exit(1);?>

Login.php

<?phpsession_start();include('../config.php');

Page 27: ITWD

include('../source.php');

$myusername=$_POST['uname']; $mypassword=$_POST['upass'];

$con=mysql_connect($host, $dbuser, $dbpass) or die(mysql_error());mysql_select_db($dbname, $con) or die(mysql_error());

$sql="select * from members where uname='$myusername' and upass='$mypassword'";$res=mysql_query($sql, $con);

while($newArray=mysql_fetch_array($res)){ $uid=$newArray[slno]; $fname=$newArray[fname]; }$count=mysql_num_rows($res);

if($count==1){ $_SESSION[uid]=$uid; $_SESSION[user]=$myusername; $_SESSION[fname]=$fname; header("Location: ../del/lsucc.php"); exit(1);}else if($count<0){ //Incorrect User name or password... header("location: $url/warn/warn2.php");} ?>

Register.php

<?php session_start(); include('../source.php'); //displaying the head, title and stylesheet infos. headreg();?><center> <form name=pras action=confreg.php method=post><table width=350px><tr> <td colspan=2><center><b>We need your following Details</b></center></td><tr><tr>

Page 28: ITWD

<td width=35%>First Name</td> <td width=65%><center><input type=text name=fname size=27></center></td></tr><tr> <td width=35%>Last Name</td> <td width=65%><center><input type=text name=lname size=27 onfocus="isEmpty(fname, 'Please Fill In Your First Name!')"></center></td></tr><tr> <td width=35%>Username</td> <td width=65%><center><input type=text name=uname size=27 onfocus="isEmpty(lname, 'Please Fill In Your Last Name!')"></center></td></tr><tr> <td width=35%>Password</td> <td width=65%><center><input type=password name=upass size=27 onfocus="isEmpty(uname, 'Please Fill In The UserName Field!')"></center></td></tr><tr> <td width=35%>e-Mail</td> <td width=65%><center><input type=text name=email size=27 onfocus="isEmpty(upass, 'You Need To Enter A Password!')"></center></td></tr><tr> <td width=35%>Shipping Address</td> <td width=65%><center><textarea name=addrs rows=4 onfocus="isEmpty(email, 'We Need Your e-Mail Address For Confirmation!')"></textarea></center></td></tr><tr> <td width=35%>Contact No</td> <td width=65%><center><input type=text name=phno1 size=3 onfocus="isEmpty(addrs, 'Please Fill In Your Shipping Address!')">&nbsp;&nbsp;&nbsp;<input type=text name=phno2 size=3 onfocus="isEmpty(phno1, 'Please Fill In Your Country Code!')">&nbsp;&nbsp;&nbsp;<input type=text name=phno3 size=10 onfocus="isEmpty(phno2, 'Please Fill In Your State Code!')"></center></td></tr><tr> <td width=35%>Credit Card Type</td> <td width=65%> <select name=ctype onfocus="isEmpty(phno3, 'Please Fill In Your Telephone Number!')"> <option value=amexp>American Express Card</option> <option value=visa>Visa Card</option> <option value=mascr>Master Card</option> <option value=disco>Discover Card</option> </select></td></tr><tr> <td colspan=2><input type=submit value="Proceed -->"></td></tr></table></form></center><br><center><h3>Choose Us Because We Have,</h3><img src=../images/satisfaction.png></center>

Page 29: ITWD

Index.php

<?php session_start(); include('config.php'); include('source.php'); //displaying the head, title and stylesheet infos. headpart("Home"); //display the username if logged in if(isset($_SESSION[user])) echo "<br><center>Welcome $_SESSION[fname]!</center><br>";

//displaying the latest product echo "<br>"; echo "<center>"; echo "<table>"; echo "<tr><td class=head><center>Latest Product In Our Store!</center></td></tr>"; echo "<tr><td><center><img name=mac height=300 width=500 src=images/leopard.jpg onmouseover=\"mac.src='images/leoparddesk.jpg'\" onmouseout=\"mac.src='images/leopard.jpg'\"></center></td></tr>"; echo "</table>"; echo "</center>"; echo "<br>";

//display user login/signup box if((isset($_SESSION[user]))!=1) { echo "<br>"; echo "<center>"; echo "<form name=pras action=/login/login.php method=post>"; echo "<table>"; echo "<tr><td colspan=2 class=head><center>Please Login or SignUp To Start Purchasing!</center></td></tr>"; echo "<tr>"; echo "<td><input type=text name=uname value=\"Your Username\" onclick=\"this.value=''\"></td>"; echo "<td><input type=password name=upass value=\"Your Password\" onclick=\"this.value=''\"></td>"; echo "</tr>"; echo "<tr>"; echo "<td><center><input type=submit value=Login></center></td>"; echo "<td><center><input type=button value=SignUp onclick=\"window.location='/login/register.php'\"></center></td>"; echo "</tr>";

Page 30: ITWD

echo "</table>"; echo "</form>"; echo "</center>"; }?></body></html>

Check.php

<?php for($i=1; $i<=5; $i++) { $sel="sel".$i; echo "$_POST[$sel]<br>"; } echo "Hey";?>

Chout.php

<?php session_start(); include('config.php'); include('source.php'); //displaying the head, title and stylesheet infos. headpart("Check Out"); echo "<br><center>"; echo "<form name=pras action=lout.php method=post>"; echo "<table>"; echo "<tr>"; echo "<td colspan=2 class=head>Please Provide The Following Details</td>"; echo "</tr>"; echo "<tr>"; echo "<td>Card Holder's Name</td>"; echo "<td><input type=text name=chn></td>"; echo "</tr>"; echo "<tr>"; echo "<td>16 Digit Card Code</td>"; echo "<td><input type=text name=dcc maxlength=20 value=\"XXXX-XXXX-XXXX-XXXX\" onclick=\"this.value=''\"></td>"; echo "</tr>"; echo "<tr>"; echo "<td>3 Digit Card Number</td>"; echo "<td><input type=password name=dcn size=2 maxlength=3></td>"; echo "</tr>"; echo "<tr>"; echo "<td>Card Expiry Date</td>"; echo "<td><input type=text name=day value=DD size=2 onclick=\"this.value=''\">

Page 31: ITWD

<input type=text name=mon value=MM size=2 onclick=\"this.value=''\"> <input type=text name=yea value=YYYY size=4 onclick=\"this.value=''\"> </td>"; echo "</tr>"; echo "<tr>"; echo "<td colspan=2><input type=submit value=\"Confirm Order\"></td>"; echo "</tr>"; echo "</table>"; echo "</form>"; echo "<br></center>"; ?>

Config.php

<?php $title="Boss Shope!"; $host="localhost"; $dbname="shcart"; $dbuser="root"; $dbpass="";?>

Lout.php

<?php include('config.php'); include('source.php'); session_start(); session_destroy(); unset($_SESSION[uid]); unset($_SESSION[user]); unset($_SESSION[fname]);

//the following lines are to avoided in real implementation $con=connect(); $sql="truncate table cart;"; mysql_query($sql, $con); include('config.php'); echo "<head>"; echo "<title>$title</title>"; echo "<script type=\"text/javascript\">"; echo "function delayloading()"; echo "{"; echo "window.location = \"index.php\""; echo "}"; echo "</script>"; echo "<link type=text/css rel=stylesheet href=/images/style.css />"; echo "</head>";

Page 32: ITWD

?><body onLoad="setTimeout('delayloading()', 5000)"><div id=header></div><div id=message>Your Order Has Been Accepted! You Will Receive The Materials Soon!<br><br>Please Wait While We Log You Out To Our Home Page..</div></body></html>

Recache.php

<?php include('config.php'); include('source.php');

//tot contains total no. items in cart, its used for iterating the deletion part $t=$_GET[t]; $con=connect(); for($i=1; $i<=$t; $i++) { $cname[$i]="del".$i; $cname[$i]=$_POST[$cname[$i]]; if(isset($cname[$i])) { $sql="delete from cart where no=$cname[$i];"; mysql_query($sql, $con); } } header("Location: vcart.php");?>

Source.php

<?php function connect() { include('config.php'); $con=mysql_connect($host, $dbuser, $dbpass) or die(mysql_error()); mysql_select_db($dbname, $con) or die(mysql_error()); return $con; } function headpart($t) { include('config.php'); echo "<head>"; echo "<title>$title - $t</title>"; echo "<script type='text/javascript'>"; echo "function isEmpty(elem, helperMsg)"; echo "{"; echo "if(elem.value.length == 0)";

Page 33: ITWD

echo "{"; echo "alert(helperMsg);"; echo "elem.focus();"; echo "return true;"; echo "}"; echo "return false;"; echo "}"; echo "function enableField('tbname')"; echo "{"; echo "alert(tbname);"; echo " document.shpras.tbname.disabled=false;"; echo "}"; echo "</script>"; echo "<link type=text/css rel=stylesheet href=/images/style.css />"; echo "</head>"; echo "<body>"; echo "<div id=header></div>"; echo "<br>"; //displaying all the categories as menu.. $con=connect(); $sql="select * from categ;"; $re=mysql_query($sql, $con) or die(mysql_error()); $t=mysql_num_rows($re); echo "<center>"; echo "<table width=900px>"; echo "<tr><td colspan=$t class=head>Our Categories</td></tr>"; echo "<tr>"; while($newArray=mysql_fetch_array($re)) echo "<td><a class=menu href=vprod.php?categ=$newArray[slno]>$newArray[cname]</a></td>"; echo "</tr>"; echo "</table>"; echo "<br>"; if(isset($_SESSION[user])) echo "<a href=vcart.php><u>Click Here To View The Items In Your Cart<u></a>"; echo "</center>"; } function headvc() { include('config.php'); echo "<head>"; echo "<title>$title - Cart Items</title>"; echo "<link type=text/css rel=stylesheet href=/images/style.css />"; echo "</head>"; echo "<body>"; echo "<div id=header></div>"; echo "<br>"; //displaying all the categories as menu..

Page 34: ITWD

$con=connect(); $sql="select * from categ;"; $re=mysql_query($sql, $con) or die(mysql_error()); $t=mysql_num_rows($re); echo "<center>"; echo "<table>"; echo "<tr><td colspan=$t class=head>Our Categories - <a href=index.php>Home</a></td></tr>"; echo "<tr>"; while($newArray=mysql_fetch_array($re)) echo "<td><a class=menu href=vprod.php?categ=$newArray[slno]>$newArray[cname]</a></td>"; echo "</tr>"; echo "</table>"; echo "<br>"; echo "</center>"; }

function headreg() { include('config.php'); echo "<head>"; echo "<title>$title</title>"; echo "<script type='text/javascript'>"; echo "function isEmpty(elem, helperMsg)"; echo "{"; echo "if(elem.value.length == 0)"; echo "{"; echo "alert(helperMsg);"; echo "elem.focus();"; echo "return true;"; echo "}"; echo "return false;"; echo "}"; echo "function enableField('tbname')"; echo "{"; echo "alert(tbname);"; echo " document.shpras.tbname.disabled=false;"; echo "}"; echo "</script>"; echo "<link type=text/css rel=stylesheet href=/images/style.css />"; echo "</head>"; echo "<body>"; echo "<div id=header></div>"; echo "<br>"; }?>

Vcart.php

Page 35: ITWD

<?php session_start(); include('config.php'); include('source.php'); //tot contains the total number of products that was listed in the previous page $t=$_GET[t]; $con=connect(); //displaying the head, title and stylesheet infos. headvc(); echo "<br>"; for($i=1; $i<=$t; $i++) { $cname[$i]="sel".$i; $qname[$i]="qua".$i; $cname[$i]=$_POST[$cname[$i]]; $qname[$i]=$_POST[$qname[$i]]; } for($i=1; $i<=$t; $i++) { if(isset($qname[$i])==1) { //echo "$cname[$i] --> $qname[$i] <br>"; $sql1="select * from prod where pno=$cname[$i];"; $res1=mysql_query($sql1, $con); while($newArray=mysql_fetch_array($res1)) { $pname=$newArray[pname]; $pprice=$newArray[pprice]; } $total=$pprice*$qname[$i]; $sql2="insert into cart values ('',$_SESSION[uid], $cname[$i],'$pname', $pprice, $qname[$i], $total)"; mysql_query($sql2, $con); } } //display all the products in the cart $sql="select * from cart;"; $res=mysql_query($sql, $con); echo "<center>"; echo "<form name=pras method=post>"; $t=mysql_num_rows($res); if($t!=0) { echo "<table>"; echo "<tr>"; echo "<td class=head>Product ID</td>"; echo "<td class=head>Product Name</td>"; echo "<td class=head>Price Per Unit</td>";

Page 36: ITWD

echo "<td class=head>Quantity</td>"; echo "<td class=head>Total Price</td>"; echo "<td class=head>Remove</td>"; echo "</tr>"; $i=1; while($newArray=mysql_fetch_array($res)) { $cname="del".$i; echo "<tr>"; echo "<td>$newArray[pno]</td>"; echo "<td>$newArray[pname]</td>"; echo "<td>$newArray[pprice]</td>"; echo "<td>$newArray[qua]</td>"; echo "<td>$newArray[total]</td>"; echo "<td><input type=checkbox name=$cname value=$newArray[no]></td>"; echo "</tr>"; $i++; } $sql="select uid, sum(total) as tot from cart group by uid;"; $res=mysql_query($sql, $con); while($newArray=mysql_fetch_array($res)) { if($newArray[uid]==$_SESSION[uid]) $total=$newArray[tot]; } echo "<tr><td class=head colspan=4>Total Price [USD]</td><td colspan=2><b>$ $total</b></td></tr>"; echo "<tr><td colspan=3><input type=submit value=\"Check Out -->\" onclick=\"pras.action='chout.php'\"></td>"; echo "<td colspan=3><input type=submit value=\"Delete Items\" onclick=\"pras.action='recache.php?t=$t'\"></td></tr>"; echo "</table>"; } else { echo "<br><br><br><br>There Are No Items In Your Cart!"; } echo "<br>"; echo "</form>"; echo "</center>";?>

Vprod.php

<?php session_start(); include('config.php'); include('source.php'); $slno=$_GET[categ];

Page 37: ITWD

$con=connect(); //displaying the head, title and stylesheet infos. headpart("Market"); echo "<br>"; $sql="select * from prod where slno=$slno"; $res=mysql_query($sql, $con); $t=mysql_num_rows($res); if($t==0) noprod(); $i=1; echo "<center>"; $url="vcart.php?t=".$t; echo "<form name=shpras action=$url method=post>"; while($newArray=mysql_fetch_array($res)) { $cname="sel".$i; $qname="qua".$i; echo "<table width=900px>"; echo "<tr><td class=phead width=15%>Product ID: $newArray[pno]</td><td class=phead colspan=3>$newArray[pname]</td></tr>"; $imgurl="/images/".$newArray[pimage1]; echo "<tr><td>Description</td><td colspan=2><p>$newArray[pdesc]</p></td> <td colspan=2><img width=250px src=$imgurl></td></tr>"; if(isset($_SESSION[user])) { echo "<tr><td><input type=checkbox name=$cname value=$newArray[pno] onfocus=\"document.shpras.$qname.disabled=false\"></td> <td>Quantity</td> <td><input type=text name=$qname size=3 disabled></td> <td>Home: $newArray[ppage]</td> </tr>"; echo "<tr><td colspan=4>Cost: $$newArray[pprice] [USD]</td></tr>"; } else { echo "<tr><td colspan=4><center>Home: $newArray[ppage]</center></td></tr>"; echo "<tr><td colspan=4>Cost: $$newArray[pprice] [USD]</td></tr>"; } echo "</table><br><br>"; $i++; } if(isset($_SESSION[user])) echo "<input type=submit value=\"Proceed -->\">"; echo "</form>"; function noprod() { echo "<center>Sorry, Currently We Have No Products In This Category!</center>"; exit(1); }?>

Page 38: ITWD

SCREENSHOTS :

Page 39: ITWD
Page 40: ITWD

EX. No:5 ADROTATOR AND CONTENT ROTATOR

AIM: To implement Ad-rotator and content-rotator using asp.

ALGORITHM: 1. The ASP AdRotator component creates an AdRotator object that displays a different

image each time a user enters or refreshes a page.2. The only difference between ad-rotator and content rotator is that, in content rotator only

content is displayed where as in ad-rotator both images and content are displayed.3. Initially the images and the content to be displayed are collected and the required html code is

written with the exact path, where those pictures are stored.4. The adrotator is given a name to access the page.5. The pictures are separately stored in another file.

CODING:Banners.asp<%url=Request.QueryString("url")If url<>"" then Response.Redirect(url)%><html><body><%set adrotator=Server.CreateObject("MSWC.AdRotator")response.write(adrotator.GetAdvertisement("textfile.txt"))%></br><%set cr=server.createobject("MSWC.ContentRotator")response.write(cr.ChooseContent("text/textads.txt"))%></body></html>

Textfile.txt

REDIRECT banners.asp*w3s.gifhttp://www.yahoo.comVisit yahoo to get all type of services!!!!!!50xmlspy.gifhttp://www.altova.comXML Editor from Altova50

Textads.txt%% #3

Page 41: ITWD

<h2>This is a great day!!</h2>

%% #3<h2>Hi Lakshmi!!!</h2>

%% #4<h3>Your Dreams will come true!!!!!!!

SAMPLE SCREENSHOTS

Screen when refresh is clicked

Page 42: ITWD

Screen when another refresh is clicked.

Page 43: ITWD

Ex No: 6 REQUEST AND RESPONSE OBJECT

AIM:

To implement request and response object in asp.

ALGORITHM:

1. Design the page using html.2. When the user clicks the button, asp file will be opened.3. In asp file, get the values of all elements that are declared in html page using

request.querystring for get method and request.form for post method.4. Then display the value by using response.write.5. Response.redirect is used to move to next page.

CODING:fun.asp<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title></head><body><center><h3><label>WELCOME TO FUN GROUPS</label> </h3><label> SIGN INTO OUR GROUP</label><form id="form1" name="form1" method="post" action="reg.asp"> <input type="submit" name="button" id="button" value="ENTER" /></form></center></body></html>

reg.asp

<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>REGISTRATION</title></head><body><center> <p>ENTER YOUR PROFILE </p></center><form method="get" action="reqstr.asp"> Enter your name: <input name="name" type="text" value="" size="50" /> <br/> Category :<input type="radio" name="category" value="student" /> Student

Page 44: ITWD

<input type="radio" name="category" value="teacher" /> Teacher<input type="radio" name="category" value="organisation" /> Organisation<br/>

Subjects of interest:<input type=checkbox name=subject1 value=GeneticAlgorithm>Genetic Algorithm<br/><input type=checkbox name=subject2 value=DataStructures>Data Structures<br/><input type=checkbox name=subject3 value=ComputerNetworks>Computer Networks<br/><input type=checkbox name=subject4 value=SoftwareEngineering>Software Engineering<br/><br/>Country:<select name=country><option value=India>India<option value=US>US<option value=UK>UK<option value=China>China</select><br/><input type=submit value=submit></form></body></html>

reqstr.asp

<html><body><center><h2>BY USING GET METHOD AND REQUEST QUERY STRING OBJECT</h2><h3><%dim name,category,subject1name=request.queryString("name")category=request.queryString("category")country=request.queryString("country")subject1=request.queryString("subject1")subject2=request.queryString("subject2")subject3=request.queryString("subject3")subject4=request.queryString("subject4")response.write ("Hi " & name &"<p>")response.write ("You are a " & category &"<p>")response.write ("you live in " & country &"<p>")response.write ("Your areas of interest are")response.write (subject1&"<p>")response.write (subject2&"<p>")response.write (subject3&"<p>")response.write (subject4&"<p>")%>

Page 45: ITWD

<form method="get" action="redirect.asp"><input type=submit value=next></form></h4></center></body></html>

redirect.asp<html><body><center><%Response.write("hi")response.redirect("contact.asp")%></center></body></html>

contact.asp

<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>CONTACT INFORMATION</title></head><body><center> <p>SOME OF YOUR PRIVATE DETAILS ARE NEEDED WE ASSURE YOU THAT THIS WILL BE PURELY CONFIDENTIAL!!! </p></center><form method="post" action="reqform.asp"> Enter your contact number: <input name="cn" type="text" value="" size="40" /> <br/> <br/> Enter your email ID: <input name="email" type="text" value="" size="40" /><br/><input type=submit value=submit></form></body></html>

reqform.asp

<html><body><center><h2>BY USING POST METHOD AND REQUEST FORM OBJECT</h2><h3>

Page 46: ITWD

<%cn=request.form("cn")email=request.form("email")response.write ("you are available at " & cn &"<p>")response.write ("Your Email ID ")response.write (email &"<p>")%></h4></center></body></html>

SAMPLE SCREENSHOTS:

fun.asp

reg.asp

Page 47: ITWD

reqstr.asp

contact.asp

Page 48: ITWD

reqform.asp

Page 49: ITWD

Ex No:7 CALLING SQL SERVER STORED PROCEDURE USING ASPAIM:

To call a stored procedure in SQL server using ASP

ALGORITHM:

1. Create a table employee in the master database of SQL SERVER 2000.2. Write a stored procedure emp for the employee table which selects the salary of the

given employee id from the table.3. Write an ASP program calling the stored procedure connecting the database along

with the tables and procedure.4. In the coding specify the stored procedure to be used.5. Create parameter objects for the parameters used in the stored procedure.6. Execute the procedure.7. Display the result in a separate page.

CODING

<%Const adCmdStoredProc = 4Const adInteger = 3Const adParamInput = 1Const adParamOutput = 2Const adExecuteNoRecords = 128' Declare our varsDim con ' Connection objectDim cmd ' Command objectDim rs ' Recordset object Dim param 'Parameter object' Establish connection to database (DB)Set con = Server.CreateObject("ADODB.Connection")con.Open "Provider=SQLOLEDB;Data Source=HEMALATHASATHIY;" _ & "Initial Catalog=master;User Id=sa;Password=sa;" ' Create Command object we'll use to execute the SPSet cmd = Server.CreateObject("ADODB.Command")' Set our Command to use our existing connectioncmd.ActiveConnection = conResponse.Write "<p>Running the stored procedure: " _

& "<strong>emp</strong>.</p>" & vbCrLf' Set the SP's name and tell the Command object' that the name we give is supposed to be a SPcmd.CommandText = "emp"cmd.CommandType = adCmdStoredProcResponse.Write "<p>Passing it two parameters:<br />" & vbCrLf _

& "<strong>@Id</strong> = 1<br />" & vbCrLf _

Page 50: ITWD

& "<strong>@salary</strong> = (an output parameter)<br />" & vbCrLf _& "</p>" & vbCrLf

Set param = cmd.CreateParameter("@Id", adInteger, adParamInput)param.Value = 1cmd.Parameters.Append paramcmd.Parameters.Append cmd.CreateParameter("@salary", adInteger ,adParamOutput)cmd.Execute, ,adExecuteNoRecords Response.Write "<p>It returned the value: salary<strong>"Response.Write cmd.Parameters("@salary").Value' Kill our objectsSet param = NothingSet cmd= Nothing%>

TABLE

STORED PROCEDURE

Page 51: ITWD

SAMPLE INPUT AND OUTPUT:

Page 52: ITWD

Ex No:8 SERVLETS WITH JDBC CONNECTION

AIM:To develop Electricity bill managent system using servlets with jdbc connection.

ALGORITHM:

1. Install j2ee server and set the environment variables2. Create the html files for user interface for viewing user details and bill details and the administrator is able to insert new customer and enable the updation of units consumed by the user per month.3. The java files for the above operations are created which are derived from HTTP servlet class.4. In the classes, methods are defined to get requests from html file and perform response results.5. Connection to jdbc-odbc drives is made and data is queried and results are displayed.6. The server is started using the command j2ee –verbose7. Compile all the java files and create the class files8. Deploy tool is started and all the class files are added.9. After deployment of the class files, open the browser window and open the html files. The server must be running.

login.jsp:

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Login Page</title> </head><body><form name="loginform" method="post" action="http://localhost:8080/Electricity?ACTION=LOGIN" ><h1>Login Page</h1><table><tr><td> User ID : </td><td> <input name="USER_ID" type="text"> </td></tr><tr><td> Password : </td><td> <input name="PASSWORD" type="password"> </td></tr><tr><td> <input type="submit" value="Submit"> </td></tr></table></form></body></html>

paybill.jsp:

Page 53: ITWD

<%@page contentType="text/html"%><%@page pageEncoding="UTF-8"%><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>JSP Page</title></head><body><form name="loginform" method="post" action="http://localhost:8080/Electricity?ACTION=PAY" ><h1>Pay Bill</h1><%String[] detailTitles = {"Customer ID", "Name" , "Address", "Phone", "Start Date", "End Date", "No. of Units", "Charge" };String[] custDetails = (String[]) request.getAttribute( "CUST_DETAILS");%><table><% for ( int i = 0; i < detailTitles.length; i ++ ) { %><tr><td> <%=detailTitles[i]%> </td><td> <%=custDetails[i]%> </td></tr><% } %></table><table><tr><td> <input type="submit" value="Pay"> </td></tr></table> </form> </body> </html>

paymentsuccess.jsp:

<html><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>JSP Page</title> </head><body><form name="loginform" method="post" action="http://localhost:8080/Electricity?ACTION=PAY" ><h1>Payment Successful.</h1><%String[] detailTitles = {"Customer ID", "Name" , "Address", "Phone", "Start Date", "End Date", "No. of Units", "Charge" };String[] custDetails = (String[]) request.getAttribute( "CUST_DETAILS");%>

Page 54: ITWD

<table><% for ( int i = 0; i < detailTitles.length; i ++ ) { %><tr><td> <%=detailTitles[i]%> </td><td> <%=custDetails[i]%> </td></tr><% } %></table></form></body></html>

adminview.jsp:

<%@page contentType="text/html"%><%@page pageEncoding="UTF-8"%><%@page import="java.util.ArrayList"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>JSP Page</title></head><body><h1>View All Customers</h1><form name="loginform" method="post" ><table><th><%String[] detailTitles = {"Customer ID", "Name" , "Address", "Phone", "Start Date", "End Date", "No. of Units", "Charge" };for ( int i = 0; i < detailTitles.length; i ++ ) { %><td> <%=detailTitles[i]%> </td><% }%></th>

<%ArrayList allCustDetails = (ArrayList) request.getAttribute("ALL_CUST_DETAILS");for ( int i = 0 ; i < allCustDetails.size(); i ++ ) {String[] custDetails = (String[]) allCustDetails.get(i);

Page 55: ITWD

String url = "http://localhost:8080/Electricity?ACTION=EDIT&CUST_ID=" + custDetails[0];%><tr><% for ( int j = 0 ; j < detailTitles.length; j ++ ) { %><td> <%= custDetails[j] %> </td><% } %><td> <a href=<%=url%>>Edit</a></tr><%}%></table></form></body></html>

adminupdate.jsp:<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>JSP Page</title></head><body><form name="loginform" method="post" action="http://localhost:8080/Electricity?ACTION=UPDATE" ><h1>Update Customer</h1><%String[] detailTitles = {"Customer ID", "Name" , "Address", "Phone", "Start Date", "End Date", "No. of Units", "Charge" };String[] custDetails = (String[]) request.getAttribute( "CUST_DETAILS");System.out.println ( "Not NULL = " + (custDetails != null) );%><table><% for ( int i = 0; i < detailTitles.length; i ++ ) { %><tr><td> <%=detailTitles[i]%> </td><td> <input name=FIELD_<%=i%> type=text value="<%=custDetails[i]%>" > </td></tr><% } %></table><table>

Page 56: ITWD

<tr><td> <input type="submit" value="Update"> </td></tr></table></form></body></html>

updatesuccess.jsp:

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>JSP Page</title></head><body><h1>Customer details updated successfully.</h1><h1>View All Customers</h1><form name="loginform" method="post" ><table><th><%String[] detailTitles = {"Customer ID", "Name" , "Address", "Phone", "Start Date", "End Date", "No. of Units", "Charge" };for ( int i = 0; i < detailTitles.length; i ++ ) { %><td> <%=detailTitles[i]%> </td><% }%></th>

<%ArrayList allCustDetails = (ArrayList) request.getAttribute("ALL_CUST_DETAILS");for ( int i = 0 ; i < allCustDetails.size(); i ++ ) {String[] custDetails = (String[]) allCustDetails.get(i);String url = "http://localhost:8080/Electricity?ACTION=EDIT&CUST_ID=" + custDetails[0];%><tr><% for ( int j = 0 ; j < detailTitles.length; j ++ ) { %><td> <%= custDetails[j] %> </td><% } %><td> <a href=<%=url%>>Edit</a>

Page 57: ITWD

</tr><%}%></table></form></body></html>

accessdb.java:

package pec.cse.elec;

import java.sql.*;import java.util.*;public class AccessDb {private Connection connection;public AccessDb () {try {Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");connection = DriverManager.getConnection ("jdbc:odbc:Electricity");} catch (SQLException e) {e.printStackTrace();} catch ( Exception e) {e.printStackTrace();}}

public boolean validateUser ( int userID, String password ) {String queryString = "SELECT CUSTID FROM ELECTRICITY WHERE CUSTID=";queryString += userID;queryString += " AND PASSWORD='";queryString += password;queryString += "';";try {Statement statement = connection.createStatement();ResultSet resultSet = statement.executeQuery( queryString );if ( resultSet.next() ) {return true;}

Page 58: ITWD

//String queryString = "SELECT CUSTID FROM ELECTRICITY WHERE ID=? AND PASSWORD=?";//PreparedStatement pStatement = connection.prepareStatement( queryString );//pStatement.setInt( 1 , userID );//pStatement.setString( 2 , password );//pStatement.executeQuery();} catch (SQLException e) {e.printStackTrace();}return false;}public boolean payBill ( int userID ) {String queryString = "UPDATE ELECTRICITY SET NUMUNITS = 0, CHARGE = 0 WHERE CUSTID=";queryString += userID;try {Statement statement = connection.createStatement();int numRecords = statement.executeUpdate( queryString );return ( numRecords > 0 );} catch (SQLException e) {e.printStackTrace();}return false;}public boolean updateCustomer ( int userID , String custName, String custAddress, int custPhone,String fromDate, String toDate, double numUnits, double charges ) {String queryString = "UPDATE ELECTRICITY SET CUSTNAME=?, CUSTADDRESS = ?, CUSTPHONE=?," +"STARTDATE = ?, ENDDATE = ?, NUMUNITS = ?, CHARGE = ? WHERE CUSTID = ?";try {PreparedStatement pStatement = connection.prepareStatement( queryString );pStatement.setString( 1 , custName );pStatement.setString( 2 , custAddress );pStatement.setInt( 3 , custPhone );pStatement.setString( 4 , fromDate );pStatement.setString( 5 , toDate );pStatement.setDouble( 6 , numUnits );pStatement.setDouble( 7 , charges );pStatement.setInt( 8 , userID );int numRecords = pStatement.executeUpdate();

Page 59: ITWD

return ( numRecords > 0 );} catch (SQLException e) {e.printStackTrace();}return false;}public String[] getCustomerDetails ( int userID ) {String queryString = "SELECT * FROM ELECTRICITY WHERE CUSTID=";queryString += userID;try {Statement statement = connection.createStatement();ResultSet resultSet = statement.executeQuery( queryString );ResultSetMetaData rsMetaData = resultSet.getMetaData();String[] resultData = new String[ rsMetaData.getColumnCount() ];while ( resultSet.next()) {for ( int i = 0; i < resultData.length; i ++) {resultData[i] = resultSet.getString(i + 1);}}return resultData;} catch (SQLException e) {e.printStackTrace();}return null;}public ArrayList getAllCustomerDetails ( ) {String queryString = "SELECT * FROM ELECTRICITY";

try {Statement statement = connection.createStatement();ResultSet resultSet = statement.executeQuery( queryString );ResultSetMetaData rsMetaData = resultSet.getMetaData();int columnCount = rsMetaData.getColumnCount();ArrayList resultData = new ArrayList ();while ( resultSet.next()) {String[] rowData = new String[ columnCount ];for ( int i = 0; i < rowData.length; i ++) {rowData[i] = resultSet.getString(i + 1);}resultData.add( rowData );}return resultData;

Page 60: ITWD

} catch (SQLException e) {e.printStackTrace();}return null;}

ElectricityServlet.java;

/** ElectricityServlet.java** Created on October 14, 2007, 11:26 AM*/

package pec.cse.elec;import java.io.*;import java.net.*;import javax.servlet.*;import javax.servlet.http.*;import java.util.*;public class ElectricityServlet extends HttpServlet {private AccessDb dbObj = new AccessDb ();protected void processRequest(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {String action = request.getParameter( "ACTION" );HttpSession session = request.getSession();if ( action == null ) {forwardPage ( request, response, "electricity/login.jsp");} else if ( "LOGIN".equals( action )) {int userID = Integer.parseInt( request.getParameter("USER_ID") );String password = request.getParameter("PASSWORD");if ( "8080".equals(Integer.toString(userID)) && "admin".equals(password)) {ArrayList allCustDetails = dbObj.getAllCustomerDetails();request.setAttribute( "ALL_CUST_DETAILS" , allCustDetails );forwardPage ( request, response, "electricity/adminview.jsp");} else {boolean isValidUser = dbObj.validateUser( userID, password );if ( isValidUser ) {

Page 61: ITWD

session.setAttribute( "USER_ID" , Integer.toString(userID) );String[] custDetails = dbObj.getCustomerDetails( userID );request.setAttribute( "CUST_DETAILS" , custDetails );forwardPage ( request, response, "electricity/paybill.jsp");}}} else if ( "PAY".equals( action )) {int userID = Integer.parseInt( (String) session.getAttribute( "USER_ID"));boolean isSuccess = dbObj.payBill( userID );if ( isSuccess ) {String[] custDetails = dbObj.getCustomerDetails( userID );request.setAttribute( "CUST_DETAILS" , custDetails );forwardPage ( request, response, "electricity/paymentsuccess.jsp");}} else if ("EDIT".equals( action )) {int custID = Integer.parseInt( request.getParameter( "CUST_ID"));String[] custDetails = dbObj.getCustomerDetails( custID );request.setAttribute( "CUST_DETAILS" , custDetails );forwardPage ( request, response, "electricity/adminupdate.jsp");} else if ("UPDATE".equals( action )) {int custID = Integer.parseInt( request.getParameter( "FIELD_0"));String custName = request.getParameter( "FIELD_1");String custAddress = request.getParameter( "FIELD_2");int custPhone = Integer.parseInt( request.getParameter( "FIELD_3"));String startDate = request.getParameter( "FIELD_4");String endDate = request.getParameter( "FIELD_5");double numUnits = Double.parseDouble( request.getParameter( "FIELD_6"));double charges = Double.parseDouble( request.getParameter( "FIELD_7"));boolean isSuccess = dbObj.updateCustomer( custID, custName, custAddress, custPhone, startDate, endDate, numUnits, charges );if ( isSuccess ) {ArrayList allCustDetails = dbObj.getAllCustomerDetails();request.setAttribute( "ALL_CUST_DETAILS" , allCustDetails );forwardPage ( request, response, "electricity/updatesuccess.jsp");}}}protected void doGet(HttpServletRequest request, HttpServletResponse response)

Page 62: ITWD

throws ServletException, IOException {processRequest(request, response);}protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {processRequest(request, response);}private void forwardPage ( HttpServletRequest request, HttpServletResponse response, String url ) {try {RequestDispatcher dispatcher = request.getRequestDispatcher( url );dispatcher.forward( request, response );} catch (ServletException ex) {ex.printStackTrace();} catch (IOException ex){ex.printStackTrace();}}}

Page 63: ITWD

SAMPLE INPUT AND OUTPUTUser:

Page 64: ITWD

Administrator:

Page 65: ITWD
Page 66: ITWD

Ex No:9 FILE AND DIRECTORY OPERATION IN ASP

AIM:To perform file and directory operations in ASP.

ALGORITHM:

1. Create an object for the file system and set path to the desired file.2. Display the date of creation and number of attributes in the file.3. Display the parent directory of the file.4. Create an object for the directory system and set path to the required directory.5. Display the sub folders in that directory.6. Create a folder and file in C directory.7. Check whether the that folder and file exists in C drive

CODING:

file.asp

<html><body><%dim fs, fset fs=Server.CreateObject("Scripting.FileSystemObject")set f=fs.GetFile(Server.MapPath("test.txt"))Response.Write(" The file test.txt was created on: " & f.DateCreated &"<br>")Response.Write(" The attributes of the file test.txt are: " & f.Attributes)set f=nothingset fs=nothing%><br><%Set fs=Server.CreateObject("Scripting.FileSystemObject")p=fs.GetParentFolderName("C:\Inetpub\wwwroot\test.txt")Response.Write("The parent folder name of C:\Inetpub\wwwroot\test.txt is: " & p &"<BR>")set fs=nothing%><%set fs=Server.CreateObject("Scripting.FileSystemObject")set fo=fs.GetFolder("c:\Inetpub")Response.Write("The folder object is created to identify in which folder u wish to work: " & fo &"<br>")Response.Write("The subfolders in " & fo & "is" )for each item in fo.subFoldersResponse.write (item &"<br>")nextset fs=nothingset fs=Server.CreateObject("Scripting.FileSystemObject")

Page 67: ITWD

set p=fs.createFolder("C:\test")Response.Write("The folder is created <br> " )set fs=nothingset fs=Server.CreateObject("Scripting.FileSystemObject")set p=fs.createTextFile("C:\test\test.txt")Response.Write("The file is created <br>" )set fs=nothingset fs=Server.CreateObject("Scripting.FileSystemObject")if fs.DriveExists("C:") thenResponse.Write("The drive exists <br>" )elseResponse.Write("The drive doesn't exists <br>" )end ifset fs=nothingset fs=Server.CreateObject("Scripting.FileSystemObject")if fs.FileExists("C:\test\test.txt") thenResponse.Write("The file exists <br>" )elseResponse.Write("The file doesn't exists <br>" )end ifset fs=nothing%></body></html>

SAMPLE SCREENSHOT

Page 68: ITWD

Ex No:10 SCIENTIFIC CALCULATOR USING JAVA APPLETS

AIM:

To implement scientific calculator using java applets.

ALGORITHM:

1. Start.2. Import the necessary packages to create an applet.3. Design the user interface using the required controls like labels, text boxes and buttons and code the necessary events for the buttons. 4. Compile the applet and run the applet by invoking the appletviewer command in the command prompt.5. When a number has to be given as an input to perform some operation the corresponding button is clicked and the respective actionPerformed() method is invoked.6. On pressing the “=” button the result is displayed in the text box.7. Stop.

CODINGimport java.awt.*;import java.applet.*;import java.awt.event.*;

Page 69: ITWD

/*<Applet code="cal.java" width=250 height=300></Applet>*/

public class cal extends Applet implements ActionListener{

String s,s2="0",w="0";int a=0,b=0,c=0,i=0;TextField t=new TextField(20);Button b1=new Button("1");Button b2=new Button("2");Button b3=new Button("3");Button b4=new Button("4");Button b5=new Button("5");Button b6=new Button("6");Button b7=new Button("7");Button b8=new Button("8");Button b9=new Button("9");Button b0=new Button("0");Button b11=new Button("+");Button b12=new Button("-");Button b13=new Button("/");Button b14=new Button("*");Button b15=new Button("sqrt");Button c1=new Button("c");Button on=new Button("ON");Button off=new Button("OFF");Button mc=new Button("MC");Button mr=new Button("MR");Button mp=new Button("M+");Button ms=new Button("MS");Button per=new Button("%");Button in=new Button("1/X");Button dot=new Button(".");Button pm=new Button("+/-");Button eql=new Button("=");public void init(){

setLayout(new FlowLayout());add(t);add(c1);add(on);add(off);add(mc);add(mr);add(ms);add(mp);add(b9);add(b8);

Page 70: ITWD

add(b7);add(b6);add(b5);add(b4);add(b3);add(b2);add(b1);add(b0);add(b11);add(b15);add(b12);add(per);add(b14);add(in);add(dot);add(pm);add(b13);add(eql);b0.addActionListener(this);b1.addActionListener(this);b2.addActionListener(this);b3.addActionListener(this);b4.addActionListener(this);b5.addActionListener(this);b6.addActionListener(this);b7.addActionListener(this);b8.addActionListener(this);b9.addActionListener(this);b11.addActionListener(this);b12.addActionListener(this);b13.addActionListener(this);b14.addActionListener(this);b15.addActionListener(this);in.addActionListener(this);off.addActionListener(this);dot.addActionListener(this);pm.addActionListener(this);eql.addActionListener(this);per.addActionListener(this);c1.addActionListener(this);on.addActionListener(this);mc.addActionListener(this);ms.addActionListener(this);mp.addActionListener(this);mr.addActionListener(this);t.setText("");

}public void actionPerformed(ActionEvent ae){

Page 71: ITWD

if(ae.getSource()==b1)if(a==1){

w=t.getText();if(w.equals("0"))

t.setText("1");else

t.setText(t.getText()+"1");}

if(ae.getSource()==b2)if(a==1){

w=t.getText();if(w.equals("0"))

t.setText("2");else

t.setText(t.getText()+"2");}

if(ae.getSource()==b3)if(a==1){

w=t.getText();if(w.equals("0"))

t.setText("3");else

t.setText(t.getText()+"3");}

if(ae.getSource()==b4)if(a==1){

w=t.getText();if(w.equals("0"))

t.setText("4");else

t.setText(t.getText()+"4");}

if(ae.getSource()==b5)if(a==1){

w=t.getText();if(w.equals("0"))

t.setText("5");else

t.setText(t.getText()+"5");}

if(ae.getSource()==b6)if(a==1){

w=t.getText();

Page 72: ITWD

if(w.equals("0"))t.setText("6");

elset.setText(t.getText()+"6");

}if(ae.getSource()==b7)

if(a==1){

w=t.getText();if(w.equals("0"))

t.setText("7");else

t.setText(t.getText()+"7");}

if(ae.getSource()==b8)if(a==1){

w=t.getText();if(w.equals("0"))

t.setText("8");else

t.setText(t.getText()+"8");}

if(ae.getSource()==b9)if(a==1){

w=t.getText();if(w.equals("0"))

t.setText("9");else

t.setText(t.getText()+"9");}

if(ae.getSource()==b0)if(a==1){

w=t.getText();if(w.equals("0"))

t.setText("1");else

t.setText(t.getText()+"0");}

if(ae.getSource()==b11)if(a==1){

s=t.getText();b=1;t.setText("0");c=0;

}

Page 73: ITWD

if(ae.getSource()==b12)if(a==1){

s=t.getText();b=2;t.setText("0");c=0;

}if(ae.getSource()==b13)

if(a==1){

s=t.getText();b=3;t.setText("0");c=0;

}if(ae.getSource()==b14)

if(a==1){

s=t.getText();b=4;t.setText("0");c=0;

}if(ae.getSource()==b15)

if(a==1){

c=0;s=t.getText();double g=Math.sqrt(Double.parseDouble(s));t.setText(String.valueOf(g));

}if(ae.getSource()==per)

if(a==1){

s=t.getText();double g=Double.parseDouble(s)/100;t.setText(String.valueOf(g));

}if(ae.getSource()==in)

if(a==1){

c=0;s=t.getText();double g=1/Double.parseDouble(s);t.setText(String.valueOf(g));

}if(ae.getSource()==pm)

if(a==1)

Page 74: ITWD

{c=0;s=t.getText();double g=Double.parseDouble(s)*-1;t.setText(String.valueOf(g));

}if(ae.getSource()==eql)

if(a==1){

String s1=t.getText();int sum;double m;switch(b){

case 1:if(c==1){

m=Double.parseDouble(s)+Double.parseDouble(s1);

t.setText(String.valueOf(m));}else{ sum=Integer.parseInt(s)+Integer.parseInt(s1); t.setText(String.valueOf(sum));}

break;case 2:

if(c==1){ m=Double.parseDouble(s)-

Double.parseDouble(s1); t.setText(String.valueOf(m));

}else{ sum=Integer.parseInt(s)-Integer.parseInt(s1);

t.setText(String.valueOf(sum));}

break;case 3:

if(c==1){

m=Double.parseDouble(s)/Double.parseDouble(s1); t.setText(String.valueOf(m));}else{

Page 75: ITWD

sum=Integer.parseInt(s)/Integer.parseInt(s1); t.setText(String.valueOf(sum));}

break;case 4:

if(c==1){

m=Double.parseDouble(s)*Double.parseDouble(s1); t.setText(String.valueOf(m));}else{ sum=Integer.parseInt(s)*Integer.parseInt(s1); t.setText(String.valueOf(sum));}

break;}

c=0;}

if(ae.getSource()==on){

a=1;t.setText("0");

}if(ae.getSource()==c1)

if(a==1)t.setText("0");

c=0;if(ae.getSource()==off){

a=0;t.setText("");

}if(ae.getSource()==mc)

if(a==1)s2="0";

if(ae.getSource()==mr)if(a==1)

t.setText("s2");if(ae.getSource()==ms)

if(a==1)s2=t.getText();

if(ae.getSource()==mp)if(a==1){

String s3=t.getText();int i=Integer.parseInt(s3)+Integer.parseInt(s2);s2=String.valueOf(i);

Page 76: ITWD

t.setText(s2);}

if(ae.getSource()==dot){

if(a==1)if(c==0)

t.setText(t.getText()+".");c=1;

}}public static void main(String a[]){

cal c=new cal();}

}

SCREENSHOTS:ADDITION OF TWO NUMBERS :

ENTER FIRST NUMBER:

Page 77: ITWD

ENTER SECOND NUMBER:

ADDED RESULT:

Page 78: ITWD

Ex No:11 SHOPPING CART USING JAVA THREADS

AIM:

To implement shopping cart using java threads.

ALGORITHM:

1. Start.2. Import the necessary packages to create an applet.3. Design the user interface using the required controls like labels, text boxes, check boxes and buttons and code the necessary events for the buttons. 4. Compile the applet and run the applet by invoking the appletviewer command in the command prompt.5. When a number has to be given as an input to perform some operation the corresponding button is clicked and the respective actionPerformed() method is invoked.6. On pressing the “=” button the result is displayed in the text box.7. Stop.

Page 79: ITWD

header.php:

<HTML><HEAD><title>e-Shop</title><style type="text/css">a:link {color:black}a:active {color:black}a:visited {color:black}td.one {background-color: #3388ff;}td.one:hover {background-color: #1111ff;}</style></HEAD>

<body background="images\back.jpg"><br><br><br><br><br><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font face="century" size="+1"><A href="index.php" style="text-decoration: none">Online shopping made easy!!!</a></font></b><br><br><br><table cellspacing=0 border="1" bordercolor="black" height=40 width="100%" ><tr><td colspan=3 bgcolor="#3388ff"><center><b><font size="+2">Our Categories</font></b></center></td></tr><TR><td align="center" class="one"><A href="product.php?categ=1" style="text-decoration: none"><b><font color="00ffdd" size="+2">Cell Phones</font></b></A></td><td align="center" class="one"><A href="product.php?categ=2" style="text-decoration: none"><b><font color="00ffdd" size="+2">Digital Camera</font></b></A></td><td align="center" class="one"><A href="product.php?categ=3" style="text-decoration: none"><b><font color="00ffdd" size="+2">MP3 Players</font></b></A></td>

Page 80: ITWD

</tr></table><table bgcolor="3388bb" cellspacing=0 border="1" bordercolor="black" height=500 width="100%"><tr><td>

index.php:

<?phpsession_start();include('header.php');?><br><br><?if(isset($_SESSION[user]))echo "<b><center>Welcome $_SESSION[fname]!</center></b>";else{echo "<table><tr><td width=600></td>";echo "<td>";echo "Welcome guest... Please login or sign up to buy our products....";echo "<br><br>";echo "<form name=login action=login.php method=post>";echo "User Name: <input type=text name=uname>";echo "Password: <input type=password name=upass><br><br>";echo "<center><input type=submit value=Login>";echo "<input type=button value=SignUp onclick=\"window.location='register.php'\"></center>";echo "</form>";echo "</td></tr></table>";}?><br><center><b><font size="+2">Latest Products In Our Store!</font></b><br><br><A href="vprod.php?categ=1" ><img height=250 width=300 src=images/1.jpg></a>&nbsp;&nbsp;<A href="vprod.php?categ=2" ><img height=250 width=300 src=images/2.jpg></a>&nbsp;&nbsp;<A href="vprod.php?categ=3" ><img height=250 width=300 src=images/3.jpg></a></center>

Page 81: ITWD

<br><p align="right"><img src="images/weaccept.gif">&nbsp;&nbsp;</p><br></td></tr></table></body></html>

login.php

<?phpsession_start();extract($_POST);$con=mysql_connect("localhost", "root", "") or die(mysql_error());mysql_select_db("shopping", $con) or die(mysql_error());$sql="select * from members where uname='$uname' and upass='$upass'";$res=mysql_query($sql, $con);while($newArray=mysql_fetch_array($res)){$uid=$newArray[slno];$fname=$newArray[fname];}$count=mysql_num_rows($res);if($count==1){$_SESSION[uid]=$uid;$_SESSION[user]=$uname;$_SESSION[fname]=$fname;header("Location: index.php");}else if($count<=0){header("Location: index.php");}?>

register.php:

<?phpsession_start();include('header.php');?><center>

Page 82: ITWD

<form name=inp action=sendinfo.php method=post><table width=350px border=1 cellspacing=0 cellpadding=5><tr> <td colspan=2><center><b>Enter the following Details</b></center></td><td width=35%>First Name</td><td width=65%><center><input type=text name=fname size=27></center></td></tr><tr><td width=35%>Last Name</td><td width=65%><center><input type=text name=lname size=27 onfocus="isEmpty(fname, 'Please Fill In Your First Name!')"></center></td></tr><tr><td width=35%>Username</td><td width=65%><center><input type=text name=uname size=27 onfocus="isEmpty(lname, 'Please Fill In Your Last Name!')"></center></td></tr><tr><td width=35%>Password</td><td width=65%><center><input type=password name=upass size=27 onfocus="isEmpty(uname, 'Please Fill In The UserName Field!')"></center></td></tr><tr><td width=35%>e-Mail</td><td width=65%><center><input type=text name=email size=27 onfocus="isEmpty(upass, 'You Need To Enter A Password!')"></center></td></tr><tr><td width=35%>Shipping Address</td><td width=65%><center><textarea name=addrs rows=4 onfocus="isEmpty(email, 'We Need Your e-Mail Address For Confirmation!')"></textarea></center></td></tr><tr><td width=35%>Contact No</td><td width=65%><center><input type=text name=phno1 size=3 onfocus="isEmpty(addrs, 'Please Fill In Your Shipping Address!')">&nbsp;&nbsp;&nbsp;<input type=text name=phno2 size=3 onfocus="isEmpty(phno1, 'Please Fill In Your Country Code!')">&nbsp;&nbsp;&nbsp;<input type=text name=phno3 size=10 onfocus="isEmpty(phno2, 'Please Fill In Your State Code!')"></center></td></tr><tr><td width=35%>Credit Card Type</td><td width=65%>

Page 83: ITWD

<select name=ctype onfocus="isEmpty(phno3, 'Please Fill In Your Telephone Number!')"><option value=amexp>American Express Card</option><option value=visa>Visa Card</option><option value=mascr>Master Card</option><option value=disco>Discover Card</option></select></td></tr><tr><td colspan=2><center><input type=submit value="Proceed"></center\></td></tr></table></form></center>

sendinfo.php:

<?phpsession_start();extract($_POST);$con=mysql_connect("localhost", "root", "") or die(mysql_error());mysql_select_db("shopping", $con) or die(mysql_error());$phno=$phno1.$phno2.$phno3;$sql="insert into members values('', '$fname', '$lname', '$uname', '$upass', '$email', '$addrs', '$phno', '$ctype');";mysql_query($sql, $con) or die(mysql_error());$sql="select * from members where uname='$uname'";$res=mysql_query($sql);while($newArray=mysql_fetch_array($res)){$uid=$newArray[slno];$fname=$newArray[fname];}$_SESSION[user]=$uname;$_SESSION[fname]=$fname;$_SESSION[uid]=$uid;header("Location: index.php");?>

product.php:

<?php

Page 84: ITWD

session_start();include("header.php");$slno=$_GET[categ];$con=mysql_connect("localhost", "root", "") or die(mysql_error());mysql_select_db("shopping", $con) or die(mysql_error());echo "<br>";$sql="select * from prod where slno=$slno";$res=mysql_query($sql, $con);$t=mysql_num_rows($res);if($t==0) noprod();$i=1; echo "<center>";$url="cart.php?t=".$t;echo "<form name=prod action=$url method=post>";while($newArray=mysql_fetch_array($res)){$cname="sel".$i;$qname="qua".$i;echo "<table width=900px border=1 cellspacing=0 cellpadding=4>";echo "<tr><td class=phead width=15%>Product ID: $newArray[pno]</td><td class=phead colspan=3>$newArray[pname]</td></tr>";$imgurl="images/".$newArray[pimage1];echo "<tr><td>Description</td><td colspan=2><p>$newArray[pdesc]</p></td><td colspan=2><img width=250px src=$imgurl></td></tr>";if(isset($_SESSION[user])){echo "<tr><td><input type=checkbox name=$cname value=$newArray[pno] onfocus=\"document.prod.$qname.disabled=false\"></td><td>Quantity</td><td><input type=text name=$qname size=3 disabled></td></tr>";echo "<tr><td colspan=4>Cost: $$newArray[pprice] [USD]</td></tr>";}else{echo "<tr><td colspan=4><center>Home: $newArray[ppage]</center></td></tr>";echo "<tr><td colspan=4>Cost: $$newArray[pprice] [USD]</td></tr>";}echo "</table><br><br>";$i++;}if(isset($_SESSION[user]))echo "<input type=submit value=\"Proceed -->\">";echo "</form>";function noprod()

Page 85: ITWD

{echo "<center>Sorry, Currently We Have No Products In This Category!</center>";exit(1);}?>

cart.php:

<?phpsession_start();include('header.php');$t=$_GET[t];$con=mysql_connect("localhost", "root", "") or die(mysql_error());mysql_select_db("shopping", $con) or die(mysql_error());echo"<center><b><font size=\"+2\" > Your Shopping Cart </font></b></center><br><br>";for($i=1; $i<=$t; $i++){$cname[$i]="sel".$i;$qname[$i]="qua".$i;$cname[$i]=$_POST[$cname[$i]];$qname[$i]=$_POST[$qname[$i]];}for($i=1; $i<=$t; $i++){if(isset($qname[$i])==1){$sql1="select * from prod where pno=$cname[$i];";$res1=mysql_query($sql1, $con);while($newArray=mysql_fetch_array($res1)){$pname=$newArray[pname];$pprice=$newArray[pprice];}$total=$pprice*$qname[$i];$sql2="insert into cart values ('',$_SESSION[uid], $cname[$i],'$pname', $pprice, $qname[$i], $total)";mysql_query($sql2, $con);}}$sql="select * from cart;";$res=mysql_query($sql, $con);

Page 86: ITWD

echo "<center><form name=cart method=post>";$t=mysql_num_rows($res);if($t!=0){echo "<table border=1 cellspacing=0 cellpadding=4>";echo "<tr>";echo "<td class=head>Product ID</td>";echo "<td class=head>Product Name</td>";echo "<td class=head>Price Per Unit</td>";echo "<td class=head>Quantity</td>";echo "<td class=head>Total Price</td>";echo "<td class=head>Remove</td>";echo "</tr>";$i=1;while($newArray=mysql_fetch_array($res)){$cname="del".$i;echo "<tr>";echo "<td>$newArray[pno]</td>";echo "<td>$newArray[pname]</td>";echo "<td>$newArray[pprice]</td>";echo "<td>$newArray[qua]</td>";echo "<td>$newArray[total]</td>";echo "<td><input type=checkbox name=$cname value=$newArray[no]></td>";echo "</tr>";$i++;}$sql="select uid, sum(total) as tot from cart group by uid;";$res=mysql_query($sql, $con);while($newArray=mysql_fetch_array($res)){if($newArray[uid]==$_SESSION[uid])$total=$newArray[tot];}echo "<tr><td class=head colspan=4>Total Price </td><td colspan=2><b>Rs. $total</b></td></tr>";echo "<tr><td colspan=3><input type=submit value=\"Check Out -->\" onclick=\"cart.action='chout.php'\"></td>";echo "<td colspan=3><input type=submit value=\"Delete Items\" onclick=\"cart.action='del.php?t=$t'\"></td></tr>";echo "</table>";}

Page 87: ITWD

else{echo "<br><br><br><br>There Are No Items In Your Cart!";}echo "<br>";echo "</form></center>";?>del.php:

<?php$t=$_GET[t];$con=mysql_connect("localhost", "root", "") or die(mysql_error());mysql_select_db("shopping", $con) or die(mysql_error());for($i=1; $i<=$t; $i++){$cname[$i]="del".$i;$cname[$i]=$_POST[$cname[$i]];if(isset($cname[$i])){$sql="delete from cart where no=$cname[$i];";mysql_query($sql, $con);}}header("Location: cart.php");?>

chout.php:

<?phpsession_start();include('header.php');echo "<br><center>";echo "<form name=pras action=lout.php method=post>";echo "<table border=1 cellspacing=0 cellpadding=4>";echo "<tr>";echo "<td colspan=2 class=head>Please Provide The Following Details</td>";echo "</tr>";echo "<tr>";echo "<td>Card Holder's Name</td>";echo "<td><input type=text name=chn></td>";echo "</tr>";echo "<tr>";

Page 88: ITWD

echo "<td>16 Digit Card Code</td>";echo "<td><input type=text name=dcc maxlength=20 value=\"XXXX-XXXX-XXXX-XXXX\" onclick=\"this.value=''\"></td>";echo "</tr>";echo "<tr>";echo "<td>3 Digit Card Number</td>";echo "<td><input type=password name=dcn size=2 maxlength=3></td>";echo "</tr>";echo "<tr>";echo "<td>Card Expiry Date</td>";echo "<td><input type=text name=day value=DD size=2 onclick=\"this.value=''\"><input type=text name=mon value=MM size=2 onclick=\"this.value=''\"><input type=text name=yea value=YYYY size=4 onclick=\"this.value=''\"></td>";echo "</tr>";echo "<tr>";echo "<td colspan=2><input type=submit value=\"Confirm Order\"></td>";echo "</tr>";echo "</table>";echo "</form>";echo "<br></center>";?>

lout.php:

<?phpsession_start();include('header.php');session_destroy();unset($_SESSION[uid]);unset($_SESSION[user]);unset($_SESSION[fname]);$con=mysql_connect("localhost", "root", "") or die(mysql_error());mysql_select_db("shopping", $con) or die(mysql_error());$sql="truncate table cart;";mysql_query($sql, $con);include('config.php');echo "<head>";echo "<title>$title</title>";echo "<script type=\"text/javascript\">";echo "function delayloading()";echo "{";

Page 89: ITWD

echo "window.location = \"index.php\"";echo "}";echo "</script>";echo "</head>";?><body onLoad="setTimeout('delayloading()', 5000)"><center><font size="+2"><b>Your Order Has Been Accepted! You Will Receive The Materials Soon!<br><br>Please Wait While We Log You Out To Our Home Page..</b></font></center></body></html>

SAMPLE INPUT AND OUTPUT:

Home page:

Page 90: ITWD

User registration form:

Page 91: ITWD

User home page:

Item Selection:

Page 92: ITWD

Billing:

Page 93: ITWD

Paying through credit card:

Page 94: ITWD

Ex No:12 SOCKET PROGRAMMING

AIM:

To implement socket programming using java.

ALGORITHM:

1. In server side, create a server socket.2. Server socket is ready to accept the client request.3. Server will get the message from client and read it using the class DataInputStream.4. In client side, client will get the server IP address.5. Then it will create the socket.6. Client will send the message through DataOutputStream class.7. In this way both server and client will communicate.

CODING:

SOURCE:

import java.io.*;import java.net.*;public class Provider{

ServerSocket providerSocket;Socket connection = null;ObjectOutputStream out;ObjectInputStream in;String message;Provider(){}void run(){

try{//1. creating a server socketproviderSocket = new ServerSocket(2004, 10);//2. Wait for connectionSystem.out.println("Waiting for connection");connection = providerSocket.accept();System.out.println("Connection received from " +

connection.getInetAddress().getHostName());//3. get Input and Output streamsout = new ObjectOutputStream(connection.getOutputStream());out.flush();in = new ObjectInputStream(connection.getInputStream());sendMessage("Connection successful");//4. The two parts communicate via the input and output streamsdo{

try{message = (String)in.readObject();

Page 95: ITWD

System.out.println("client>" + message);if (message.equals("bye"))

sendMessage("bye");}catch(ClassNotFoundException classnot){

System.err.println("Data received in unknown format");}

}while(!message.equals("bye"));}catch(IOException ioException){

ioException.printStackTrace();}finally{

//4: Closing connectiontry{

in.close();out.close();providerSocket.close();

}catch(IOException ioException){

ioException.printStackTrace();}

}}void sendMessage(String msg){

try{out.writeObject(msg);out.flush();System.out.println("server>" + msg);

}catch(IOException ioException){

ioException.printStackTrace();}

}public static void main(String args[]){

Provider server = new Provider();while(true){

server.run();}

}}

Page 96: ITWD

CLIENT:

import java.io.*;import java.net.*;public class Requester{

Socket requestSocket;ObjectOutputStream out;

ObjectInputStream in; String message;

Requester(){}void run(){

try{//1. creating a socket to connect to the serverrequestSocket = new Socket("localhost", 2004);System.out.println("Connected to localhost in port 2004");//2. get Input and Output streamsout = new ObjectOutputStream(requestSocket.getOutputStream());out.flush();in = new ObjectInputStream(requestSocket.getInputStream());//3: Communicating with the serverdo{

try{message = (String)in.readObject();System.out.println("server>" + message);sendMessage("Hi my server");message = "bye";sendMessage(message);

}catch(ClassNotFoundException classNot){

System.err.println("data received in unknown format");}

}while(!message.equals("bye"));}catch(UnknownHostException unknownHost){

System.err.println("You are trying to connect to an unknown host!");}catch(IOException ioException){

ioException.printStackTrace();}finally{

//4: Closing connectiontry{

in.close();out.close();requestSocket.close();

Page 97: ITWD

}catch(IOException ioException){

ioException.printStackTrace();}

}}void sendMessage(String msg){

try{out.writeObject(msg);out.flush();System.out.println("client>" + msg);

}catch(IOException ioException){

ioException.printStackTrace();}

}public static void main(String args[]){

Requester client = new Requester();client.run();

}}

Page 98: ITWD

SAMPLE INPUT AND OUTPUT: