WT Lab Manual Cse Jntuh
WT Lab Manual Cse Jntuh
WT Lab Manual Cse Jntuh
1 Creation of static web pages of online book store such as HOME, LOGIN, and
CATALOGUE pages.
5 Validation of XML file using DTD and displaying its data in a table using XSL and
CSS
6 Creation of simple visual bean with area filled with a color. The shape of area
depends on property shape, and configuration of the bean.
7 Installation of TOMCAT web server APACHE tomcat on port no 4040 and APACHE
on port no 8080
Designing of following static web pages required for an online book store web site.
1) HOME PAGE
2) LOGIN PAGE:
3) CATOLOGUE PAGE:
The catalogue page should contain the details of all the books available in the
web site in a table.
The details contain the following:
a. Snap shot of Cover Page.
b. Author Name.
c. Publisher.
d. Price.
e. Add to cart button.
4) CART PAGE:
a. The cart page contains the details about the books which are added to the
cart.
b. The cart page should look like this:
5) REGISTRATION PAGE:
“registration form “with the following fields
1) Name (Text field)
2) Password (password field)
3) E-mail id (text field)
4) Phone number (text field)
5) Sex (radio button)
6) Date of birth (3 select boxes)
7) Languages known (check boxes – English, Telugu, Hindi, Tamil)
8) Address (text area)
<html>
<head><title>Book</title></head>
<frameset rows="25%,75%">
<frame src="top.html" name="top" framespacing="0" scrolling="no" frameborder="0"
noresize>
<frameset cols="15%,85%">
<frame src="left.html" name="left" framespacing="0" scrolling="auto"
frameborder="0" noresize>
<frame src="right.html" name="right" framespacing="0" scrolling="auto"
frameborder="0" noresize>
</frameset>
</frameset>
</html>
<html>
<head>
<title>top</title>
<style>
a:link{text-decoration:none}
a:visited {text-decoration:none;color:red}
a:hover {text-decoration:underline;color:green}
a:active {text-decoration:none;color:blue}
</style>
</head>
<body bgcolor="#fedcba" >
<p align="center">
<table height="100%" width="100%" border="0" align="center" height="100%">
<colgroup span="5" width="20%"></colgroup>
<tr align="center"><td><img src="logo.gif" width="85%" name="logo" alt="site
logo"></td><td colspan="4"><h1>AMAZON BOOKS WORLD</h1></td></tr>
<tr align="center"><td><a name="home" href="home.html"
target="right">HOME</a></td>
<td><a name="login" href="login.html" target="right">LOGIN</a></td>
<td><a name="registration" href="registration.html"
target="right">REGISTRATION</a></td>
<td><a name="catalogue" href="catalogue.html"
target="right">CATALOGUE</a></td>
<td><a name="cart" href="cart.html" target="right">CART</a></td>
</tr>
</table>
</p>
</body>
</html>
<html>
<head>
<title>right frame
</title>
</head>
<body bgcolor="#abcdef">
<font color='#123123' size='+3'>welcome to amazon books world</font>
<br>
This site provides the books information related to various categories.
</body>
</html>
<html>
<head>
<title>home page
</title>
</head>
<body bgcolor="#abcdef">
<font color='#123123' size='+3'>welcome to amazon books world</font>
<br>
This site provides the books information related to various categories.
</body>
</html>
<html>
<head>
<title>login form</title>
</head>
<body bgcolor="#abcdef">
<h3 align="center">login into the site</h3>
<form method="post">
<table align="center">
<tr><td>name</td><td><input type="text" name="uname"></td></tr>
<tr><td>password</td><td><input type="password" name="pass"></td></tr>
<tr align="center"><td><input type="submit" value=" login "></td><td><input
type="reset" value=" reset "></td></tr>
</table>
</form>
</body>
</html>
<html>
<head>
<title>Registration form</title>
</head>
<body bgcolor="orange">
<h3 align="center" color="pink">Registration form</h3>
<center>
<form name="regform" method="post">
<table cellspacing="15">
<tr><td>NAME</td><td><input type="text" name="name" size="25"></td></tr>
<tr><td>PASSWORD</td><td><input type="password" name="pass" size="25">
</td></tr>
<tr><td>PHONE NUMBER</td><td><input type="text" maxLength="10" name="phno"
size="25"></td></tr>
<tr><td>E-MAIL</td><td><input type="text" name="emai" size="25"> </td></tr>
<tr><td>GENDER</td><td>male <input type="radio" name="gender" value="male"
checked="checked"> female <input type="radio" name="gender"
value="female"></td></tr>
<tr><td>DATE OF BIRTH</td><td>day<select name="day"><option
value="1">1</option><option value="2">2</option></select>
month <select name="month"><option
value="jan">jan</option><option value="feb">feb</option></select>
year<select name="year"><option value="1990">1990</option><option
value="1991">1991</option></select> </td></tr>
<tr><td>LANGUAGES KNOWN</td><td>TELUGU <input
type="checkbox" name="telugu" value="telugu"><br>ENGLISH <input
type="checkbox" name="english" value="english"><br>HINDI
<input type="checkbox" name="hindi" value="hindi"> </td>
</tr>
<tr><td>ADDRESS</td><td><textarea rows="3" cols="25" name="address"
wrap="soft"></textarea></td>
</tr>
</table>
<br><br>
<input type="submit" align="center" value="send"> <input type="reset"
align="center" value="cancel">
</form>
</center>
</body>
</html>
<html>
<head>
<title>catalogue page</title>
</head>
<body bgcolor="#abcdef">
<table width="100%">
<tr><td><img src="xml.jpg"></td>
<td>Book: XML Bible<br>
Author: Winston<br>
Publication: Wiely
</td>
<td>$ 40.5</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="html.jpg"></td>
<td>Book : HTML in 24 hours<br>
Author : Sam Peter<br>
Publication : Sam publication
</td>
<td>$ 50</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="ai.jpg"></td>
<td>Book : AI<br>
Author : S.Russel<br>
Publication : Princeton hall
</td>
<td>$ 63</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="java.jpg"></td>
<td>Book : Java 2<br>
Author : Watson<br>
Publication : BPB publications
</td>
<td>$ 35.5</td>
<td><img src="cartbutton.jpg"></td>
</tr>
</table>
</body>
</html>
<html>
<head>
<title>cart page</title>
</head>
<body bgcolor="#abcdef">
<table align="center" width="75%">
<tr align="center"><th>Book Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Amount</th>
</tr>
<tr align="center"><td>Java2</td>
<td>$35.5</td>
<td>2</td>
<td>$70</td>
</tr>
<tr align="center"><td>XML Bible</td>
<td>$40.5</td>
<td>1</td>
<td>$40.5</td>
</tr>
<tr align="right"><th colspan="4">Total amount -$110</th>
</table>
</body>
</html>
<html>
<head>
<title>csit books</title>
</head>
<body bgcolor="skyblue">
<h3 align="center">Computer Science & IT Books</h3>
<table width="100%">
<tr><td><img src="xml.jpg"></td>
<td>Book: Mobile Computing<br>
Author: Winston<br>
Publication: Wiely
</td>
<td>$ 40.5</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="html.jpg"></td>
<td>Book : Computer Networks<br>
Author : Sam Peter<br>
Publication : Sam publication
</td>
<td>$ 50</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="ai.jpg"></td>
<td>Book : Computer Communications<br>
Author : S.Russel<br>
Publication : Princeton hall
</td>
<td>$ 63</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="java.jpg"></td>
<td>Book : Web Design<br>
Author : Watson<br>
Publication : BPB publications
</td>
<td>$ 35.5</td>
<td><img src="cartbutton.jpg"></td>
</tr>
</body>
</html>
<html>
<head>
<title>eee books</title>
</head>
<body bgcolor="skyblue">
<h3 align="center">Electrical and Electronics Eng. Books</h3>
<table width="100%">
<tr><td><img src="xml.jpg"></td>
<td>Book: Machines<br>
Author: Winston<br>
Publication: Wiely
</td>
<td>$ 40.5</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="html.jpg"></td>
<td>Book : Power Electronics<br>
Author : Sam Peter<br>
Publication : Sam publication
</td>
<td>$ 50</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="ai.jpg"></td>
<td>Book : Transmision Systems<br>
Author : S.Russel<br>
Publication : Princeton hall
</td>
<td>$ 63</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="java.jpg"></td>
<td>Book : Network Theory<br>
Author : Watson<br>
Publication : BPB publications
</td>
<td>$ 35.5</td>
<td><img src="cartbutton.jpg"></td>
</tr>
</body>
</html>
<html>
<head>
<title>ece books</title>
</head>
<body bgcolor="skyblue">
<h3 align="center">Electronics & Communtion Eng. Books</h3>
<table width="100%">
<tr><td><img src="xml.jpg"></td>
<td>Book: Micro Processor<br>
Author: Winston<br>
Publication: Wiely
</td>
<td>$ 40.5</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="html.jpg"></td>
<td>Book : Priciples of Communtion<br>
Author : Sam Peter<br>
Publication : Sam publication
</td>
<td>$ 50</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="ai.jpg"></td>
<td>Book : Digital Logic Design<br>
Author : S.Russel<br>
Publication : Princeton hall
</td>
<td>$ 63</td>
<td><img src="cartbutton.jpg"></td>
</tr>
<tr><td><img src="java.jpg"></td>
<td>Book : Signal Processing<br>
Author : Watson<br>
Publication : BPB publications
</td>
<td>$ 35.5</td>
<td><img src="cartbutton.jpg"></td>
</tr>
</body>
</html>
Output:
WEEK 3:
VALIDATION:
1. Name (Name should contains alphabets and the length should not be less
than 6 characters).
2. Password (Password should not be less than 6 characters length).
3. E-mail id (should not contain any invalid and must follow the standard pattern
[email protected])
4. Phone number (Phone number should contain 10 digits only).
Create a file in notepad and save with “registration.html” which contains javascript code
to validate the name,password,e-mail and phone number entered in registration page.
<html>
<head>
<title>login form</title>
<script language="javascript">
function validate()
{
name=document.forms[0].elements[0].value;
pwd=document.forms[0].elements[1].value;
name_re=new RegExp("^[A-Za-z][a-zA-Z .]+$","g");
pwd_re=new RegExp("^[0-9a-zA-Z]+$","g");
if(name.match(name_re))
{
if(pwd.match(pwd_re))
{
alert("login successful");
}
else
{
alert(" invalid password");
document.forms[0].elements[1].select();
}
}
els
e
{
alert("invalid user name");
document.forms[0].elements[0].select();
}
}
</script>
</head>
<body bgcolor="#abcdef">
<h3 align="center">login into the site</h3>
<form method="post">
<table align="center">
<tr><td>name</td><td><input type="text"
name="uname"></td></tr>
<tr><td>password</td><td><input type="password"
name="pass"></td></tr>
<tr align="center"><td><input type="submit" value=" login "
onClick="validate()"></td><td><input type="reset" value=" reset "></td></tr>
</table>
</form>
</body>
</html>
Crate a file in notepad and save with “login.html” , contains javascript code for
login form validation
<html>
<head>
<title>Registration form</title>
<script language="javascript">
function validate()
{
var flag=true;
var name=document.forms[0].elements[0].value;
var pwd=document.forms[0].elements[1].value;
var phno=document.forms[0].elements[2].value;
var email=document.forms[0].elements[3].value;
if(!name.match(name_re))
{
alert(" name contains only alphabets only");
flag=false;
document.forms[0].elements[0].select();
}
if(name.length<6)
{
flag=false;
alert("name should contain atleast 6 characters");
document.forms[0].elements[0].select();
}
if(!pwd.match(pwd_re))
{
flag=false;
alert(" password should contain alphanumerics only");
document.forms[0].elements[1].select();
}
if(pwd.length<6)
{
flag=false;
alert("password should contain atleast 6 characters");
document.forms[0].elements[1].select();
}
if(!phno.match(phno_re))
{
flag=false;
alert(" invalid phone number");
document.forms[0].elements[2].select();
}
if(phno.length<10)
{
flag=false;
alert("phone number should contain 10 digits ");
document.forms[0].elements[2].select();
}
if(!email.match(email_re))
{
flag=false;
alert(" invalid email");
document.forms[0].elements[3].select();
}
if(flag==true)
alert("registration is successful");
else
alert("registration is faild");
}
</script>
</head>
<body bgcolor="orange">
<h2 align="center">Registration from</h2>
<center>
<form name="regform" action="./RegServlet" method="post">
<table cellspacing="15">
<tr><td>NAME</td><td><input type="text" name="name" size="25"></td></tr>
<tr><td>PASSWORD</td><td><input type="password" name="pass" size="25">
</td></tr>
<tr><td>PHONE NUMBER</td><td><input type="text" maxLength="10" name="phno"
size="25"></td></tr>
<tr><td>E-MAIL</td><td><input type="text" name="email" size="25"> </td></tr>
<tr><td>GENDER</td><td>male <input type="radio" name="gender" value="male"
checked="checked"> female <input type="radio" name="gender"
value="female"></td></tr>
<tr><td>DATE OF BIRTH</td><td>day<select name="day"><option
value="1">1</option><option value="2">2</option></select>
month <select name="month"><option
value="jan">jan</option><option value="feb">feb</option></select>
year<select name="year"><option value="1990">1990</option><option
value="1991">1991</option></select> </td></tr>
<tr><td>LANGUAGES KNOWN</td><td>TELUGU <input
type="checkbox" name="telugu" value="telugu"><br>ENGLISH <input
type="checkbox" name="english" value="english"><br>HINDI
<input type="checkbox" name="hindi" value="hindi"></td></tr>
<tr><td>ADDRESS</td><td><textarea rows="3" cols="25" name="address"
wrap="soft"></textarea></td></tr>
</table>
<br><br>
<input type="button" align="center" value="send" onClick="validate()"> <input
type="reset" align="center" value="cancel">
</form>
</center>
</body>
</html>
Output:
Week-4:
Designing a web page using CSS (Cascading Style Sheets) which includes the
following:
PROGRAM NO:4(a)
Create file in notepad and save with “fonts.html”
<html>
<head>
<link rel="stylesheet" type="text/css" href="test1.css">
</head>
<body>
<h1>This header is red</h1>
<h2>This header is blue</h2>
<p> This text is normal</p>
</body>
</html>
h1{color:red;font-size:22px;font-family:arial;text-decoration:underline}
h2{color:blue;font-size:16px}
p{font-family:arial;font-size:30px}
PROGRAM NO:4(b)
<html>
<head>
<style type="text/css">
body{ background-image:url("flower.jpg");
background-repeat:no-repeat; }
</style>
</head>
<body>
<center>
<h1>Life is beautiful!!!</h1>
<h2>Strength is live</h2>
<h2>weakness is death</h2>
</center>
</body>
</html>
PROGRAM NO:4(c)
<html>
<head>
<style type="text/css">
body{ background-image:url("flower1.jpg");
background-repeat:repeat;
}
h1{ color:green;
font-size:35px;
}
</style>
</head>
<body>
<center>
<h1>Life is beautiful!!!</h1>
<h2>Strength is live</h2>
<h2>weakness is death</h2>
</center>
</body>
</html>
PROGRAM NO:4(d)
<html>
<head>
<link rel="stylesheet" type="text/css" href="test4.css" media="screen">
</head>
<body>
<h1>This style sheet is for links</h1>
<p>You can experiment with the following link</p>
<p><a href="http://www.google.co.in">This is a link</a></p>
</body>
</html>
body{ background-color:"#abccba"}
h1{ color:black;font-size:22pt}
p{font-size:12pt;margin-left:15px}
a:link{color:blue}
a:visited{color:purple}
a:hover{color:red;text-decoration:underline}
a:active{color;green}
PROGRAM NO:4(e)
<html>
<head>
<title>Layers Demo</title>
</head>
<body>
<div style="position:relative;font-size:50px;left:50;top:10;background-
color:red;z-index:1 width:20; height:60" >layer1</div>
<div style="position:relative;font-size:50px;left:150;top:3;background-
color:green;z-index:2">layer2</div>
<div style="position:relative;font-size:25px;left:200;top:-5;background-
color:blue;z-index:3">layer1</div>
</body>
</html>
PROGRAM NO:4(e)
Create file in notepad and save with “cursors.html”
<html>
<head>
<title> customized cursor</title>
<style>
.alink{cursor:auto}
.xlink{cursor:crosshair}
.dlink{cursor:default}
.rslink{cursor:e-resize}
.hlink{cursor:help}
.mlink{cursor:move}
.nrlink{cursor:n-resize}
.nelink{cursor:ne-resize}
.nwlink{cursor:nw-resize}
.plink{cursor:pointer}
.proglink{cursor:progress}
.slink{cursor:s-resize}
.selink{cursor:se-resize}
.swlink{cursor:sw-resize}
.tlink{cursor:text}
.wlink{cursor:w-resize}
.waitlink{cursor:wait}
</style>
<body>
<p>Mouse over the words to change the cursor.</p>
<span class="alink">auto</span><br />
<span class="xlink">crosshair</span><br />
<span class="dlink">default</span><br />
<span class="rslink">e-resize</span><br />
<span class="hlink">help</span><br />
<span class="mlink">move</span><br />
<span class="nrlink">n-resize</span><br />
<span class="nelink">ne-resize</span><br />
<span class="nwlink">nw-resize</span><br />
<span class="plink">pointer</span><br />
<span class="proglink">progress</span><br />
<span class="slink">s-resize</span><br />
<span class="selink">se-resize</span><br />
<span class="swlink">sw-resize</span><br />
<span class="tlink">text</span><br />
<span class="wlink">w-resize</span><br />
<span class="waitlink">wait</span><br />
</body>
</html>
Output:
Week-5:
A. An XML file which will display the Book information which includes the following:
The contents should be displayed in a table. The header of the table should be in
color GREY. And the Author names column should be displayed in one color and
should be capitalized and in bold. Use your own colors for remaining columns.
Usage of XML schemas XSL and CSS for the above purpose.
5(A) Create file in notepad which contains schema definition for the XML file and save
with “catalogue.dtd”
Create file in notepad which contains the styles for the tags in XML file and save
with “library.css”
Catalog
{
font-family:arial;
color:red;
font-size:16pt
}
Book
{
display:block;
font-family:"times new Roman";
font-color:blue;
table-layout:auto;
font-size:14pt
}
Title
{
font-family:arial;
color:blue;
font-size:14pt
}
Autho
r font-family:arial;
{ color:red;
}
Publication,Edition,ISBN,Price
{
disp
lay:
bloc
k;
font
-
fam
ily:
aria
l;
colo
r:m
aro
on;
font
-
size
:10
pt;
mar
gin-
left:
20p
t;
}
Create an XML file which contain information about books and save with
“
c
a
t
a
l
o
g
.
x
m
l
”
5(B) Create file in notepad which contains the style sheet format for XML file, save
with “catalog_xsl.xsl”
VISUAL BEANS:
Create a simple visual bean with a area filled with a color.The shape of the area depends
on the property shape. If it is set to true then the shape of the area is Square and it is
Circle, if it is false. The color of the area should be changed dynamically for every mouse
click. The color should also be changed if we change the color in the “property window “.
This command creates the file colors.jar and places it in the directory
c:\bdk\jars.
6. Start the BDK
Change to the directory c:\bdk\beanbox> and type run. This causes the
BDK to start. You should see three windows, titled ToolBox, BeanBox, and
Properties. The ToolBox window should include an entry labeled “Colors”
for your new Bean.
Create an instance of the OurButton Bean in the BeanBox window. Then follow these
steps:
1. Go to the Properties window and change the label of the Bean to “Change”.You
should see that the button appearance changes immediately when this property is
changed.
2. Go to the menu bar of the BeanBox and select Edit | Events | action
|actionPerformed.
3. Move the cursor so that it is inside the Colors Bean display area, and click the
left mouse button. You should see the Event Target Dialog dialog box.
4. The dialog box allows you to choose a method that should be invoked when this
button is clicked. Select the entry labeled “change” and click the OK button. You
should see a message box appear very briefly, stating that the tool is “Generating
and compiling adaptor class.”
While installing tomcat server on your PC you can either make use of Windows Installer
or you can download the package from using zip or tar files.
If you click on window installer then this program will automatically install tomcat web
server on your computer. When you start installation using this windows installer
program initially following window will appear.
click the Next button and the following screen will appear
you have to accept the terms by clicking the I Agree button
Just click Next button and the next window will appear on which the installation
directory can be chosen. If we want to change the default path you can click the browse
button and can change it. In this a folder created with the name Tomcat 5.5 on the C
drive and in that folder Tomcat server installed.
Then click the Next button and you will get the Configuration window. Here you can set
the connector port. By default the port is 8080 for Apache Tomcat Server. You can
change to any other value except the first 1024 values (The first 1024 port numbers are
reserved )
we can also set the user name and password for administration login. The click the Next
button
It will ask to select the JRE 5.0 path installed on our system.
After selecting the path click Install button ,then installation will start
At the end click the Finish button and the installation procedure gets completed.
After installing this software we need to configure it with the help of environment
variables. The configuration of Tomcat can be done using the following steps.
Step 1: First set the user environment variable JAVA_HOME. For that go to control
panel System Advanced tab. Click the Environment variables and set the
JAVA_HOME=C:\jdk1.5.0_15 (select the jdk home directory installed on the system)
step 2: Then set the environment variable for CATALINA_HOME as the Tomcat’s
directory. This environment variable is needed to start the Tomcat server.
Now you can start the Tomcat server by clicking the startup.bat batch file in the
C:\Tomcat 5.5\bin Directory or by giving the command at the command prompt as
follows.
After extracting the binary distribution in the Tomcat 5.5 directory, we must set the
environment variable in the same way as in Method 1.
Now after starting up the Tomcat we must open the command prompt window and must
give the following commands.
After starting the Tomcat server the following window will appear on your compute
By default the tomcat server gets installed on the port 8080 but we can change the port
number. For instance if we want to change this port from 8080 to 4040 then we must go
to the directory C:\Tomcat 5.5\conf. Then there is an XML file named server.xml. For
editing this open this file it in Notepad.
For stopping the Tomcat web server just press Control+c keys. Or type the
shutdown.bat command in command prompt.
Testing Tomcat
To test the Tomcat web server we should open some web browser and enter this URL in
the address filed http://localhost:4040
Note that the by default the server name is localhost and we have set the port
4040(default port number is 8080). Following page gets displayed.
Installation of Apache web server on port 8080
Apache web server is an open source product and it is available on the internet. Get it
download from the site http://httpd.apache.org/download.cgi
Get the zip file with MSI installer (no_ssl) for downloading it on windows. Unzip it and
the installation procedure will start by appearing following window.
It will prompt for License Agreement. Just click on I accept .. and click Next button.
Click the next button
Then click the Install button. Finally you will get the installation complete message.
Hello Servlet Program
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
response.setContentType("text/html"); PrintWriter
out = response.getWriter();
out.print("<h2>Hello</h2> message from servlet");
out.close();
}
}
Create a program in notepad and save with “web.xml”
1. Create a Cookie and add these four user id’s and passwords to this
Cookie.
<html>
<head>
<title>login.html</title>
</head>
<body>
<form action="./getcookieservlet " method="post">
<table>
<tr><td>name</td><td><input type="text" name="uname"></td></tr>
<tr><td>password</td><td><input type="password" name="pass"></td></tr>
<tr align="center"><td><input type="submit" value=" submit “></td><td><input
type="reset" value=" reset "></td></tr>
</table>
</form>
</body>
</html>
Create a file in notepad and save with “CookieServlet.java”
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CookieServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Cookie c1=new Cookie("user1","pass1");
Cookie c2=new Cookie("user2","pass2");
Cookie c3=new Cookie("user3","pass3");
Cookie c4=new Cookie("user4","pass4");
response.addCookie(c1);
response.addCookie(c2);
response.addCookie(c3);
response.addCookie(c4);
out.println("cookies are added");
out.close();
}
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import javax.servlet.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String name,pass;
name=request.getParameter("uname").trim();
pass=request.getParameter("pass").trim();
if(p.containsKey(name))
{
if(pass.equals(p.getProperty(name)))
{
out.println("login successful<br>");
out.println("welcome <font color='green'
size='15'>"+name+"</font>");
}
else
out.print("invalid password");
}
else
out.println("invalid username");
out.close();
}
}
Create a file in notepad and save with “login.html”
<html>
<head>
<title>login.html</title>
</head>
<body>
<form action="./UA" method="post">
<table>
<tr><td>name</td><td><input type="text" name="uname"></td></tr>
<tr><td>password</td><td><input type="password" name="pass"></td></tr>
<tr align="center"><td><input type="submit" value=" submit “></td><td><input
type="reset" value=" reset "></td></tr>
</table>
</form>
</body>
</html>
import java.io.*;
import java.sql.*;
public class jdbctest
{
public static void main(String[] args) throws Exception
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
conn=DriverManager.getConnection("jdbc:oracle:oci:@XE","system","manager");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select *from student");
System.out.println("rno \t name \t percentage(%)\n");
while(rs.next())
{ System.out.println(rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getDo
uble(3));
}
}
Output:
Week-9:
<html>
<head>
<title>registration.html</title>
</head>
<body>
<h2 align="center">Registration from</h2>
<center>
<form name="regform" action="./regservlet" method="post">
<table cellspacing="15">
<tr><td>NAME</td><td><input type="text" name="name" size="25"></td></tr>
<tr><td>PASSWORD</td><td><input type="password" name="pass" size="25">
</td></tr>
<tr><td>PHONE NUMBER</td><td><input type="text" maxLength="10" name="phno"
size="25"></td></tr>
<tr><td>E-MAIL</td><td><input type="text" name="emai" size="25"> </td></tr>
<tr><td>GENDER</td><td>male <input type="radio" name="gender" value="male"
checked="checked"> female <input type="radio" name="gender"
value="female"></td></tr>
<tr><td>DATE OF BIRTH</td><td>day<select name="day"><option
value="1">1</option><option value="2">2</option></select>
month <select name="month"><option
value="jan">jan</option><option value="feb">feb</option></select>
year<select name="year"><option value="1990">1990</option><option
value="1991">1991</option></select> </td></tr>
<tr><td>LANGUAGES KNOWN</td><td>TELUGU <input
type="checkbox" name="telugu" value="telugu"><br>ENGLISH <input
type="checkbox" name="english" value="english"><br>HINDI
<input type="checkbox" name="hindi" value="hindi"> </td></tr>
<tr><td>ADDRESS</td><td><textarea rows="3" cols="25" name="address"
wrap="soft"></textarea></td></tr>
</table>
<br><br>
<input type="submit" align="center" value="send"> <input type="reset"
align="center" value="cancel">
</form>
</center>
</body>
</html>
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Connection conn=null;
Statement stmt=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
Class.forName("oracle.jdbc.driver.OracleDriver");
conn=DriverManager.getConnection("jdbc:oracle:oci:@XE","system","manager");
stmt=conn.createStatement();
pstmt=conn.prepareStatement("INSERT INTO REGISTRATION
VALUES(?,?,?,?,?,?,?,?,?)");
}
catch(Exception e)
{ System.out.println("error:"+e.toString()
);
}
response.setContentType("text/html");
PrintWriter out = response.getWriter();
try{
conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
conn.setAutoCommit(false);
rs=stmt.executeQuery("SELECT MAX(REGID) FROM REGISTRATION");
int regid;
if(rs.next()){
regid=rs.getInt(1);
}
else{
regid=0;
}
regid++; pstmt.setInt(1,regid);
pstmt.setString(2,request.getParameter("name").trim());
pstmt.setString(3,request.getParameter("pass").trim());
pstmt.setString(4,request.getParameter("phno").trim());
pstmt.setString(5,request.getParameter("email").trim());
pstmt.setString(6,request.getParameter("gender").trim());
String dob;
dob=request.getParameter("day")+"/"+request.getParameter("month")+"/"+request.get
Parameter("year");
String languages;
languages=request.getParameter("telugu")+","+request.getParameter("english")+","+re
quest.getParameter("hindi");
pstmt.setString(7,dob); pstmt.setString(8,languages);
pstmt.setString(9,request.getParameter("address").trim());
int i=pstmt.executeUpdate();
if(i==1)
{
conn.commit();
out.println("Registration is successful </br> your regid is " );
out.println("<font color='green' size='4'>"+regid+"</font>");
}
else{ conn.rollback();
out.println("<h2 color='red'>registration is fail</h2>");
}
}
catch(Exception e){
out.println(e);
}
out.close();
}
Output:
The URL is http://localhost:8080/usebean_page.jsp
Week-10:
<html>
<head>
<title>registration.html</title>
</head>
<body>
<h2 align="center">Registration from</h2>
<center>
<form name="regform" action="./registration.jsp" method="post">
<table cellspacing="15">
<tr><td>NAME</td><td><input type="text" name="name" size="25"></td></tr>
<tr><td>PASSWORD</td><td><input type="password" name="pass" size="25">
</td></tr>
<tr><td>PHONE NUMBER</td><td><input type="text" maxLength="10" name="phno"
size="25"></td></tr>
<tr><td>E-MAIL</td><td><input type="text" name="email" size="25"> </td></tr>
<tr><td>GENDER</td><td>male <input type="radio" name="gender" value="male"
checked="checked"> female <input type="radio" name="gender"
value="female"></td></tr>
<tr><td>DATE OF BIRTH</td><td>day<select name="day"><option
value="1">1</option><option value="2">2</option></select>
month <select name="month"><option
value="jan">jan</option><option value="feb">feb</option></select>
year<select name="year"><option value="1990">1990</option><option
value="1991">1991</option></select> </td></tr>
<tr><td>LANGUAGES KNOWN</td><td>TELUGU <input
type="checkbox" name="telugu" value="telugu"><br>ENGLISH <input
type="checkbox" name="english" value="english"><br>HINDI
<input type="checkbox" name="hindi" value="hindi"> </td></tr>
<tr><td>ADDRESS</td><td><textarea rows="3" cols="25" name="address"
wrap="soft"></textarea></td></tr>
</table>
<br><br>
<input type="submit" align="center" value="send"> <input type="reset"
align="center" value="cancel">
</form>
</center>
</body>
</html>
try{ Class.forName("oracle.jdbc.driver.OracleDriv
er");
Connection
conn=DriverManager.getConnection("jdbc:oracle:oci:@XE","system","manager");
Statement stmt=conn.createStatement();
PreparedStatement pstmt=conn.prepareStatement("INSERT INTO REGISTRATION1
VALUES(?,?,?,?)");
pstmt.setString(1,name);
pstmt.setString(2,pass);
pstmt.setString(3,phno);
pstmt.setString(4,email);
i=pstmt.executeUpdate();
pstmt.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
out.println(e.toString());
}
%>
<html>
<body>
<% if(i==1)
out.println("<h3 color='green'>Registation is successful</h3>");
else
out.println("<h3 color='red'>Registration fail</h3>"); %>
</body>
</html>
Class.forName("oracle.jdbc.driver.OracleDriver"); Connection
conn=DriverManager.getConnection("jdbc:oracle:oci:@XE","system","manager");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("SELECT name,pass FROM REGISTRATION1");
while(rs.next()){
if(name.equals(rs.getString("name"))&&pass.equals(rs.getString("pass")))
{
valid=true;
break;
}
}
rs.close();
stmt.close();
conn.close();
}
catch(Exception e){
out.println(e.toString());
}
%>
<html>
<body>
<% if(valid){ %>
<h2 color="yellow">login sucessfull</h2><br>
<h3><% out.println("welcome user <font color='green'>"+name+"</font>");%>
<%}else{ %>
<h2 color="yellow">login fail invalid username/password</h2>
try again <a href="http://localhost:8080/week10/login.html">click here</a>
<%} %>
</body>
</html>
Output:
Create tables in the database which contain the details of items (books in our
case like Book name , Price, Quantity, Amount )) of each category. Modify your
catalogue page (week 2)in such a way that you should connect to the database
and extract data from the tables and display them in the catalogue page using
JDBC.
%>
<table bgcolor="#00ff00" align="center" border="2" width="75%">
<tr><td>NAME</td><td>AUTHOR</td><td>PUBLICATION</td><td>PRICE</td>
<% while(rs.next()){ %>
<tr bgcolor="#123456"><td><%=rs.getString(1) %></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3) %></td>
<td><%=rs.getString(4) %></td>
<% } %>
</table>
<% rs.close();
stmt.close();
conn.close();
}// end of try
catch(Exception e)
{ out.println(e.toString()
);
} %>
</body>
</html>
%>
<table bgcolor="#00ff00" align="center" border="2" width="75%">
<tr><td>NAME</td><td>AUTHOR</td><td>PUBLICATION</td><td>PRICE</td>
<% while(rs.next()){ %>
<tr bgcolor="#acffdb"><td><%=rs.getString(1) %></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3) %></td>
<td><%=rs.getString(4) %></td>
<% } %>
</table>
<% rs.close();
stmt.close();
conn.close();
}// end of try
catch(Exception e){
out.println(e.toString());
} %>
</body>
</html>
Create the file and save with “ eeebooks.jsp”
%>
<table bgcolor="#00ff00" align="center" border="2" width="75%">
<tr><td>NAME</td><td>AUTHOR</td><td>PUBLICATION</td><td>PRICE</td>
<% while(rs.next()){ %>
<tr bgcolor="#acffdb"><td><%=rs.getString(1) %></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3) %></td>
<td><%=rs.getString(4) %></td>
<% } %>
</table>
<% rs.close();
stmt.close();
conn.close();
}// end of try
catch(Exception e){
out.println(e.toString());
} %>
</body>
</html>
%>
<table bgcolor="#00ff00" align="center" border="2" width="75%">
<tr><td>NAME</td><td>AUTHOR</td><td>PUBLICATION</td><td>PRICE</td>
<% while(rs.next()){ %>
<tr bgcolor="#acffdb"><td><%=rs.getString(1) %></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3) %></td>
<td><%=rs.getString(4) %></td>
<% } %>
</table>
<% rs.close();
stmt.close();
conn.close();
}// end of try
catch(Exception e)
{ out.println(e.toString()
);
} %>
</body>
</html>
Output:
<html>
<head><title>home</title>
</head>
<body>
<form action="./dateservlet" method="get">
<input type="submit" value="click">
</form>
</body>
</html>
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DateServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{ HttpSession hs =
request.getSession(true);
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.print("<B>");
// Display date/time of last access.
Date date = (Date)hs.getAttribute("date");
if(date != null) {
pw.print("Last access: " + date + "<br>");
}
// Display current date/time.
date = new Date();
hs.setAttribute("date", date);
pw.println("Current date: " + date);
}
}
<html>
<head>
<title>JSP 2.0 Expression Language - Basic Arithmetic</title>
</head>
<body>
<h1>JSP 2.0 Expression Language - Basic Arithmetic</h1>
<hr>
This example illustrates basic Expression Language arithmetic.
Addition (+), subtraction (-), multiplication (*), division (/ or div),
and modulus (% or mod) are all supported. Error conditions, like
division by zero, are handled gracefully.
<br>
<blockquote>
<code>
<table border="1">
<thead>
<td><b>EL Expression</b></td>
<td><b>Result</b></td>
</thead>
<tr>
<td>\${1}</td>
<td>${1}</td>
</tr>
<tr>
<td>\${1 + 2}</td>
<td>${1 + 2}</td>
</tr>
<tr>
<td>\${1.2 + 2.3}</td>
<td>${1.2 + 2.3}</td>
</tr>
<tr>
<td>\${1.2E4 + 1.4}</td>
<td>${1.2E4 + 1.4}</td>
</tr>
<tr>
<td>\${-4 - 2}</td>
<td>${-4 - 2}</td>
</tr>
<tr>
<td>\${21 * 2}</td>
<td>${21 * 2}</td>
</tr>
<tr>
<td>\${3/4}</td>
<td>${3/4}</td>
</tr>
<tr>
<td>\${3 div 4}</td>
<td>${3 div 4}</td>
</tr>
<tr>
<td>\${3/0}</td>
<td>${3/0}</td>
</tr>
<tr>
<td>\${10%4}</td>
<td>${10%4}</td>
</tr>
<tr>
<td>\${10 mod 4}</td>
<td>${10 mod 4}</td>
</tr>
<tr>
<td>\${(1==2) ? 3 : 4}</td>
<td>${(1==2) ? 3 : 4}</td>
</tr>
</table>
</code>
</blockquote>
</body>
</html>
OUTPUT:
EL Expression Result
${1} 1
${1 + 2} 3
${-4 - 2} -6
${21 * 2} 42
${3/4} 0.75
${3/0} Infinity
${10%4} 2
${10 mod 4} 2
${(1==2) ? 3 : 4} 4
WEEK 12:
WRITE A JAVASCRIPT SCRIPT FOR SELECTION SORT.
PROGRAM
<html>
<head>
<title> Sort</title>
<script language="Javascript">
var b,i,j,temp;
var a;
a=[];
document.write("Enter array");
for(i=0;i<5;i++)
{
b=prompt("enter array element=","0");
a[i]=parseInt(b);
}
for(i=0;i<5;i++)
{
document.write("<br>"+a[i]);
}
document.write("<br>Sorted array is");
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(a[i]<a[j])
{
temp=a[i]; a[i]=a[j]; a[j]=temp;
} } }
for(i=0;i<5;i++)
{
document.write("<br>"+a[i]);
}
</script> </head></html>
OUTPUT
Enter array 4 2 5
Sorted array is 2 4 5