jwt lab manual for m.tech final

52
 1) 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. Home page, Registration and user Login, User profile page, Books catalog, Shopping cart, Payment By credit card, order confirmation.  HOME PAGE: The static home page must con tain three frames. Top frame: Logo and the college name and links to Home page, Login page, Registration page, Catalogue page and Cart page (the description of these pages will be given below). Left frame: At least four links for navigation, which will display the catalogue of respective links. For e.g.: When you click the link “CSE” the catalogue for CSE Books should be displayed in the Right frame. Right frame: The pages to the links in the left frame must be loaded here . Initially this page contains description of the web site. HomePage.html <html> <head> <title> Online Book Store</title> <frameset rows="20%,*%" scrolling="no"> <frame name="tframe" src="Title.html"> <frameset cols=20%,80%"> <frame name="tframe" src="Links.html"> <frame name="rframe" src="Home.html"> </frameset> </frameset> </head> <body> </body></html>

Upload: prashanth-kumar

Post on 03-Apr-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 1/52

 

1) 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. Home page, Registration and

user Login, User profile page, Books catalog, Shopping cart, Payment By credit card, order

confirmation. 

HOME PAGE:

The static home page must contain three frames.

Top frame: Logo and the college name and links to Home page, Login page, Registration page,

Catalogue page and Cart page (the description of these pages will be given below).

Left frame: At least four links for navigation, which will display the catalogue of respective

links. For e.g.: When you click the link “CSE” the catalogue for CSE Books should be displayed

in the Right frame.

Right frame: The pages to the links in the left frame must be loaded here. Initially this page

contains description of the web site.

HomePage.html

<html>

<head>

<title> Online Book Store</title>

<frameset rows="20%,*%" scrolling="no">

<frame name="tframe" src="Title.html">

<frameset cols=20%,80%">

<frame name="tframe" src="Links.html">

<frame name="rframe" src="Home.html">

</frameset>

</frameset>

</head>

<body>

</body></html>

Page 2: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 2/52

 

OutPut:

LOGIN PAGE:

LoginPage.html

<html>

<head>

<title> Online Book Store</title>

</head>

<body bgcolor="pink">

<center>

Page 3: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 3/52

 

<h1>LOGIN</h1>

<form action="account.html">

<table border="0">

<tr>

<h3><td>Username:</td>

<td><input type="text" value="" name="t1"></td></h3>

</tr>

<tr>

<h3><td>Password:</td>

<td><input type="password" name="p1"></td></h3>

</tr>

<tr>

<td></td>

<td><input type="submit" value="Sign In">

<input type="submit" value="Reset"></td>

</tr>

</table>

</form>

</center>

</body>

</html>

Page 4: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 4/52

 

OutPut:

CATOLOGUE PAGE: 

The catalogue page should contain the details of all the books available in the web site in a

table.

The details should contain the following:

1. Snap shot of Cover Page.

2. Author Name.

3. Publisher.

4. Price.

5. Add to cart button.

Page 5: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 5/52

 

Catologue.html

<html>

<head>

<title>Online Book Store</title>

</head>

<body bgcolor="pink">

<h1>Books</h1>

<ul type="square" compact>

<li>C</li>

<li>C++</li>

<li>Java</li>

<li>DBMS</li>

<li>UNIX</li>

<li>WT</li>

</ul>

</body>

</html>

Page 6: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 6/52

 

OutPut:

Page 7: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 7/52

 

REGISTRATION PAGE:

Create a “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)

RegistrationPage.html

<html>

<head>

<title> Online Book Store</title>

</head>

<body bgcolor="pink">

<center>

<h1>REGISTRATION</h1>

<table border="3">

<tr>

<h3><td>Name:</td>

<td><input type="text"></td>

</tr>

<tr>

<td>Password:</td>

Page 8: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 8/52

 

<td><input type="password"></td>

</tr>

<tr>

<td>Sex:</td>

<td><input type="radio" name="r1">Male

<input type="radio" name="r1">Female</td>

</tr>

<tr>

<td>Email ID:</td>

<td><input type="text"></td>

</tr>

<tr>

<td>Phone no:</td>

<td><input type="text"></td>

