WT-lab-Manual MASTER MANUAL
WT-lab-Manual MASTER MANUAL
Regulation : R20
A.Y. : 2023-24
WT LAB 1
CMR Engineering CSE(AI
LAB CODE
Students should report to the concerned lab as per the time table.
Students who turn up late to the labs will in no case be permitted to do the program schedule for the day.
After completion of the program, certification of the concerned staff in-charge in the observation book is necessary.
Student should bring a notebook of 100 pages and should enter the readings /observations into the notebook while
performing the experiment.
The record of observations along with the detailed experimental procedure of the experiment in the immediate last session
should be submitted and certified staff member in-charge.
The group-wise division made in the beginning should be adhered to and no mix up of students among different groups will
be permitted.
When the experiment is completed, should disconnect the setup made by them, and should return all the
components/instruments taken for the purpose.
Any damage of the equipment or burn-out components will be viewed seriously either by putting penalty or by dismissing
the total group of students from the lab for the semester/year.
Students are required to prepare thoroughly to perform the experiment before coming to laboratory.
WT LAB 2
CMR Engineering CSE(AI
WT LAB 3
CMR Engineering CSE(AI
2. PHP script to
a. Find the length of a string.
<!DOCTYPE html>
<html>
<body>
<?php
echo strlen("Hello world!");
?>
</body>
</html>
OUTPUT:
12
b. Count no of words in a string.
<!DOCTYPE html>
<html>
<body>
<?php
echo str_word_count("Hello world!");
?>
WT LAB 4
CMR Engineering CSE(AI
</body>
</html>
OUTPUT:
c. Reverse a string.
<!DOCTYPE html>
<html>
<body>
<?php
echo strrev("Hello world!");
?>
</body>
</html>
OUTPUT:
!dlrowolleH
d. Search for a specific string.
<!DOCTYPE html>
<html>
<body>
<?php
echo strpos("Hello world!", "world");
?>
</body>
</html>
OUTPUT:
6
<!DOCTYPE html>
<html>
<body>
<?php
echo str_replace("world", "Dolly", "Hello world!");
?>
OUTPUT:
Hello Dolly!
</body>
</html>
WT LAB 5
CMR Engineering CSE(AI
3. Write a PHP script to merge two arrays and sort them as numbers, in descending order.
<?php
$a1=array(1,3,15,7,5);
$a2=array(4,3,20,1,6);
$num=array_merge($a1,$a2);
array_multisort($num,SORT_DESC,SORT_NUMERIC);
print_r($num);
?>
Array ( [0] => 20 [1] => 15 [2] => 7 [3] => 6 [4] => 5 [5] => 4 [6] => 3 [7] => 3 [8] => 1 [9] => 1 )
4. Write a PHP script that reads data from one file and write into another file.
<?php
if(isset($_POST['save']))
$f=$_POST['file'];
$ext=$_POST['ext'];
$data=$_POST['data'];
$file=$f.$ext;
if(file_exists($file))
else
$fo = fopen($file,"w");
fwrite($fo,$data);
WT LAB 6
CMR Engineering CSE(AI
?>
<form method="post">
</textarea><br/>
</form>
<?php
if(isset($_POST['disp']))
WT LAB 7
CMR Engineering CSE(AI
$f=$_POST['file'];
$ext=$_POST['ext'];
$file=$f.$ext;
if(file_exists($file))
$fo = fopen($file,"r");
$contents = fread($fo,filesize($file));
else
?>
<form method="post">
WT LAB 8
CMR Engineering CSE(AI
</textarea><br/>
</form>
WT LAB 9
CMR Engineering CSE(AI
5. &6. Develop static pages (using Only HTML) of an online book store. The pages should
resemble: www.amazon.com. The website should consist the following pages.
a) Home page
b) Registration and user Login
c) User Profile Page
d) Books catalog
e) Shopping Cart
f) Payment By credit card
g) Order Conformation
Home page
Main.html:
<html>
<head>
<title>
Amazon</title>
</head>
<body bgcolor="cyan"><center>
<strong><h1>Welcome to AMAZON</h1></strong>
<form method="post" action="login.html" target=_blank >
<h4>for books</h4><input type="submit" value="click here">
</form>
</center>
</body>
</html>
Login.html:
<html>
<head>
<title>
login</title>
</head>
<body bgcolor="cyan"><center>
<strong><h1> AMAZON </h1></strong></center>
<right>
<table align="right">
<tr>
<td><h4>user name</td>
<td><input type="text" ></td>
<td></td>
</tr>
<tr>
WT LAB 10
CMR Engineering CSE(AI
<td><h4>password</td>
<td><input type="password"></td>
<td></td>
</tr>
<tr>
<td>
<form method="post" action="catalog.html" >
<input type="submit" value="submit" >
</form>
</td>
<td>
<form method="post" action="reg.html" >
<input type="submit" value="register" >
<input type="reset" value="reset"></form></td>
</tr>
</table>
</body>
</html>
Registration page
reg.html:
<html>
<head>
<title>
login page</title>
</head>
<body bgcolor="cyan">
<center><strong><h1> AMAZON </h1></strong></center>
<form method="post" action="catalog.html" >
<right>
<table align="left">
<tr>
<td><h4>user name</td>
<td><input type="text" ></td>
<tr>
<tr>
<td><h4>password</td>
<td><input type="password"></td>
</tr>
<tr>
<td><h4>confirm password</td>
<td><input type="password"></td>
</tr>
WT LAB 11
<t
<td><h4>male
<option >
<input type="radio" name="sex" id="male"></td>
<td><h4>female
<input type="radio" name="sex" id="female" ></td>
</option>
</tr>
<tr>
<td>Address</td>
<td><textarea name="address" rows=5 cols=19>
</textarea>
</td>
<tr>
<td>
<input type="submit" value="submit" ></td>
<td>
<input type="reset" value="reset"></td>
</tr>
</form>
</body>
</html>
Userprofile
userprofile.html
<html>
<head>
<title>
userprofile</title>
</head>
<body bgcolor="cyan"><center>
<strong><h1>Welcome to AMAZON Online Book Store </h1></strong></center>
Edit your profile here...
<form method="post" action="catalog.html" >
<right>
<table align="left">
<tr>
<td><h4>Edit user name</td>
<td><input type="text" ></td>
<tr>
<tr>
<td><h4>Edit password</td>
<td><input type="password"></td>
</tr>
WT LAB 12
<t
<option >
<td><h4>male
<input type="radio" name="sex" id="male"></td>
<td><h4>female
<input type="radio" name="sex" id="female" ></td>
</option>
</tr>
<tr>
<td>Edit Address</td>
<td><textarea name="address" rows=5 cols=19>
</textarea>
</td>
<tr>
<td>
<input type="submit" value="submit" ></td>
</tr>
</form>
</body>
</html>
Books catalog
Catalog.html:
<html>
<head>
<title>
books catalog</title>
</head>
<body bgcolor="cyan">
<center><h1>AMAZON</h1></center>
<form method="post" action="shopping.html">
<left>
<table>
<tr>
<td><b><h3>frontend books</td>
<td></td></tr>
<tr>
<td></td>
<td><h4>C&Ds</td>
</tr>
<tr>
<td></td>
<td><h4>Ads</td>
</tr>
WT LAB 13
<t
<td></td>
<td><h4>JAVA
</td></tr>
<tr>
<td><b><h3>backend books</td>
<td></td>
</tr>
<tr>
<td></td>
<td><h4>Oracle</td>
</tr>
<tr>
<td></td>
<td><h4>Ms SQL Server
</td></tr>
<tr>
<td></td>
<td><h4>MySql</td>
</tr>
</table>
</h4>
<center>
<b>for buy one of these books
<br>
</b><input type="submit" value="click here">
</center>
</form>
</body>
</html>
Shopping cart
Shopping.html:
<html>
<head><title>shopping cart</title>
</head>
<body bgcolor="cyan">
<center><h1>
Shopping Cart</h1></center>
<br><br><br><br><br>
<table align="center">
<tr>
<td>Text Books</td>
<td>
WT LAB 14
<select >
<optgroup label="select the book">
<option value="C&Ds">C&Ds
<option value="Ads">Ads
<option value="Java">Java
<option value="Oracle">Oracle
<option value="Ms SQL Server">Ms SQL Server
<option value="MySql">MySql
</optgroup>
</select>
</td></tr>
<tr>
<td>
Quantity</td>
<td>
<input type="text" id="q">
</td></tr>
<tr>
<td></td>
<td>
<form method=post action="payment.html">
<input type="submit" value=ok />
</form>
</td></tr>
</table>
<center>
<pre>Cost of one book is"500" + shipping "100"</pre>
</center>
<body>
</html>
Payment.html:
<html>
<head><title>payment</title></head>
<body bgcolor="cyan">
<center><h1>Payment By Credit Card</h1></center>
<form method=post action="ordrconform.html">
<br><br><br><br><br>
<table align="center">
<tr>
<td>
<h4>Total Amount</h4></td>
WT LAB 15
<td><input type="text">
</td>
</tr>
<tr>
<td><h4>Credit Card Number</td>
<td><input type="text"></td>
</tr>
<tr>
<td>
</td>
<td><input type="submit" value=OK>
</td>
</tr>
</table>
</form></body>
</html>
Order Conformation
Ordrconform:
<html>
<head><title>order conformation</title><M/head>
<body bgcolor="cyan">
<center>
<h1><b>BOOK SHOPPING</h1>
<pre><strong>
<b>Your order Is Conformed
</strong></pre>
<h2><b>THANK YOU</h2>
</center>
</body></html>
WT LAB 16
output:
WT LAB 17
WT LAB 18
WT LAB 19
WT LAB 20
7. Validate the Registration, user login, user profile and payment by credit card pages
using JavaScript.
Homepage:
Main.html:
<html>
<frameset rows="25%,*">
<frame src="top.html" name="top" scrolling ="no" frameborder ="0">
<frameset cols="25%,75%">
<frame src="left.html" name="left" scrolling ="no" frameborder ="0">
<frame src="right.html" name="right" scrolling ="auto" frameborder ="0">
</frameset>
</frameset>
</html>
Top.html:
<html>
<body bgcolor="pink">
<br><br>
<marquee><h1
align=”center”><b><u>ONLINE BOOK
STORAGE</u></b></h1></marquee>
</body>
</html>
Right.html:
<html>
<body>
<br><br><br><br><br>
<h2 align="center">
<b><p> welcome to online book storage. Press
login if you are having id otherwise press
registration.
</p></b></h2>
</body></html>
Left.html:
WT LAB 21
<html>
<body bgcolor="pink">
<h3>
<ul>
<li><a href="login.html"
target="right"><font color="black">
LOGIN</font></a></li><br><br>
<li><a href="profile.html"
target="right"><font color="black"> USER
PROFILE</font></a></li><br><br>
<li><a href="catalog.html"
target="right"><font color="black"> BOOKS
CATALOG</font></a></li><br><br>
<li><a href="scart.html"
target="right"><font color="black">
SHOPPINGCART</font></a></li><br><br>
<li><a href="payment.html" target="right"><font
color="black">
PAYMENT</font></a></li><br><br>
<br><br>
</ul>
</body>
</html>
Registration and user Login
Login.html:
<html>
<body bgcolor="pink"><br><br><br>
<script
language="javascript">
function validate()
{
var flag=1;
if(document.myform.id.value=="
"||
document.myform.pwd.value==
"")
{
alert("LoginId and Password must be
filled") flag=0;
}
if(flag==1)
{
WT LAB 22
alert("VALID INPUT");
window.open("catalog.html","right");
}
else
{
alert("INVALID INPUT");
//document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
LOGIN ID:<input type="text" name="id"><br>
PASSWORD:<input type="password"
name="pwd"><br><br>
</pre>
<input type="button" value="ok" onClick="validate()">
<input type="reset" value="clear" >
</div>
</form>
</body>
</html>
User profilepage
Profile.html:
<html>
<body bgcolor="pink"><br><br>
<script
type="text/javasc
ript"> function
validate()
{
var flag=1;
if(document.myform.name.value
==""||
document.myform.add
r.value==""||
document.myform.phn
o.value==""||
document.myform.id.v
alue==""||
document.myform.pw
WT LAB 23
d.value=="")
{
alert("Enter all the details");
flag=0;
}
var str=document.myform.phno.value;
var x=new RegExp("\\d","g");
if(!(str.match(x)))
{
if(!(str.
length
==10))
flag=0
;
}
var str1=document.myform.id.value;
var x1=new RegExp("^[A-Z][a-
zA-Z]+$","g");
if(!(str1.match(x1)))
{
flag=0;
alert("Invalid UserID");
}
var
str1=document.myform.pwd.valu
e; var x1=new RegExp("^[A- Z]
[a-zA-Z]+$","g");
if(!(str1.match(x1)))
{
flag=0;
alert("Invalid password");
}
if(f
lag
==
1)
{
alert("VALID INPUT");
window.self.location.href="login.html";
}
WT LAB 24
else
{
alert("INVALIDINPUT");
document.myform.focus();
<br><br>
}
}
</script>
<form name="myform">
<div align="center"><pre>
NAME :<input type="text" name="name"><br> ADDRESS :<input
type="type" name="addr"><br> CONTACT NUMBER:<input
type="text"name="phno"><br> LOGINID :<input
type="text"name="id"><br>
PASSWORD :<input type="password"name="pwd"></pre><br><br>
</div>
<div align="center">
<input type="button" value="ok" onClick="validate()">
<input type="reset" value="clear">
</form></body></html>
Bookscatalog:
Scart.html:
<html>
<body bgcolor="pink"><br><br><br>
<script
language="javascript
"> function
validate()
{
var flag=1;
if(document.myform.title.val
ue=="")
{
flag=0;
}
str=document.myform.title.value;
if(str=="c"||str=="C")
WT LAB 25
{
document.myform.t1.value="C";
document.myform.t2.value=444;
}
else if(str=="jsp"||str=="JSP")
else{
document.myform.t1.value="JSP"; document.myform.t2.value=555;
}
{
flag=0;
}
Shoppingcart:
Catalog.html:
<html>
<body bgcolor="pink"><br><br><br>
<script
language="javascript
"> function
validate()
{
var flag=1;
if(document.myform.id.value
==""||
document.myform.title.valu
e==""||
document.myform.no.valu
e==""||
document.myform.cost.val
ue=="")
{
flag=0;
}
str=document.myform.title.value;
var str1=document.myform.cost.value;
if(!((str=="c"&& str1==444) || (str=="jsp" && str1==555)))
{
WT LAB 26
flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
else
}
{
alert("INVALIDINPUT");
document.myform.focus();
}
</script>
<form name="myform" action="scart.html" target="right">
<div align="center"><pre>
LOGINID :<input type="text"
name="id"><br> TITLE :<input
type="text" name="title"><br>NO.OFBOOKS
:<input type="text"name="no"><br>
COSTOFBOOK :<input type="text"name="cost"><br>
</pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">
<input type="reset" value="clear">
</form>
</body>
</html>
Payment by creditcard
WT LAB 27
Payment.html:
<html>
<body bgcolor="pink"><br><br><br>
<script language="javascript">
function validate()
{
var flag=1;
if(document.myform.id.value==""|| document.myform.pwd.value==""||
document.myform.amount.value==""|| document.myform.num.value=="")
{
flag=0;
}
var str=document.myform.amount.value;
var x=new RegExp("\\d","g");
if(!(str.match(x)))
{
{
flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
window.self.location.href="order.html";
}
else
{
alert("INVALIDINPUT");
document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
LOGINID :<input type="text" name="id"><br>
PASSWORD :<input type="password" name="pwd"><br>
AMOUNT :<input
type="text"name="amount"><br>
CREDITCARDNUMBER :<input type="PASSWORD"name="num"><br></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="button" value="ok" onClick="validate()">
<input type="reset" value="clear" >
</form>
</body>
WT LAB 28
</html>
Order ConformationOrder.html:
<html>
<head><title>order conformation</title><M/head>
<body bgcolor="cyan">
<center>
<h1><b>AMAZON</h1>
<pre><strong>
<b>Your order Is Conformed
</strong></pre>
<h2><b>THANK YOU</h2>
</center>
</body>
</html>
OUTPUT:
Main.html
Login.html:
WT LAB 29
Catalog.html:
WT LAB 30
Scart.html:
WT LAB 31
Payment.html:
Order.html
WT LAB 32
8. Create and save an XML document on the server, which contains 10 users information.
Write a program, which takes User Id as an input and returns the user details by taking the
user information from the XML document.
<employees>
<employee id="111">
<firstName>Chandrika</firstName>
<lastName>Gupta</lastName>
<location>India</location>
</employee>
<employee id="222">
<firstName>Srinivas</firstName>
<lastName>Reddy</lastName>
<location>Russia</location>
</employee>
<employee id="333">
<firstName>Anupama</firstName>
<lastName>P</lastName>
<location>USA</location>
</employee>
<employee id="444">
<firstName>Lokesh</firstName>
<lastName>Gupta</lastName>
<location>India</location>
</employee>
<employee id="555">
<firstName>Vishnu</firstName>
<lastName>Gussin</lastName>
<location>Russia</location>
</employee>
<employee id="666">
<firstName>Veeru</firstName>
<lastName>Feezor</lastName>
<location>USA</location>
WT LAB 33
</employee>
<employee id="777">
<firstName>Pavan</firstName>
<lastName>Feezor</lastName>
<location>USA</location>
</employee>
<employee id="888">
<firstName>Narayana</firstName>
<lastName>Gussin</lastName>
<location>Russia</location>
</employee>
<employee id="999">
<firstName>David</firstName>
<lastName>Feezor</lastName>
<location>USA</location>
</employee>
<employee id="1000">
<firstName>Sunder</firstName>
<lastName>Feezor</lastName>
<location>USA</location>
</employee>
</employees>
ReadXML.java:
import org.w3c.dom.*;
import javax.xml.parsers.*;
import java.io.*;
import java.util.Scanner;
publicclassReadXML {
publicstaticvoidmain(String a[]) throws
Exception{ DocumentBuilderFactory factory
=
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
//Build Document
Document document = builder.parse(new
File("C:\\Users\\Narayana\\Desktop\\employees.xml"));
//Normalize the XML Structure; It's just too
important !!
document.getDocumentElement().normalize();
WT LAB 34
//Here comes the root node
Element root = document.getDocumentElement();
OUTPUT:-
WT LAB 35
9. Install TOMCAT web server. Convert the static web pages of assignments 2 into dynamic
web pages using servlets and cookies. Hint: Users information (user id, password, credit card
number) would be stored in web.xml. Each user should have a separate Shopping Cart.
PROCEDURE:
Web.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Servlet 2.4 Examples</display-name>
<description>
Servlet 2.4 Examples.
</description>
<servlet>
<servlet-name>reg</servlet-name>
<servlet-class>reg</servlet-class>
</servlet>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>login</servlet-class>
</servlet>
<servlet>
<servlet-name>profile</servlet-name>
<servlet-class>profile</servlet-class>
</servlet>
<servlet>
<servlet-name>catalog</servlet-name>
<servlet-class>catalog</servlet-class>
WT LAB 36
<servlet-mapping>
<servlet-name>order</servlet-name>
<url-p</servlet>
<servlet>
<servlet-name>order</servlet-name>
<servlet-class>order</servlet-class>
</servlet>attern>order<
/url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>catalog</servlet-name>
<url-pattern>catalog</url-pattern>
</servlet-mapping> 26
<servlet-mapping>
<servlet-name>profile</servlet-name>
<url-pattern>profile</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>login</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>reg</servlet-name>
<url-pattern>reg</url-pattern>
</servlet-mapping>
</web-app>
Main.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="pink">
<br /><br /><br /><br /><br />
<h1 align="center"><U>ONLINE BOOK STORAGE</U></h1><br /><br /><br />
<h2 align="center"><pre>
<b>Welcome to online book
storage. Press LOGIN if you are
having id otherwise press
REGISTRATION
</b></pre></h2>
<br /><br/><pre>
<div align="center"><a
href="/tr/login.html">LOGIN</a><a href="/tr/reg.html">
REGISTRATION</a></div></pre>
</body>
</html>
Login.html
WT LAB 37
<html>
<body bgcolor="pink"><br /><br /><br />
<form name="myform" method="post" action="/tr/login">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br />
PASSWORD :<input type="password" name="pwd" /></pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()"
/> <input type="reset"
value="clear" />
</div>
</form>
</body>
</html>
Reg.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="pink"><br /><br />
<form name="myform" method="post" action="/tr/reg">
<div align="center"><pre>
NAME :<input type="text" name="name" /><br/>
ADDRESS :<input type="text" name="addr"
/><br /> CONTACTNUMBER :<input type="text"
name="phno" /><br /> LOGINID :<input type="text"
name="id"
/><br/>
PASSWORD :<input type="password" name="pwd" /></pre><br /><br/>
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()"
/> <input type="reset"
value="clear" />
</div>
</form>
</body>
</html>
Profile.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="pink"><br /><br /><br />
<form name="myform" method="post" action="/tr/profile">
WT LAB 38
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br />
</pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()"
/> <input type="reset"
value="clear" />
</div></form></body></html>
Catalog.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="pink"><br /><br /><br />
<form method="post" action="/tr/catalog">
<div align="center"><pre>
BOOK TITLE :<input type="text" name="title" /><br />
</pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" name="button1"/>
<input type="reset" value="clear"name="button2"/>
</div>
</form>
</body></html>
Order.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
WT LAB 39
name="button1"/> <input type="reset"
value="clear" name="button2"/>
</div>
</form>
</body>
</html>
Login.java 29
import java.sql.*;
import java.io.*;
import java.util.*;
import
javax.servlet.*;
import javax.servlet.http.*;
public class login extends HttpServlet
{
public void
service(HttpServletRequestreq,HttpServletResponse resp)
throws ServletException,IOException
{ PrintWriter
pw=resp.getWriter();
pw.println("<html><body bgcolor=\"pink\");
Stringid=req.getParamenter("id");
String
pwd=req.getParameter("pwd"); try
{ Driver
d=neworacle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger
")
;
Statement stmt=con.createStatement();
String sqlstmt="select id,password from
login";
ResultSetrs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next(
))
{
if(id.equal(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)
{
WT LAB 40
}
else
{
pw.println("SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\"/tr/login.html\">press LOGIN to RETRY</a>");
pw.println("<li><ahref=\"catalog.html\"><fontcolor=\"black\">BOO
KS CATALOG</font></a></li><br><br>");
pw.println("<li><ahref=\"order.html\"><fontcolor=\"black\">OR
DER CONFIRMATION</font> </a></li><br><br>");
}
pw.println("</body></html>");
}
catch(Exception e)
{ resp.sendError(500,e.toString());
}
}
Reg.html 30
import java.sql.*;
import java.io.*;
import java.util.*;
import
javax.servlet.*;
import javax.servlet.http.*;
public class login extends HttpServlet
{
public void
service(HttpServletRequestreq,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body
bgcolor=\"pink\"); String
name=req.getParamenter("name");
String addr=req.getParameter("addr");
String phno=req.getParameter("phno");
Stringid=req.getParamenter("id");
String
pwd=req.getParameter("pwd"); int
WT LAB 41
no=Integer.parseInt(phno);
try
{
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger
")
;
Statement stmt=con.createStatement();
String sqlstmt="select id,password from
login";
ResultSetrs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next(
))
{
if(id.equal(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
} }
if(flag==1)
{
pw.println("SORRY INVALID ID ALREADY EXITS TRY AGAIN WITH NEW
ID<br><br>");
pw.println("<a href=\"/tr/reg.html\">press REGISTER to RETRY</a>");
}
else
{ Statement
stmt1=con.createStatement();
stmt1.executeUpdate("insertintologin
values("+names","+addr+","+no+","+id+","+pwd+")");
pw.println("YOUR DETAILS
AREENTERED<br><br>");
pw.println("<a href=\"/tr/login.html\">press LOGIN to login</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{ resp.sendError(500,e.toString());
} }}
Catlog.java 31
import java.sql.*;
import java.io.*;
import java.util.*;
import
javax.servlet.*;
import javax.servlet.http.*;
WT LAB 42
public class login extends HttpServlet
{
public void
service(HttpServletRequestreq,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body
bgcolor=\"pink\"); String
title=req.getParameter("title");
try
{
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger
")
;
Statement stmt=con.createStatement();
String sqlstmt="select id,password from
login";
ResultSetrs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next(
))
{
pw.println(",div align=\"center\">");
pw.println("TITLE
:"+rs.getString(1)+"<br>
"); pw.println("AUTHOR :"+rs.getString(2)+"<br>");
pw.println("VERSION :"+rs.getString(3)+"<br>");
pw.println("PUBLISHER
:"+rs.getString(4)+"<br>
"); pw.println("COST
:"+rs.getString(5)+"<br>
"); pw.println("</div");
flag=1;
}
if(flag==0)
{
pw.println("SORRY INVALID TITLE TRY AGAIN <br><br>");
pw.println("<a href=\"/tr/catalog.html\">press HERE to RETRY</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
WT LAB 43
}
}
Profile.java
import java.sql.*;
import java.io.*;
import java.util.*;
import
javax.servlet.*;
import javax.servlet.http.*;
public class login extends HttpServlet
{
public void
service(HttpServletRequestreq,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body
bgcolor=\"pink\"); String
id=req.getParamenter("id");
try
{
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
con=DriverManager.getConnection("jdbc:ora
cle:thin:
@localhost:1521:orcl","scott","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from login
where id="+id+"";
ResultSetrs=stmt.executeQuery(sqlstmt);
int flag=0;
pw.println("<br><br><br>");
while(rs.next())
{
pw.println("<div align=\"center\">");
pw.println("NAME
:"+rs.getString(1)+"<br>"
);
pw.println("ADDRESS:"+rs.getString(2)+"<br
>");
pw.println("PHONENO
:"+rs.getString(3)+"<br>"
); pw.println("</div>");
flag=1;
}
if(flag==0)
{
WT LAB 44
pw.println("SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\"/tr/profile.html\">press HERE to RETRY</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
Order.java 33
import java.sql.*;
import java.io.*;
import java.util.*;
import
javax.servlet.*;
import javax.servlet.http.*;
public class login extends HttpServlet
{
public void
service(HttpServletRequestreq,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body
bgcolor=\"pink\");
Stringid=req.getParamenter("id");
String
pwd=req.getParameter("pwd");
String
title=req.getParameter("title");
String
count1=req.getParameter("no");
String
date=req.getParameter("date");
String
cno=req.getParameter("cno");
intcount=Integer.parseInt(count1);
try
{
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger
")
;
Statement stmt=con.createStatement();
String sqlstmt="select id,password from
WT LAB 45
login";
ResultSetrs=stmt.executeQuery(sqlstmt);
int
flag=0,amount,x;
while(rs.next())
{
if(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)
{
pw.println("SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\\"/tr/order.html\\">press HERE to RETRY</a>");
}
else
{
Statement stmt2=con.createStatement();
String s="select cost from book where title="+title+""; ResultSet
rs1=stmt2.executeQuery(s);
int flag1=0; while(rs1.next())
{
flag1=1;
x=Integer.parseInt(rs1.getString(
1));
amount=count*x; 34
pw.println("AMOUNT :"+amount+"<br><br><br><br>");
Statement stmt1=con.createStatement();
stmt1.executeUpdate("insertintodetailsvalues('"+id+",'"+title
+"'+amount+'","'+cno+'")"'); pw.println("YOUR ORDER has
taken<br>");
}
if(flag1==0)
{
pw.println("SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\\"/tr/order.html\\">press HERE to RETRY</a>");
}
}
pw.println("</body></html>");
con.close();
}
WT LAB 46
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
35
WT LAB 47
36
WT LAB 48
37
WT LAB 49
10. Redo the previous task using JSP by converting the static web pages of assignments 2
into dynamic web pages. Create a database with user information and books information. The
books catalogue should be dynamically loaded from the database. Follow the MVC
architecture while doing the website.
PROCEDURE:
Main.html:
<html>
<body bgcolor=”pink”>
<br><br><br><br><br><br>
<h1 align=”center”>>U>ONLINE BOOK STORAGE</u></h1><br><br><br>
<h2 align=”center”><PRE>
<b> Welcome to online book
storage. Press LOGIN if
you are having id
Otherwise press REGISTRATION
</b></PRE></h2>
<br><br><pre>
<div align=”center”><a
href=”/tr/login.html”>LOGIN</a>href=”/tr/log
in.html”>REGISTRATION</a></div></pre>
</body></html>
Login.html:
<html>
<body bgcolor=”pink”><br><br><br>
<form name="myform" method="post" action=/tr1/login.jsp">
<div align="center"><pre>
LOGIN ID :<input type="passwors"
name="pwd"></pre><br><br> PASSWORD : <input
type="password" name="pwd"></pre><br><br>
</div>
<br><br>
<div align="center">
<inputtype="submit"value="ok"onClick="validate()">
<input type="reset" value="clear">
WT LAB 50
</form>
</body></html>
Reg.html:
<html>
<body bgcolor="pink"><br><br>
<form name="myform" method="post" action="/tr1/reg.jsp">
<div align="center"><pre>
NAME :<input type="text"
name="name"><br> ADDRESS :<input
type="text"name="addr"><br>
CONTACT NUMBER :<input type="text"
name="phno"><br> LOGINID : <input
type="text"name="id"><br>
PASSWORD :<input type="password" name="pwd"></pre><br><br>
</div>
<br><br>
<div align="center">
<inputtype="submit"value="ok"
onClick="validate()">()"> <input
type="reset" value="clear">
</form>
</body>
</html>
Profile.html:
<html>
<body bgcolor="pink"><br><br>
<form name="myform" method="post" action="/tr1/profile.jsp">
<div align="center"><pre>
LOGINID : <input type="text"name="id"><br>
</pre><br><br>
</div>
<br><br>
<div align="center">
<inputtype="submit"value="ok"
onClick="validate()">()"> <input
type="reset" value="clear">
</form>
</body>
</html>
WT LAB 51
Catalog.html:
<html>
<body bgcolor="pink"><br><br><br>
<form method="post" action="/tr1/catalog.jsp">
<div align="center"><pre>
BOOK TITLE :<input type="text" name="title"><br>
</pre><br><br>
</div>
<br><br>
<div align="center">
<inputtype="submit"value="ok"
name=”button1”> <inputtype="reset"value="clear"
name=”button2
”>
</form>
</body>
</html>
Order.html:
<html>
<body bgcolor="pink"><br><br><br>
<form method="post" action="/tr1/order.jsp">
<div align="center"><pre>
LOGINID :<input type="text"
name="id"><br>PASSWORD :<input
type="password" name="pwd"><br> TITLE
:<input
type="text"name="title"><br>
NO. OF BOOKS :<input type="text"
name="no"><br> DATE : <input
type="text"name="date"><br>
CREDIT CARD NUMBER :<input type="password" name="cno"><br></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" name=”button1”> <input
type="reset" value="clear"name=”button2”>
</form>
</body>
</html>
Login.jsp: 41
%@page import=”java.sql.*”%
%@page import=”java.io.*”%
<%
out.println(“<html><body
bgcolor=\”pink\”>”); String
WT LAB 52
id=request.getParameter(“id”);
String
pwd=request.getParameter(“pwd”);
Driver d=new
oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
con=DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”);
Statement stmt=con.createStatement();
String sqlstmt=”selectid,password from login where id=”+id+” and
password=”+pwd+””; ResultSetrs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.nex
t())
{
flag=1;
}
if(flag==0)
{
out.println(“SORRY INVALID ID TRY AGAIN ID<br><br>”);
out.println(“ <a href=\”/tr1/login.html\”>press LOGIN to RETRY</a>”);
}
else
{
out.println(“VALID LOGIN ID<br><br>”);
out.println(“<h3><ul>”);
out.println(“<li><ahref=\”profile.html\”><fontcolor=\”black\”>USER
PROFILE</font></a></li><br><br>”);
out.println(“<li><ahref=\”catalog.html\”><fontcolor=\”black\”>BOOKS
CATALOG</font></a></li><br><br>”);
out.println(“<li><ahref=\”order.html\”><fontcolor=\”black\”>ORDER
CONFIRMATION</font></a></li><
br><br>”); out.println(“</ul>”);
}
out.println(“<body></html>”);
%>
42
Reg.jsp:
%@page import=”java.sql.*”%
%@page import=”java.io.*”%
<%
out.println(“<html><body
bgcolor=\”pink\”>”); String
name=request.getParameter(“name”);
String
addr=request.getParameter(“addr”);
WT LAB 53
String
phno=request.getParameter(“phno”);
String id=request.getParameter(“id”);
String
pwd=request.getParameter(“pwd”);
int no=Integer.parseInt(phno);
Driver d=new
oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection con=
DriverManager.getConnection
(“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”); Statement
stmt=con.createStatement();
String sqlstmt=”select id from
login”;
ResultSetrs=stmt.executeQuery(sql
stmt); int flag=0;
while(rs.next())
{
if(id.equals(rs.getString(1)))
{
flag=1;
}
}
if(flag==1)
{
out.println(“SORRY LOGIN ID ALREADY EXISTS TRY AGAIN WITH NEW ID <br><br>”);
out.println(“<a href=\”/tr1/reg.html\”>press REGISTER to RETRY</a>”);
}
else
{
Statement stmt1=con.createStatement ();
stmt1.executeUpdate (“insert into login values
(“+name+”,”+addr+”,”+no+”,”+id+”,”+pwd+”)”); out.println (“YOU DETAILS
ARE ENTERED <br><br>”);
out.println (“<a href =\”/tr1/login.html\”>press LOGIN to login</a>”);
}
out.println (“</body></html>”);
%>
Profile.jsp: 43
<%@page import=”java.sql.*”%>
<%@page import=”java.io.*”%>
<%
out.println (“<html><body
bgcolor=\”pink\”>”); String
id=request.getParameter(“id”);
Driver d=new
oracle.jdbc.driver.OracleDriver();
DriverManager.regiserDriver(d);
WT LAB 54
Connection con=
DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:orcl”,”s
cott”,”tiger”); Statement stmt=con.createStatement ();
String sqlstmt=”select * from login where
id=”+id+””; ResultSetrs=stmt.executeQuery
(sqlstmt);
int
flag=0;
while(rs.next())
{
out.println (“<div align=\”center\”>”);
out.println(“NAME
:”+rs.getString(1)+”<b
r>”); out.println (“ADDRESS
:”+rs.getString(2)+”<br>”); out.println
(“PHONE NO :”+rs.getString(3)+”<br>”);
out.println (“</div>”);
flag=1;
}
if(flag==0)
{
out.println(“SORRY INVALID ID TRY AGAIN ID <br><br>”);
out.println(“<a href=\”/tr1/profile.html\”>press HERE to RETRY </a>”);
}
out.println (“</body></html>”);
%>
Catalog.jsp:
<%@page import=”java.sql.*”%>
<%@page import=”java.io.*”%>
<%
out.println (“<html><body
bgcolor=\”pink\”>”); String
title=request.getParameter (“title”);
Driver d=new
oracle.jdbc.driver.OracleDriver ();
DriverManager.regiserDriver (d);
Connection con=
DriverManager.getConnection
(“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”); Statement
stmt=con.createStatement ();
String sqlstmt=”select * from book where
title=”+title+””; ResultSetrs=stmt.executeQuery
(sqlstmt);
int
flag=0;
while(rs.nex
t())
WT LAB 55
{
out.println (“<div align=\”center\”>”);
out.println(“TITLE
:”+rs.getString(1)+”<br
>”); out.println (“AUTHOR
:”+rs.getString(2)+”<br>”); out.println
(“VERSION:”+rs.getString(3)+”<br>”);
out.println (“PUBLISHER :”
+rs.getString(4)+”<br>”); out.println
(“COST :”
+rs.getString(5)+”<br>”); out.println
(“</div>”);
flag=1;
}
if(flag==0)
{
out.println(“SORRY INVALID ID TRY AGAIN ID <br><br>”);
out.println(“<a href=\”/tr1/catalog.html\”>press HERE to RETRY </a>”);
}
out.println (“</body></html>”);
%>
Order.jsp:
<%@page import=”java.sql.*”%>
<%@page import=”java.io.*”%>
<%
out.println (“<html><body
bgcolor=\”pink\”>”); String
id=request.getParameter (“id”);
String pwd=request.getParameter
(“pwd”); String
title=request.getParameter (“title”);
String count1=request.getParameter
(“no”); String
date=request.getParameter (“date”);
String cno=request.getParameter
(“cno”); int
count=Integer.parseInt(count1);
Driver d=new
oracle.jdbc.driver.OracleDriver ();
DriverManager.regiserDriver (d);
Connection con=
DriverManager.getConnection
(“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”); Statement
stmt=con.createStatement ();
String sqlstmt=”select id, password
from login”;
ResultSetrs=stmt.executeQuery
(sqlstmt);
WT LAB 56
int
flag=0,amount,x;
while(rs.next())
{
if(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)
{
out.println(“SORRY INVALID ID TRY AGAIN ID <br><br>”);
out.println(“<a href=\”/tr1/order.html\”>press HERE to RETRY </a>”);
}
els
e{
Statement stmt2=con.createStatement();
String s=”select cost from book where
title=”+title+””; ResultSet
rs1=stmt2.executeQuery(s);
int flag1=0;
{ while(rs1.nex
t())
flag1=1;
x=Integer.parseInt(rs1.getStri
ng(1)); amount=count*x;
out.println(“AMOUNT
:”+amount+”<br><br><br><br>”); Statement
} stmt1=con.createStatement ();
stmt1.executeUpdate (“insert into details
(“+id+”,”+title+”,”+amount+”,”+date+”,”+cno+”)”); out.println
(“YOU ORDER HAS TAKEN<br>”);
if(flag1==0)
{
out.println(“SORRY INVALID BOOK TRY AGAIN <br><br>”);
out.println(“<a href=\”/tr1/order.html\”>press HERE to RETRY </a>”);
}
} out.println (“</body></html>”);%>
WT LAB 57
WT LAB 58
WT LAB 59
WT LAB 60
LEAD EXPERMENTS
1. Write a program to check the given number is Armstrong or not using PHP SCRIPT?
PROGRAM:
<html>
<body bgcolor=red>
<!-- to test this script type 371 or 407, these are armstrong numbers -->
</form>
</body>
</html>
<?php
if( $_POST )
WT LAB 61
{
}else
?>
OUTPUT
WT LAB 62
WT LAB 63
2. Write a program to perform validations to the Script
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<?php
$name = test_input($_POST["name"]);
$email = test_input($_POST["email"]);
$website = test_input($_POST["website"]);
$comment = test_input($_POST["comment"]);
$gender = test_input($_POST["gender"]);
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
?>
<br><br>
WT LAB 64
E-mail: <input type="text" name="email">
<br><br>
<br><br>
<br><br> Gender:
<br><br>
</form>
<?php
echo "<h2>Your Input:</h2>"; echo $name;echo "<br>"; echo $email; echo "<br>";
echo $website; echo "<br>"; echo $comment; echo "<br>"; echo $gender;
?>
</body>
</html>
OUTPUT:
WT LAB 65
WT LAB 66