</tr>

<tr>

<td>Address:</td>

<td> <textarea name ="string"></textarea></td>

</tr>

<tr>

<td><input type="submit" value="Sign In">

<input type="reset" value="Reset"></td>

</tr>

</table>

</center>

</body>

</html>

Page 9: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 9/52

 

OutPut:

PAYMENT PAGE:

PaymentPage.html

<html>

<head>

<title> Online Book Store</title>

</head>

<body bgcolor="pink">

<center>

<h1>Card Information</h1>

<table border="2">

Page 10: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 10/52

 

<tr>

<h3><td>Select Card Type:</td>

<td><select name=" " size="1">

<option value="type" selected>None</opiton>

<option value="credit card">Credit Card</opiton>

<option value="master card">Master Card</opiton>

<option value="debit card">Debit Card</opiton>

</select>

</td>

</tr>

<tr>

<td>Enter card no:</td>

<td><input type=""></td>

</tr>

<tr>

<td>Name on card:</td>

<td><input type="text"></td>

</tr>

<tr>

<td></td>

<td><input type="submit" value="Sign In">

<input type="reset" value="Reset"></td>

</tr>

</table>

</center>

</body>

</html>

Page 11: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 11/52

 

OutPut:

Page 12: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 12/52

 

2. VALIDATION:Write JavaScript to validate the following fields of the above registration page.

1. Name (Name should contains alphabets and the length >=6 characters).

2. Password (Password should not be less than 6 characters length).3. E-mail id (Only valid format :[email protected])

4. Phone number (Phone number should contain 10 digits only).

Registration validation.html: 

Source code:

<html><head>

<title> Welcome to AMAZON website</title>

<link rel="stylesheet" href="style.css" type="text/css"><script type="text/javascript" src="validation.js">

</script>

</head><body>

<center>

<h3>Registration Form </h3>

<br/><form name="f1" onsubmit="return form1_validation()">

<table cellpadding="1" align="center" >

<tr>

<td> Name:*</td><td> <input type="text" name="username"></td></tr>

<tr>

<td>Choose a ID:*</td><td> <input type="text" name="id"></td></tr>

<tr>

<td>Choose a Password:*</td><td> <input type="password" name="password"></td></tr>

<tr>

<td>Reenter Password:*</td>

<td> <input type="password" name="password1"></td></tr>

<tr>

<td>Email ID:*</td>

<td> <input type="text" name="email"></td></tr><tr>

<td>Phone Number:*</td>

<td> <input type="text" name="phno"></td></tr><tr>

Page 13: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 13/52

 

<td valign="top">Gender:*</td><td> <input type="radio" name="radio" value="1">Male<br>

<input type="radio" name="radio" value="2">Female</td></tr>

<tr><td>Date of Birth:*</td>

<td>dd:

<select name=dd >

<option> </option><script type="text/javascript">

for(i=1;i<=31;i++)

document.write("<option value=i>"+i+"</option>");

</script></select>

mm:

<select name=mm><option> </option>

<script type="text/javascript">

for(i=1;i<=12;i++)document.write("<option value=i>"+i+"</option>");

</script>

</select>

yyyy:<select name=yyyy>

<option> </option>

<script type="text/javascript">

for(i=1880;i<=2008;i++)document.write("<option value=i>"+i+"</option>");

</script>

</select></td></tr>

<tr>

<td>Material Status:*</th><td><input type="text" name="mstatus" ></td></tr>

<tr>

<td>Natinality:*</th>

<td><input type="text" name="Nationality" ></td></tr>

<tr> <td valign="top">Language Known:*</td>

<td> <input type="checkbox" name="checkbox" value="English">English<br>

<input type="checkbox" name="checkbox" value="Telugu">Telugu<br><input type="checkbox" name="checkbox" value="Hindi">Hindi<br>

<input type="checkbox" name="checkbox" value="Tamil">Tamil</td></tr>

<tr><td valign="top">Address:*</td>

Page 14: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 14/52

 

<td> <textarea name="address"></textarea></td><tr><td></td><td><input type="submit" value="Submit" hspace="10">

<input type="reset" value="Reset"></td></tr>

<tr><td colspan=2 >*<font color="#FF0000"> fields are mandatory</font ></td></tr>

</table>

</center>

</body></html>

Validation.js: 

Source code:

function form1_validation()

{

//Username Validationif(f1.username.value=="")

{

alert("You must enter a User Name");

f1.username.focus();return false;

}

if(f1.username.value.length<3)

{ alert("User Name must consist of atleast 3 character");

f1.username.focus();

return false;}

var checkStr=f1.username.value;

for(i=0;i<checkStr.length;i++)if(!(checkStr.charCodeAt(i)>=65&&checkStr.charCodeAt(i)<=91)

&& !(checkStr.charCodeAt(i)>=97 && checkStr.charCodeAt(i)<=122))

{

alert("Please enter valid User Name");

f1.username.focus();return false;

}

//Password Validationif(f1.password.value.length<6)

{

alert("Please enter Password not less than 6");f1.password.focus();

Page 15: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 15/52

 

return false;}

if(!(f1.password.value==f1.password1.value))

{alert("Please re-enter corrert Password");

f1.password1.focus();

return false;

}//email validation

flag=true;

if(f1.email.value=="")

flag=false;var Str=f1.email.value;

if(allValidChars(Str))

for(i=0;i<Str.length;i++)if(Str.charAt(i)=="@")

{

if((Str.substr(i+1,9)=="yahoo.com")||(Str.substr(i+1,9)=="gmail.com"))

{

flag=true;

 break;}

}

else

flag=false;if(!(flag))

{

alert("Please enter a valid Email ID");f1.email.focus();

return false;

}//phone number validation

flag=true;

if(f1.phno.value.length!=10)

flag=false;

var phno=f1.phno.value;for(i=0;i<phno.length;i++)

if(!(phno.charCodeAt(i)>=48&&phno.charCodeAt(i)<=57))

flag=false;if(!flag)

{

alert("Please enter valid Phone Number");f1.phno.focus();

Page 16: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 16/52

 

return false;}

//gender validation

flag=false;for(i=0;i<f1.radio.length;i++)

if(f1.radio[i].checked)

flag=true;

if(!(flag)){

alert("Please choose a Gender");

return false;

}//Date of birth validation

if((f1.dd.selectedIndex<=0)||(f1.mm.selectedIndex<=0)||(f1.yyyy.selectedIndex<=0))

{alert("Please choose a Date of Birth");

f1.phno.focus();

return false;}

//checkbox validation

flag=false;

for (i = 0; i < f1.checkbox.length; i++){

if (f1.checkbox[i].checked)

flag = true;

}if(!(flag))

{

alert("Please select at least one of the \"Language\" options.");return false;

}

//address validationif(f1.address.value.length<25)

{

alert("Please enter a Correct Address");

return false;

}}

function allValidChars(email)

{var validchars = "[email protected]_";

for (i=0; i < email.length; i++)

{var letter = email.charAt(i).toLowerCase();

Page 17: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 17/52

 

if (validchars.indexOf(letter) == -1)return false;

}

return true;}

Output: 

Page 18: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 18/52

 

3. Create and save an XML document at the server, which contains 10 users information.

Write a program which takes User Id as input and returns the user details by taking the

user information from the XML document

student.dtd:

<!ELEMENT student(rollnum,name,parntname,branch,year,addr,email,phno)>

<!ELEMENT roll_no(#PCDATA)>

<!ELEMENT name(first_name,last_name)>

<!ELEMENT first_name(#PCDATA)>

<!ELEMENT last_name(#PCDATA)>

<!ELEMENT father_name(fname,mname,lname)>

<!ELEMENT first_name(#PCDATA)>

<!ELEMENT last_name(#PCDATA)>

<!ELEMENT branch(#PCDATA)>

<!ELEMENT year(#PCDATA)>

<!ELEMENT address(door_no,street,city)>

<!ELEMENT door_no(#PCDATA)>

<!ELEMENT street(#PCDATA)>

<!ELEMENT city(#PCDATA)>

<!ELEMENT email(#PCDATA)>

<!ELEMENT phno(#PCDATA)>

student.xsd:

<xs:schema>

<xs:element name="student">

<xs:complextype>

<xs:sequence>

<xs:element name="roll_no" type="xs:string"/>

Page 19: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 19/52

 

<xs:element name="name">

<xs:complextype>

<xs:sequence>

<xs:element name="first_name" type="xs:string"/>

<xs:element name="last_name" type="xs:string"/>

</xs:sequence>

</xs:complextype>

</xs:element>

<xs:element name="father-name">

<xs:complextype>

<xs:sequence>

<xs:element name="first_name" type="xs:string"/>

<xs:element name="last_name" type="xs:string"/>

</xs:sequence>

</xs:complextype>

</xs:element>

<xs:element name="branch" type="xs:string"/>

<xs:element name="year" type="xs:integer"/>

<xs:element name="addr">

<xs:complextype>

<xs:sequence>

<xs:element name="door-no" type="xs:string"/>

<xs:element name="street" type="xs:string"/>

<xs:element name="city" type="xs:string"/>

</xs:sequence>

Page 20: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 20/52

 

</xs:complextype>

</xs:element>

<xs:element name="email" type="xs:string"/>

<xs:element name="phno" type="xs:integer"/>

</xs:sequence>

</xs:complextype>

</xs:element>

</xs:schema>

student.xml:

<?xml version="1.0" ?> 

- <student xmlns:xsi="xmlschema-instance" xsi:SchemaLocation="student.xsd"> 

<roll_no>08A01D2501</roll_no> 

- <name> 

<first_name>A</first_name> 

<Last_name>Aruna</Last_name> 

</name> 

- <father_name> 

<first_name>Venkateswara</first_name> 

<Last_name>Rao</Last_name> 

</father_name> 

< branch>software engineering</ branch> 

<year >1ST Year</year > 

- <address> 

<door-no>32-15/1-44</door-no> 

<street>B.R.Nagar-1</street> 

Page 21: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 21/52

 

<city>Hyderabad</city> 

</address> 

<email>[email protected]</email> 

< phno>9949643372</ phno> 

<roll_no>08A01D2501</roll_no> 

- <name> 

<first_name>Prathap</first_name> 

<Last_name>Rudra</Last_name> 

</name> 

- <father_name> 

<first_name>Venkateswara </first_name> 

<Last_name>B</Last_name> 

</father_name> 

< branch> software engineering (mtech) </ branch> 

<year >1st Year</year > 

- <address> 

<door-no>door no 603/n</door-no> 

<street>Recoloney</street> 

<city>Vijayawada</city> 

</address> 

<email>[email protected]</email> 

< phno>9866145423</ phno> 

<roll_no>08A01D2503</roll_no> 

- <name> 

<first_name>Ramesh</first_name> 

<Last_name>Kumar</Last_name> 

</name> 

Page 22: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 22/52

 

- <father_name> 

<first_name>Venkateswara</first_name> 

<Last_name>Rao</Last_name> 

</father_name> 

< branch> software engineering(mtech) </ branch> 

<year >1st

Year</year > 

- <address> 

<door-no>32-15/1-44</door-no> 

<street>B.R.Nagar-1</street> 

<city>Hyderabad</city> 

</address> 

<email>[email protected]</email> 

< phno>9985150379</ phno> 

<roll_no>08A01D2504</roll_no> 

- <name> 

<first_name>kishore</first_name> 

<Last_name>Galla</Last_name> 

</name> 

- <father_name> 

<first_name>Venkateswara</first_name> 

<Last_name>Rao</Last_name> 

</father_name> 

< branch> software engineering (mtech) </ branch> 

<year >1st Year</year > 

- <address> 

<door-no>32-15/1-44</door-no> 

<street>B.R.Nagar-1</street> 

Page 23: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 23/52

 

<city>hyderabad</city> 

</address> 

<email>[email protected]</email> 

< phno>990837394</ phno> 

<roll_no>08A01D2505</roll_no> 

- <name> 

<first_name>Madhu</first_name> 

<Last_name>Garlapati</Last_name> 

</name> 

- <father_name> 

<first_name>Venkateswara</first_name> 

<Last_name>Rao</Last_name> 

</father_name> 

< branch> software engineering (mtech) </ branch> 

<year >1st Year</year > 

- <address> 

<door-no>32-15/1-44</door-no> 

<street>B.R.Nagar-1</street> 

<city>Hyderabad</city> 

</address> 

<email>[email protected]</email> 

< phno>9908005778</ phno> 

</student> 

Page 24: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 24/52

 

4. Bean Assignments

a.  Create a JavaBeans which gives the exchange value of INR (Indian Rupees) into equivalent

American/Canadian/Australian Dollar value.

b.  Create a simple Bean with a label which is the count of number of clicks. Then create a

Bean info class such that only the count properly is visible in the property Window.

c.  Create two Beans – a) Keypad b) Display pad. After that integrate the two Beans to make it

work as a calculator. 

d.  Create two Beans Traffic Light(implemented as a label with only three background

colors-red, green, yellow) and Automobile(Implemented as a Text Box which states its

state/movement). The state of the Automobile should depend on the following Light

Transition table. 

Developing a Simple Bean Using the BDK:

This section presents an example that shows how to develop a simple Bean and connect it to

other components via the BDK. Our new component is called the Colors Bean. It appears as either a

rectangle or ellipse that is filled with a color. A color is chosen at random when the Bean begins

execution. A public method can be invoked to change it. Each time the mouse is clicked on the Bean,

another random color is chosen. There is one boolean read/write property that determines the shape. The

BDK is used to lay out an application with one instance of the Colors Bean and one instance of the

OurButton Bean. The button is labeled “Change.” Each time it is pressed, the colo r changes. 

DEVELOPMENT

USING JAVA

Create a New Bean

Here are the steps that you must follow to create a new Bean:

1. Create a directory for the new Bean.

2. Create the Java source file(s).

3. Compile the source file(s).

4. Create a manifest file.

5. Generate a JAR file.

6. Start the BDK.

7. Test.

Page 25: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 25/52

 

The following sections discuss each of these steps in detail.

Create a Directory for the New Bean You need to make a directory for the Bean. To follow along

with this example, create c:\bdk\demo\sunw\demo\colors. Then change to that directory. The Colors andOurButton Beans Create the Source File for the New Bean The source code for the Colors component is

shown in the following listing. It is located in the file Colors.java. The import statement at the beginning

of the file places it in the package named sunw.demo.colors. Recall from Chapter 9 that the directory

hierarchy corresponds to the package hierarchy. Therefore, this file must be located in a subdirectory

named sunw\demo\colors relative to the CLASSPATH environment variable. The color of the

component is determined by the private Color variable color, and its shape is determined by the private

boolean variable rectangular. The constructor defines an anonymous inner class that extends

MouseAdapter and overrides its mousePressed( ) method. The change( ) method is invoked in response

to mouse presses. The component is initialized to a rectangular shape of 200 by 100 pixels. The change( )

method is invoked to select a random color and repaint the component. The getRectangular( ) and

setRectangular( ) methods provide access to the one property of this Bean. The change( ) method callsrandomColor( ) to choose a color and then calls repaint( ) to make the change visible. Notice that the

paint( ) method uses the rectangular and color variables to determine how to present the Bean.

// A simple Bean.

 package sunw.demo.colors;

import java.awt.*;

import java.awt.event.*;

 public class Colors extends Canvas {

transient private Color color;

 private boolean rectangular;

 public Colors() {

addMouseListener(new MouseAdapter() {

 public void mousePressed(MouseEvent me) {

change();

}

});

rectangular = false;

Page 26: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 26/52

 

setSize(200, 100);

change();

}

 public boolean getRectangular() {

return rectangular;

}

 public void setRectangular(boolean flag) {

this.rectangular = flag;

repaint();

}

 public void change()

color = randomColor();

repaint();

}

 private Color randomColor() {

int r = (int)(255*Math.random());

int g = (int)(255*Math.random());

int b = (int)(255*Math.random());

return new Color(r, g, b);

}

 public void paint(Graphics g) {

Dimension d = getSize();

int h = d.height;

int w = d.width;

Page 27: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 27/52

 

g.setColor(color);

if(rectangular) {

g.fillRect(0, 0, w-1, h-1);

}

else {

g.fillOval(0, 0, w-1, h-1);

}

}

}

Compile the Source Code for the New Bean Compile the source code to create a class file. Type the

following:

 javac Colors.java.

Create a Manifest File You must now create a manifest file. First, switch to the c:\bdk\demo directory.

This is the directory in which the manifest files for the BDK demos are located. Put the source code for 

your manifest file in the file colors.mft.

It is shown here:

 Name: sunw/demo/colors/Colors.class

Java-Bean: True

This file indicates that there is one .class file in the JAR file and that it is a Java Bean Notice that the

Colors.class file is in the package sunw.demo.colors and in the subdirectory sunw\demo\colors relative

to the current directory. Generate a JAR File Beans are included in the ToolBox window of the BDK only

if they are in JAR files in the directory c:\bdk\jars. These files are generated with the jar utility.

Enter the following:

 jar cfm ..\jars\colors.jar colors.mft sunw\demo\colors\*.class

This command creates the file colors.jar and places it in the directory c:\bdk\jars.

(You may wish to put this in a batch file for future use.)

Page 28: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 28/52

 

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 Colors Bean After you

complete the preceding steps, create an instance of the Colors Bean in the BeanBox window. Test your new component by pressing the mouse anywhere within its borders. Its color immediately changes. Use

the Properties window to change the rectangular  property from false to true. Its shape immediately

changes.

Create and Configure an Instance of the OurButton 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 shou ld 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.” 

5. Click on the button. You should see the color change. You might want to experiment with the Colors

Bean a bit before moving on.

Output:

 

Page 29: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 29/52

 

d) Create two Beans Traffic Light(implemented as a label with only three background colors-red,green, yellow) and Automobile(Implemented as a Text Box which states its state/movement). Thestate of the Automobile should depend on the following Light Transition table.

/*<applet code="Sig.class" height=300 width=200></applet>*/

import java.awt.*;

import java.lang.String;

import java.awt.event.*;

import java.applet.Applet;

import java.applet.*;

 public class Sig extends Applet implements ItemListener{

 boolean c1,c2,c3;

String s1;

Checkbox r1,r2,r3;

CheckboxGroup cbg;

 public void init(){

cbg=new CheckboxGroup();

Panel p=new Panel();

 p.setLayout(new GridLayout());

add(r1=new Checkbox("red",cbg,false));

add(r2=new Checkbox("yellow",cbg,false));

add(r3=new Checkbox("green",cbg,false));

r1.addItemListener(this);

r2.addItemListener(this);

r3.addItemListener(this);

}

 public void paint(Graphics g) {

g.setColor(Color.red);

g.drawOval(10, 30, 20, 20);

//System.out.println(s1);

Page 30: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 30/52

 

g.setColor(Color.yellow);

g.drawOval(10, 60, 20, 20);

g.setColor(Color.green);

g.drawOval(10, 90, 20, 20);

s1=cbg.getSelectedCheckbox().getLabel();

if(s1=="red")

{

g.setColor(Color.red);

g.fillOval(10, 30, 20, 20);

}

else if(s1=="yellow")

{

g.setColor(Color.yellow);

g.fillOval(10, 60, 20, 20);

}

else if(s1=="green")

{

g.setColor(Color.green);

g.fillOval(10, 90, 20, 20);

}

}

 public void itemStateChanged(ItemEvent ie) {

repaint();

}}

Page 31: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 31/52

 

5) a) Install TOMCAT web server and APACHE. While installation assign port number

4040 to TOMCAT and 8080 to APACHE. Make sure that these ports are available i.e., no

other process is using this port.

b) Access the above developed static web pages for books web site, using these servers by

putting the web pages developed in week-1 and week-2 in the document root.

a) Installation of Apache Tomcat 6.0

1) 

Download the backup program of Apache Tomcat 6.0 from Apache website. Doubleclick on it to start the installation.

2)  Then it will display some description about the installation. Click next to continue.

Page 32: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 32/52

 

3)  Then it will display the list of components to be installed. Don’t change

anything click next to continue.

 

4)  Then it will display the installation directory. Click next to continue.

Page 33: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 33/52

 

5)  Enter the port number as 8080 and give proper username and password. Click next

to continue.

6)  Java Virtual Machine will be automatically detected by the Installer, once you have

installed the JDK software prior to the installation of this web server software.

Page 34: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 34/52

 

7)  Then the installer finishes its installation. Click on finish to complete the

installation.

Page 35: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 35/52

 

 b) Path setting for servlet-api.jar 

1)  Right click on my computer then select properties.

2)  Then under Advanced tab select Environment variables.

Page 36: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 36/52

 

3)  click on new then enter Variable name as classpath and enter Variable value as the

following.

C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar;.;

4)  Click on OK to complete the Settings.

Page 37: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 37/52

 

c) Testing the Tomcat Web Server.

1)  Click on StartMenu -> Programs -> Apache Tomcat 6.0 -> Configure Tomcat.

2)  Click on start to start the Tomcat service. 

Page 38: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 38/52

 

3)  Then open the Web browser and enter the following in the address to open tomcathomepage.

http://localhost:8080

Page 39: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 39/52

 

4)  Then click on Tomcat Manager and provide the username and password to get into

the application managers page.

Page 40: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 40/52

 

6) 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.

User Authentication:

Assume four users user1, user2, user3 and user4 having the passwords pwd1, pwd2, pwd3 and

 pwd4 respectively. Write a servelet for doing the following.

1. Create a Cookie and add these four user id’s and passwords to this Cookie. 

2. Read the user id and passwords entered in the Login form (week1) and authenticate with the

values (user id and passwords) available in the cookies If he is a valid user(i.e., user-name and

 password match) you should welcome him by name(user-name) else you should display “ Youare not an authenticated user “. 

Use init-parameters to do this. Store the user-names and passwords in the webinf.xml and access

them in the servlet by using the getInitParameters() method.

User Authentication Using Cookies:

Login.html

<html>

<head>

<title>login.html</title

</head>

<body bgcolor="pink">

<center>

<h1>Cookies Example</h1>

<form action="/Week8Cookies/log">

<table>

Page 41: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 41/52

 

<tr>

<td><b>userid:</b></td><td><input type="text" name="username"></td>

</tr>

<tr>

<tr>

<td><b>password:</b></td><td><input type="text" name="password"></td>

</tr>

<tr>

<td></td>

<td><input type="submit" value="Login"><input type="reset" value="Reset"></td>

</tr>

</table>

</form>

</center>

</body>

</html>

AddUsers.java

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class AddUsers extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

Page 42: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 42/52

 

response.setContentType("text/html");

PrintWriter out = response.getWriter();

Cookie user1 = new Cookie("John","John123");

Cookie user2 = new Cookie("Johnson","Johnson123");

Cookie user3 = new Cookie("Rahul","Rahul123");

Cookie user4 = new Cookie("Rohit","Rohit123");

Cookie user5 = new Cookie("Raj","Raj123123");

response.addCookie(user1);

response.addCookie(user2);

response.addCookie(user3);

response.addCookie(user4);

response.addCookie(user5);

out.println("<html><body bgcolor=pink>");

out.println("<center><h1>Cookies added

Successfully</h1><center></body></html>");

out.close();

}

}

Page 43: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 43/52

 

LoginForm.java

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class LoginForm extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html");

PrintWriter out = response.getWriter();

Cookie cs[] = request.getCookies();

String userName = request.getParameter("username");

String password = request.getParameter("password");

boolean validUser = false;

String cuserName = null;

String cpassword = null;

for(Cookie c:cs){

cuserName = c.getName();

cpassword = c.getValue();

if(cuserName.equals(userName) && cpassword.equals(password)) {

Page 44: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 44/52

 

validUser = true;

break;

}

}

if(validUser) {

out.println("<html><body bgcolor=pink>");

out.println("<h1>Login Successfull</h1>");

out.println("<b>Welcome " + cuserName+"</b></body></html>");

}

else {

out.println("<html><body bgcolor=pink>");

out.println("<b>"+userName + "is an invalid user</b></body></html>");

}

out.close();

}

}

web.xml

<?xml version="1.0"?>

<web-app>

<servlet>

<servlet-name>AddUsersServlet</servlet-name>

<servlet-class>AddUsers</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>AddUsersServlet</servlet-name>

Page 45: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 45/52

 

<url-pattern>/add</url-pattern>

</servlet-mapping>

<servlet>

<servlet-name>LoginFormServlet</servlet-name>

<servlet-class>LoginForm</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>LoginFormServlet</servlet-name>

<url-pattern>/log</url-pattern>

</servlet-mapping>

</web-app>

Output Screens

1) URL : http://localhost:8085/WeekCookie/add 

Page 46: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 46/52

 

2) URL : http://localhost:8085/WeekCookie/login.html 

3) URL: http://localhost:8085/WeekCookie/log?username=John&password=John123

 

Page 47: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 47/52

 

User Authentication Using Initialization Parameters:

Login.html

<html>

<head>

<title>login.html</title

</head>

<body bgcolor="pink">

<center>

<h1>Cookies Example</h1>

<form action="/Week8Init/log">

<table>

<tr>

<td><b>userid:</b></td><td><input type="text" name="username"></td>

</tr>

<tr>

<tr>

<td><b>password:</b></td><td><input type="text" name="password"></td>

</tr>

<tr>

<td></td>

<td><input type="submit" value="Login"><input type="reset"value="Reset"></td>

</tr>

</table>

</form>

</center>

</body>

</html>

Page 48: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 48/52

 

LoginForm.java

import java.io.*;

import java.util.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class LoginForm extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html");

PrintWriter out = response.getWriter();

Enumeration en = getInitParameterNames();

String userName = request.getParameter("username");

String password = request.getParameter("password");

String initName = null;

String initPass = null;

boolean validUser=false;

while (en.hasMoreElements()) {

initName = (String)en.nextElement();

initPass = getInitParameter(initName);

if(initName.equals(userName) && initPass.equals(password)) {

validUser = true;

break;

}

Page 49: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 49/52

 

}

if(validUser) {

out.println("<html><body bgcolor=pink>");

out.println("<h1>Login Successfull</h1>");

out.println("<b>Welcome " + userName+"</b></body></html>");

}

else {

out.println("<html><body bgcolor=pink>");

out.println("<b>"+userName + "is an invalid user</b></body></html>");

}

out.close();

}

}

web.html

<?xml version="1.0"?>

<web-app>

<servlet>

<servlet-name>LoginFormServlet</servlet-name>

<servlet-class>LoginForm</servlet-class>

<init-param>

<param-name>John</param-name>

<param-value>John123</param-value>

Page 50: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 50/52

 

</init-param>

<init-param>

<param-name>Johnson</param-name>

<param-value>Johnson123</param-value>

</init-param>

<init-param>

<param-name>Rahul</param-name>

<param-value>Rahul123</param-value>

</init-param>

<init-param>

<param-name>Rohit</param-name>

<param-value>Rohit123</param-value>

</init-param>

<init-param>

<param-name>Raj</param-name>

<param-value>Raj123</param-value>

</init-param>

</servlet>

<servlet-mapping>

<servlet-name>LoginFormServlet</servlet-name>

<url-pattern>/log</url-pattern>

</servlet-mapping>

</web-app>

Page 52: Jwt Lab Manual for m.tech Final

7/28/2019 Jwt Lab Manual for m.tech Final

http://slidepdf.com/reader/full/jwt-lab-manual-for-mtech-final 52/52

 

7) Implement the “Hello World!” program using JSP Struts Framework. Source Code for the Hello

World Tag Example

<html>

<head>

<title>JSP 2.0 Examples - Hello World SimpleTag Handler</title>

</head>

<body><h1>JSP 2.0 Examples - Hello World SimpleTag Handler</h1>

<hr>

<p>This tag handler simply echos "Hello, World!" It's an example of 

a very basic SimpleTag handler with no body.</p>

<br><b><u>Result:</u></b>

<mytag:helloWorld/></body>

</html>OUT PUT

This tag handler simply echos "Hello, World!" It's an example of a very basic SimpleTag handler with no

 body. 

Result: Hello, world!