Web Designing programs

Published on May 2016 | Categories: Documents | Downloads: 56 | Comments: 0 | Views: 401
of 122
Download PDF   Embed   Report

Contains all programs

Comments

Content

JNTUH

WEB TECHNOLOGIES

Web Technologies Syllabus Programs (JNTU)
S.No

Programs

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.
Validate the registration, user login, user profile and payment by credit
card pages using JavaScript.

2
3

4

5

6

7

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.
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.
Install TOMCAT web server. Convert the static web pages of
assignments 2 into dynamic web pages using servlets and cookies. Hint:
User’s information (user id, password, credit card number) would be
stored in web. Xml. Each user should have a separate shopping cart.
Redo the previous task using JSP by converting the static web pages of
assignment 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.
Implement the “Hello World” program using JSP Struts Framework.

1

JNTUH

WEB TECHNOLOGIES

1.Develop static pages (using only HTML) of an online Book store. The pages should
resemble: www.amazon.com
The website consists the following pages.
Home page, Registration and user Login, User profile page, Books catalog, Shopping
cart, Payment By credit card, order confirmation.
HOME PAGE
<!DOCTYPE html>
<html>
<body>
<table width=100%>
<tr>
<td><img src="amazonlogo.jpg"> </td>
<td style="background-color:#E55151">
<h1> WELCOME TO AMAZON.COM <h1> </td>
</tr>
<tr>
<td colspan="2" style="background-color:#AFB3F2"> HOMEPAGE
</td>
</tr>
<tr>
<td colspan="2" style="background-color:#E8F2AF; text-align:center">
<a href="regamazon.html" style="text-decoration:none"> registration
link </a>
<hr>
<a href="logamazon.html" style="text-decoration:none"> user login link </a>
<hr>
<a href="profamazon.html" style="text-decoration:none" > user profile page </a>
<hr>
<a href="bookamazon.html" style="text-decoration:none" > books catalog </a>
<hr>
<a href="shopcart.html" style="text-decoration:none"> shopping cart</a>
<hr>
<a href="payamazon.html" style="text-decoration:none"> payment by
credit card
</a>
<hr>
<a href="orderamazon.html" style="text-decoration:none"> order confirmation </a>
</td>
</tr>
<tr>
<td colspan="2" style="background-color:#FFA500;text-align:center;">
www.amazon.com </td>
</tr>
</body>
</html>

2

JNTUH

WEB TECHNOLOGIES

REGISTRATION
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style>
p.reg {color:#990000}
</style>
</head>
<body><b><font size="4">
<div id="main" style="margin-left:60px;width:800px;height:100%">
<table WIDTH=100%>
<tr>
<td width=70%> <img src="amazonlogo.jpg">
</td>
<td width=100%> <button type="button"
onclick="window.location.href='Amazon4.html'">HOMEPAGE</BUTTON>
</td>
</tr>
</table>
<table>
<tr>
<p class="reg" > Registration <br> New to Amazon.com? Register Below.<br></p>
</tr>
<tr >
<form action="">
3

JNTUH

WEB TECHNOLOGIES

<td style="text-align:right">My name is:</td> <td><input type="text" name="name"></td>
</form>
</tr>
<tr >
<form action="">
<td style="text-align:right">My e-mail address is:</td> <td> <input type="text"
name="emailid"></td>
</form>
</tr>
<tr >
<form action="">
<td style="text-align:right">Type it again:</td> <td> <input type="text" name="emailid">
</td>
</form>
</tr>
<tr >
<form action="">
<td style="text-align:right">My mobile phone number is: </td> <td><input type="text"
name="phone"> </td>
</form>
</tr>
</table>
<table width=100%>
<tr>
<p class="reg" > Protect your information with a password</p>
</tr>
<tr >
<form action="">
<td style="text-align:right">Enter a new password:</td> <td> <input type="password"
name="password1"></td>
</form>
</tr>
<tr >
<form action="">
<td style="text-align:right">Type it again:</td> <td> <input type="password"
name="password1"></td>
</form>
</tr>
<tr>
<td colspan="2" style="text-align:center"><button type="button" onclick="alert('Thank
you')">Create Account</td>
</tr>
</table>
</b>
</font>
</div>
</body>
</html>

4

JNTUH

WEB TECHNOLOGIES

LOGIN
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style>
p.reg {color:#990000}
</style>
</head>
<body><font size="4">
<div id="main" style="margin-left:60px;width:800px;height:100%">
<table WIDTH=100%>
<tr>
<td width=70%> <img src="amazonlogo.jpg">
</td>
<td width=100%> <button type="button"
onclick="window.location.href='Amazon4.html'">HOMEPAGE</BUTTON>
</td>
</tr>
</table>
<div id="body" style="border:1px solid black"><b>
5

JNTUH

WEB TECHNOLOGIES

<p class="reg"> Sign In <br> What is your e-mail address?</p>
<table align="center">
<tr >
<form action="">
<td style="text-align:right">My e-mail address is:</td> <td> <input
type="text"
name="emailid1"></td>
</form>
</tr>
</table>
<p class="reg"> Do you have an Amazon.com password?</p>
<table align="center">
<tr >
<form action="">
<input type="radio" name="ans" value="no">No, I am a new
customer<br>
<input type="radio" name="ans" value="yes">Yes,I have a password:<input
type="text" name="password"><br>
</form>
</tr>
<tr> <a href="">Forgot password</a></tr>
<tr>
<td>
<button type="button">Sign in using our secure server</button>
</td>
</table></b>
</div>
<div id="help">
<p>Sign In Help</p>
<p>Forgot your password? <a href=""> Get password help.</a></p>
<p> Has your e-mail address changed? <a href="">Update it
here.</a></p>
<hr>
</div>
<div id="footer" style="text-align:center"><a href="">Conditions of Use</a>
<a href="">Privacy Notice</a>@ 1996-2013,Amazon.com,Inc. or its affliates</div>
</DIV>
</body>
</html>

6

JNTUH

WEB TECHNOLOGIES

PROFILE PAGE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<div id="main" style="margin-left:60px;width:800px;height:100%">
<table WIDTH=100%>
<tr>
<td width=70%> <img src="amazonlogo.jpg">
</td>
<td width=100%> <button type="button"
onclick="window.location.href='Amazon4.html'">HOMEPAGE</BUTTON>
</td>
</tr>
</table>
<hr>
<h1>John</h1>
<div id="index" style="width:100%;height:500px">
<div id="a" style="float:left;width=300px;height:500px">
<img src="dp.jpg">
</div>
<div id="b" style="float:left;width=100%;height:500px">
<table>
<tr >
<td style="text-align:right">My name is:</td> <td>----------------</td>
</tr>
<tr >
<td style="text-align:right">My e-mail address is:</td> <td>-------------</td>
7

JNTUH

WEB TECHNOLOGIES

</tr>
<tr >
<td style="text-align:right">My mobile phone number is: </td> <td>--------- </td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>

BOOKS CATALOG
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body >
<div id="main" style="margin-left:60px;width:800px;height:100%">
<table WIDTH=100%>
<tr>
<td width=70%> <img src="amazonlogo.jpg">
</td>
<td width=100%> <button type="button"
onclick="window.location.href='Amazon4.html'">HOMEPAGE</BUTTON>
</td>
</tr>
8

JNTUH

WEB TECHNOLOGIES

</table>
<h1><CENTER>BOOKS</center></H1>
<img src="book.jpg">
<br><br>
<div id="index" style="width:100%;height:500px">
<div id="a" style="float:left;width=300px;height:500px">
<h4>Department</h4>
<li>Arts & Photography</li>
<li>Biographies & Memoirs</li>
<li>Business & Investing </li>
<li>Calendars</li>
<li>Children's Books </li>
<li>Christian Books & Bibles</li>
<li>Comics & Graphic Novels </li>
<li>Computers & Technology </li>
</div>
<div id="b" style="float:left;width=100%;height:500px">
<h2>Select the book to get further details</h2>
<table border=1>
<tr>
<td><a href="bk1.html"><img src="bk1.jpg"><br><p>The Space between
Us<br>Thrity Umrigar</p></a></td>
<td><a href="bk6.html"><img
src="bk6.jpg"><br><p>Sapphire<br>Katie
Price</p></a></td>
<td><a href="bk2.html"><img
src="bk2.jpg"><br><p>Reflex<br>Steven
Gold</p></td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>

9

JNTUH

WEB TECHNOLOGIES

SHOPPING CART
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<div id="main" style="margin-left:60px;width:800px;height:100%">
<table WIDTH=100%>
<tr>
<td width=70%> <img src="amazonlogo.jpg">
</td>
<td width=100%> <button type="button"
onclick="window.location.href='Amazon4.html'">HOMEPAGE</BUTTON>
</td>
</tr>
</table>
<h1><center>SHOPPING CART</center></h1>
<hr>
<table border=1>
<tr>
<th width=80%>Items to buy now</th>
<th width=20%>Price</th>
<th width=20%>Quantity</th>
</tr>
<tr>
<td width=80% height="90"></td>
<td width=20% height="90"></td>
<td width=20% height="90"></td>
</tr>
</table>
<hr>
10

JNTUH

WEB TECHNOLOGIES

<h3>Saved for later</h3>
<table border=1>
<tr>
<th width=80%>To buy an item now, click "Move to cart"</th>
<th width=20%>Price</th>
<th width=20%>Move to cart</th>
</tr>
<tr>
<td width=80% height="90"></td>
<td width=20% height="90"></td>
<td width=20% height="90"></td>
</tr>
</table>
<hr>
<h1><center>SUBTOTAL: INR </center></h1>
<hr>
<center><button type="button"
onclick="window.location.href='shipnpay.html'">Proceed to
checkout</center></button>
</center>
</body>
</html>

SHIPPING ADDRESS
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

11

JNTUH

WEB TECHNOLOGIES

<html>
<body>
<div id="main" style="margin-left:60px;width:800px;height:100%">
<tr>
<td width=70%> <img src="amazonpic.png">
</td>
<td width=100%> <button type="button"
onclick="window.location.href='Amazon4.html'">HOMEPAGE</BUTTON>
</td>
</tr>
</table>
<p><font size="6">Select a shipping address</font></p>
<p><font size="5">Enter a new shipping address.</font></p>
<p>When finished,click the "Continue" button.
<form action=""><b>
Full name:<br><input type="text" name="name" size="50" maxlength="60" ><br>
Address Line1:<br><input type="text" name="address1" size="50" maxlength="60"
placeholder="Street address, P.O. box,company name,c/o"><br>
Address Line2:<br><input type="text" name="address2" size="50" maxlength="60"
placeholder="Apartment, suite, unit, building, floor, etc."><br>
City:<br><input type="text" name="city" size="50" maxlength="60"><br>
Sity/Province/Region:<br><input type="text" name="state" size="50" maxlength="60"><br>
ZIP:<br><input type="text" name="zip" size="50" maxlength="60"><br>
Country:<br><select name="country" maxlength="60">
<option value="AF">Afghanistan</option>
<option value="AX">Aland Islands</option>
<option value="AL">Albania</option>
<option value="DZ">Algeria</option>
<option value="AS">American Samoa</option>
<option value="AD">Andorra</option>
<option value="AO">Angola</option>
<option value="AI">Anguilla</option>
<option value="AQ">Antarctica</option>
<option value="AG">Antigua and Barbuda</option>
<option value="AR">Argentina</option>
<option value="AM">Armenia</option>
<option value="AW">Aruba</option>
<option value="BY">Belarus</option>
<option value="BE">Belgium</option>
<option value="BZ">Belize</option>
<option value="BJ">Benin</option>
<option value="BM">Bermuda</option>
<option value="CM">Cameroon</option>
<option value="HK">Hong Kong</option>
<option value="HU">Hungary</option>
<option value="IS">Iceland</option>
<option value="IN">India</option>
<option value="ID">Indonesia</option>
<option value="IQ">Iraq</option>
<option value="IE">Ireland</option>
12

JNTUH

WEB TECHNOLOGIES

<option value="IM">Isle of Man</option>
<option value="IL">Israel</option>
<option value="IT">Italy</option>
<option value="JM">Jamaica</option>
<option value="JP">Japan</option>
<option value="JE">Jersey</option>
<option value="JO">Jordan</option>
<option value="LY">Libya</option>
<option value="LI">Liechtenstein</option>
<option value="AE">United Arab Emirates</option>
<option value="GB">United Kingdom</option>
<option value="US" >United States</option>
<option value="UM">United States Minor Outlying Islands</option>
<option value="UY">Uruguay</option>
<option value="UZ">Uzbekistan</option>
<option value="VU">Vanuatu</option>
<option value="ZM">Zambia</option>
<option value="ZW">Zimbabwe</option>
</select><br>
Phone Number:<br><input type="text" size="50" maxlength="60"><br>
</b></form>
<p><font size="6"> Optional Delivery Preferences</font></p>
<form action=""><b>
Address Type:<br><select name="addresstype" placeholder="Select an Address Type">
<option value="res">Residential</option>
<option value="com">Commercial</option>
</select><br>
Security Access Code:<br><input type="text" placeholder="For buildings or gated
communities"><br>
Is this address also your billing address(the address that appears on your credit card or bank
statement)?<br>
<input type="radio" name="ans" value="yes">Yes<br>
<input type="radio" name="ans" value="no">No (If not, we'll ask you for it in a moment )
<br>
<hr>
</form>
<form action="pay.html">
<button type="button" ONCLICK="window.location.href='pay.html'">Continue</button>
</form>
</div>
</body>
</html>

13

JNTUH

WEB TECHNOLOGIES

PAYMENT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body><font size="4">
<div id="main" style="margin-left:60px;width:800px;height:100%">
<img src="amazonpic.png">
<p><font size="6">Add a Payment Method</font></p>
<hr>
<p><font size="5">Credit or Debit Cards</font></p>
<p>Amazon accepts all major credit and debit cards:</p>
<div id="imagecredit" style="marginleft:600px;width:200px;height:90px">
<img src="creditcard.jpg">
</div>
<p>Add a card</p>
<p>Enter your card information:</p>
<form action="">
<table><b>
<tr>
<td>Name on card<br><input type="text" name="cardname"></td>
<td>Card number<br><input type="text" name"cardno"></td>
<td>Expiration Date<br><select name="month">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
14

JNTUH

WEB TECHNOLOGIES
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
<select name="year">
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
</select>

</td>
<td><button type="button">Add your card</button></td>
</tr>
</form>
</table></b>
<hr>
<p><font size="5">Gift Cards & Promotional Codes</font></p>
<p>Enter a gift card or promotional code</p>
<form>
<input type="text" name="code"><button type="button">Apply</button>
</form>
<hr>
<button type="button"
ONCLICK="window.location.href='confirm.html'">Cotinue</button>
</div>
</font>
</body>
</html>

15

JNTUH

WEB TECHNOLOGIES

ORDER CONFIRMATION
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body><font size="4">
<div id="main" style="margin-left:60px;width:800px;height:100%">
<img src="amazonconfirm.png">
<p><font size="6">Review your order</font></p>
<p>By placing your order, you agree to Amazon.com's privacy notice
conditions
of use.</p>
<div id="a" style="width:800px;height:200px">
<table border=1>
<tr>
<th width=50%>Shipping Address</th>
<th width=30%>Payment Method</th>
<th width=30%>Gift cards & promotional codes</th>
</tr>
<tr>
<td width=50% height="90"></td>
<td width=30% height="90"></td>
<td width=30% height="90"></td>
</tr>
</table>
</div>
<hr>
<div id="b" style=";width:800px;height:200px">
<b>Estimated delivery date:<br><br><br><br><br></b></td>
16

and

JNTUH

WEB TECHNOLOGIES

</div>
<div id="b" style="border:2px solid black;width:800px;height:200px">
<p><b>Order Summary</b></p>
Items: INR<br>
Shipping & Building: INR<br>
<hr>
Total before tax: INR<br>
Estimated tax to be collected: INR<br>
Import Fees Deposit: INR<br>
<hr>
<h1><b>Order total: INR </b></h1>
<hr>
<center><button type="button" name="confirm"
ONCLICK="window.location.href='thanku.html'" >
CONFIRM</button></center>
</div>
</font>
</body>
</html>

17

JNTUH

WEB TECHNOLOGIES

18

JNTUH

WEB TECHNOLOGIES

2. Validate the registration, user login, user profile and payment by credit card pages
using JavaScript.
REGISTRATION

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<style>
p.reg {color:#990000}
</style>
</head>
<body><b><font size="4">

<script>
function myFunc()
{
if(document.getElementById("myName").elements[0].value=="")
{
alert("First name must be filled out");
return false;
}
if(document.getElementById("myMail").elements[0].value=="")
{
alert("Please provide the e-mail id!");
return false;
}
if(document.getElementById("Mail").elements[0].value=="")
{
19

JNTUH

WEB TECHNOLOGIES

alert("Type in the e-mail id again !");
return false;
}
if(document.getElementById("myMail").elements[0].value.length!
=document.getElementById("Mail").elements[0].value.length)
{
alert("E-mail id do not match");
document.getElementById("myMail").elements[0].value="";
document.getElementById("Mail").elements[0].value="";
return false;
}
if(document.getElementById("myMail").elements[0].value.length==document.getElementBy
Id("Mail").elements[0].value.length)
{
if(document.getElementById("myMail").elements[0].value!
=document.getElementById("Mail").elements[0].value)
{
alert("E-mail id do not match");
document.getElementById("myMail").elements[0].value="";
document.getElementById("Mail").elements[0].value="";
return false;
}
}
if(document.getElementById("myPhone").elements[0].value="")
{
alert("Please enter a valid phone number");
return false;
}
if(document.getElementById("myPass").elements[0].value=="")
{
alert("Please enter a password");
return false;
20

JNTUH

WEB TECHNOLOGIES

}
if(document.getElementById("myPass").elements[0].value!="")
{
if(document.getElementById("myPass").elements[0].value.length<8)
{
alert("password should be atleast of length 8");
return false;
}
}
if(document.getElementById("Pass").elements[0].value=="")
{
alert("Type in the password again !");
return false;
}
if(document.getElementById("myPass").elements[0].value.length!
=document.getElementById("Pass").elements[0].value.length)
{
alert("passwords do not match");
document.getElementById("myPass").elements[0].value="";
document.getElementById("Pass").elements[0].value="";
return false;
}
if(document.getElementById("myPass").elements[0].value.length==document.getElementBy
Id("Pass").elements[0].value.length)
{
if(document.getElementById("myPass").elements[0].value!
=document.getElementById("Pass").elements[0].value)
{
alert("passwords do not match");
document.getElementById("myPass").elements[0].value="";
document.getElementById("Pass").elements[0].value="";
return false;
21

JNTUH

WEB TECHNOLOGIES

}}
else
{
alert("thank u");
}}
</script>

<div id="main" style="margin-left:60px;width:800px;height:100%">
<table WIDTH=100%>
<tr>
<td width=70%> <img src="amazonlogo.jpg">
</td>
<td width=100%> <button type="button"
onclick="window.location.href='Amazon4.html'">HOMEPAGE</BUTTON>
</td>
</tr>
</table>
<table>
<tr>
<p class="reg" > Registration <br> New to Amazon.com? Register Below.<br></p>
</tr>
<tr >
<form id="myName" action="" method="post">
<td style="text-align:right">My name is:</td> <td><input type="text" name="fname"></td>
</form>
</tr>
<tr >
<form id="myMail" action="">
<td style="text-align:right">My e-mail address is:</td> <td> <input type="text"
name="emailid"></td>
</form>
22

JNTUH

WEB TECHNOLOGIES

</tr>
<tr >
<form id="Mail" action="">
<td style="text-align:right">Type it again:</td> <td> <input type="text" name="emailid">
</td>
</form>
</tr>
<tr >
<form id="myPhone" action="">
<td style="text-align:right">My mobile phone number is: </td> <td><input type="text"
name="phone"> </td>
</form>
</tr>
</table>

<table width=100%>
<tr>
<p class="reg" > Protect your information with a password</p>
</tr>
<tr >
<form id="myPass" action="">
<td style="text-align:right">Enter a new password:</td> <td> <input type="password"
name="password1"></td>
</form>
</tr>
<tr >
<form id="Pass" action="">
<td style="text-align:right">Type it again:</td> <td> <input type="password"
name="password1"></td>
</form>
</tr>
<tr>
23

JNTUH

WEB TECHNOLOGIES

<td colspan="2" style="text-align:center"><button onclick="myFunc()">Create
Account</td>
</tr>
</table>
</b>
</font>
</div>
</body>
</html>

LOGIN

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style>
p.reg {color:#990000}
</style>
24

JNTUH

WEB TECHNOLOGIES

</head>
<body><font size="4">

<script>
function myFunc()
{
if(document.getElementById("mail").elements[0].value=="")
{
alert("Please enter the e-mail id");
return false;
}
if(document.getElementById("options").elements[1].checked)
{
if(document.getElementById("options").elements[2].value=="")
{
alert("please write password");
return false;
} }}
</script>

<div id="main" style="margin-left:60px;width:800px;height:100%">
<table WIDTH=100%>
<tr>
<td width=70%> <img src="amazonlogo.jpg">
</td>
<td width=100%> <button type="button"
onclick="window.location.href='Amazon4.html'">HOMEPAGE</BUTTON>
</td>
</tr>
</table>
<div id="body" style="border:1px solid black"><b>
25

JNTUH

WEB TECHNOLOGIES

<p class="reg"> Sign In <br> What is your e-mail address?</p>
<table align="center">
<tr >
<form id="mail" action="">
<td style="text-align:right">My e-mail address is:</td> <td> <input
name="emailid1"></td>

type="text"

</form>
</tr>
</table>
<p class="reg"> Do you have an Amazon.com password?</p>
<table align="center">
<tr >
<form id="options" action="">
<input type="radio" name="ans" value="no">No, I am a new

customer<br>

<input type="radio" name="ans" value="yes">Yes,I have a password:<input
type="text" name="password"><br>
</form>
</tr>
<tr> <a href="">Forgot password</a></tr>
<tr>
<td>
<button onclick="myFunc()">Sign in using our secure server
</td>
</table></b>
</div>
<div id="help">
<p>Sign In Help</p>
<p>Forgot your password? <a href=""> Get password help.</a></p>
<p> Has your e-mail address changed? <a href="">Update it
<hr>
</div>
26

here.</a></p>

JNTUH

WEB TECHNOLOGIES

<div id="footer" style="text-align:center"><a href="">Conditions of Use</a>
<a href="">Privacy Notice</a>@ 1996-2013,Amazon.com,Inc. or its affliates</div>
</DIV>
</body>
</html>

PAYMENT

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<script>
function myFunc()
{
if(document.getElementById("ship").elements[0].value=="")
{
alert("Please enter the name");
return false;
27

JNTUH

WEB TECHNOLOGIES

}
if(document.getElementById("ship").elements[1].value=="")
{
alert("Please enter the address");
return false;
}
if(document.getElementById("ship").elements[2].value=="")
{
alert("Please enter the address");
return false;
}
if(document.getElementById("ship").elements[3].value=="")
{
alert("Please enter the city");
return false;
}
if(document.getElementById("ship").elements[4].value=="")
{
alert("Please enter the state");
return false;
}
if(document.getElementById("ship").elements[5].value=="")
{
alert("Please enter the ZIP");
return false;
}

if(document.getElementById("ship").elements[7].value=="")
{
alert("Please enter the phone no.");
return false;
28

JNTUH

WEB TECHNOLOGIES

}
return true;
}
</script>
<div id="main" style="margin-left:60px;width:800px;height:100%">
<tr>
<td width=70%> <img src="amazonpic.png">
</td>
<td width=100%> <button type="button"
onclick="window.location.href='Amazon4.html'">HOMEPAGE</BUTTON>
</td>
</tr>
</table>
<p><font size="6">Select a shipping address</font></p>
<p><font size="5">Enter a new shipping address.</font></p>
<p>When finished,click the "Continue" button.
<form id="ship" action=""><b>
Full name:<br><input type="text" name="name" size="50" maxlength="60" ><br>
Address Line1:<br><input type="text" name="address1" size="50" maxlength="60"
placeholder="Street address, P.O. box,company name,c/o"><br>
Address Line2:<br><input type="text" name="address2" size="50" maxlength="60"
placeholder="Apartment, suite, unit, building, floor, etc."><br>
City:<br><input type="text" name="city" size="50" maxlength="60"><br>
Sity/Province/Region:<br><input type="text" name="state" size="50"
maxlength="60"><br>
ZIP:<br><input type="text" name="zip" size="50" maxlength="60"><br>
Country:<br><select name="country" maxlength="60">
<option value="AF">Afghanistan</option>
<option value="AX">Aland Islands</option>
<option value="AL">Albania</option>
<option value="DZ">Algeria</option>
<option value="AS">American Samoa</option>
29

JNTUH

WEB TECHNOLOGIES
<option value="AD">Andorra</option>
<option value="AO">Angola</option>
<option value="AI">Anguilla</option>
<option value="AQ">Antarctica</option>
<option value="AG">Antigua and Barbuda</option>
<option value="AR">Argentina</option>
<option value="AM">Armenia</option>
<option value="AW">Aruba</option>

<option value="AU">Australia</option>
<option value="AT">Austria</option>
<option value="AZ">Azerbaijan</option>
<option value="BS">Bahamas, The</option>
<option value="CV">Cape Verde</option>
<option value="KY">Cayman Islands</option>
<option value="CF">Central African Republic</option>
<option value="TD">Chad</option>
<option value="NE">Niger</option>
<option value="NG">Nigeria</option>
<option value="PH">Philippines</option>
<option value="SA">Saudi Arabia</option>
<option value="UM">United States Minor Outlying Islands</option>
<option value="UY">Uruguay</option>
<option value="UZ">Uzbekistan</option>
<option value="VU">Vanuatu</option>
<option value="VE">Venezuela</option>
<option value="YE">Yemen</option>
<option value="ZM">Zambia</option>
<option value="ZW">Zimbabwe</option>
</select><br>
Phone Number:<br><input type="text" size="50" maxlength="60"><br>
</b></form>
30

JNTUH

WEB TECHNOLOGIES

<p><font size="6"> Optional Delivery Preferences</font></p>
<form id="ship1" action=""><b>
Address Type:<br><select name="addresstype" placeholder="Select an Address Type">
<option value="res">Residential</option>
<option value="com">Commercial</option>
</select><br>
Security Access Code:<br><input type="text" placeholder="For buildings or gated
communities"><br>
Is this address also your billing address(the address that appears on your credit card or bank
statement)?<br>
<input type="radio" name="ans" value="yes">Yes<br>
<input type="radio" name="ans" value="no">No (If not, we'll ask you for it in a moment )
<br>
<hr>
</form>

<button type="button" onclick="myFunc()" >Confirm</button><br>
<form action="pay.html">

<button type="button" ONCLICK="window.location.href='pay.html'">Continue</button>
</form>
</div>
</body>
</html>

31

JNTUH

WEB TECHNOLOGIES

32

JNTUH

WEB TECHNOLOGIES

3. XSL FILE TO RETREIVE THE DATA
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Title</th>
<th style="text-align:left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

33

JNTUH

WEB TECHNOLOGIES

XML FILE CONTAINING THE DATA
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="stu.xsl" ?>
<!-- Edited by XMLSpy -->
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
<cd>
<title>Still got the blues</title>
34

JNTUH

WEB TECHNOLOGIES
<artist>Gary Moore</artist>
<country>UK</country>
<company>Virgin records</company>
<price>10.20</price>
<year>1990</year>

</cd>
<cd>
<title>Eros</title>
<artist>Eros Ramazzotti</artist>
<country>EU</country>
<company>BMG</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>One night only</title>
<artist>Bee Gees</artist>
<country>UK</country>
<company>Polydor</company>
<price>10.90</price>
<year>1998</year>
</cd>
<cd>
<title>Sylvias Mother</title>
<artist>Dr.Hook</artist>
<country>UK</country>
<company>CBS</company>
<price>8.10</price>
<year>1973</year>
</cd>
<cd>
35

JNTUH

WEB TECHNOLOGIES
<title>Maggie May</title>
<artist>Rod Stewart</artist>
<country>UK</country>
<company>Pickwick</company>
<price>8.50</price>
<year>1990</year>

</cd>
<cd>
<title>Romanza</title>
<artist>Andrea Bocelli</artist>
<country>EU</country>
<company>Polydor</company>
<price>10.80</price>
<year>1996</year>
</cd>
<cd>
<title>When a man loves a woman</title>
<artist>Percy Sledge</artist>
<country>USA</country>
<company>Atlantic</company>
<price>8.70</price>
<year>1987</year>
</cd>
<cd>
<title>Big Willie style</title>
<artist>Will Smith</artist>
<country>USA</country>
<company>Columbia</company>
<price>9.90</price>
<year>1997</year>
</cd>
36

JNTUH

WEB TECHNOLOGIES

</cd>
<cd>
<title>The very best of</title>
<artist>Cat Stevens</artist>
<country>UK</country>
<company>Island</company>
<price>8.90</price>
<year>1990</year>
</cd>
<cd>
<title>Stop</title>
<artist>Sam Brown</artist>
<country>UK</country>
<company>A and M</company>
<price>8.90</price>
<year>1988</year>
</cd>
<cd>
<title>Bridge of Spies</title>
<artist>T`Pau</artist>
<country>UK</country>
<company>Siren</company>
<price>7.90</price>
<year>1987</year>
</cd>
<cd>
<title>Private Dancer</title>
<artist>Tina Turner</artist>
<country>UK</country>
<company>Capitol</company>
<price>8.90</price>
37

JNTUH

WEB TECHNOLOGIES
<year>1983</year>

</cd>
<cd>
<title>Midt om natten</title>
<artist>Kim Larsen</artist>
<country>EU</country>
<company>Medley</company>
<price>7.80</price>
<year>1983</year>
</cd>
<cd>
<title>Pavarotti Gala Concert</title>
<artist>Luciano Pavarotti</artist>
<country>UK</country>
<company>DECCA</company>
<price>9.90</price>
<year>1991</year>
</cd>
</catalog>

38

JNTUH

WEB TECHNOLOGIES

39

JNTUH

WEB TECHNOLOGIES

4. Create and save an XML document 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.

demo.html
<html>
<body>

<script>
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","details.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

var x=xmlDoc.getElementsByTagName("user");
function myfun()
{
var a = document.forms["form1"]["userid"].value;
for (i=0;i<x.length;i++)
{
if (a==x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue)
{ document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue );
document.write(" ");
document.write(x[i].getElementsByTagName("age")[0].childNodes[0].nodeValue);
40

JNTUH
document.write("

WEB TECHNOLOGIES
");

}
}}
</script>
<p id="s1"> <form name="form1"" method="get"> <p id="s1">UserId <input type="text"
name="userid"><br> <input type="submit" onclick="myfun()" value="SUBMIT"></p>
</form>
</body>
</html>

details.xml
<users>
<user>
<name>lalitha</name>
<age>21</age>
<sex>female</sex>
</user>
<user>
<name>susheel2</name>
<age>21</age>
<sex>male</sex>
</user>
<user>
<name>srinivasl3</name>
<age>21</age>
<sex>male</sex>
</user>
<user>
<name>lucas</name>
<age>13</age>
<sex>male</sex>
41

JNTUH

WEB TECHNOLOGIES

</user>
<user>
<name>nathan</name>
<age>14</age>
<sex>male</sex>
</user>
<user>
<name>brooke</name>
<age>15</age>
<sex>female</sex>
</user>
<user>
<name>susheel7</name>
<age>16</age>
<sex>male</sex>
</user>
<user>
<name>srinivasl9</name>
<age>18</age>
<sex>male</sex>
</user>
<user>
<name>leela10</name>
<age>20</age>
<sex>male</sex>
</user>
</users>

42

JNTUH

WEB TECHNOLOGIES

43

JNTUH

WEB TECHNOLOGIES

5. JavaBeans which gives the exchange value of INR (Indian Rupees) into equivalent
American Dollar value.

Indian.java
import java.beans.*;
import java.awt.*;
import java.awt.event.*;
public class Indian extends Canvas
{
private double rupees;
private String other;
public Indian()
{
setSize( 200 ,25 );
other= "America" ;
}
public void setRupees( double amount)
{ rupees=amount; repaint();
}
public double getRupees()
{ return rupees;
}
public void setOther( String other)
{ this .other=other;
repaint();
}
44

JNTUH

WEB TECHNOLOGIES

public String getOther()
{ return other;
}
public void paint( Graphics g)
{
if (other.equals( "America" ))
g.drawString( String .valueOf(rupees/ 42 ), 20 ,20 );
else

if (other.equals( "Australia" ))

g.drawString( String .valueOf(rupees/ 27 ), 20 ,20 );
else if (other.equals( "Canada" ))
g.drawString( String .valueOf(rupees/ 35 ), 20 ,20 );
else g.drawString( "I Can't convert for such country" ,20 ,20 );
}
}
1.

Compile the source code for the Bean and generate the
Currency_converter1.class in the command prompt :

    javac Indian.java
2.

Create a manifest file in a text editor.
The manifest file specifies the name of the class file and indicates that it is a
JavaBean. The manifest file becomes part of the JAR file. You can name the
manifest file manifest.man. It contains the following two lines:
Name: Indian.class
Java­Bean: True
 
(On Windows, be sure to include a carriage return at the end of the text in the
manifest file.)

3..

Create the executable JAR file.
Use the form of the jar command to include the manifest file along with the
Indian.class file (Type the command on one line):
45

JNTUH

WEB TECHNOLOGIES

jar cfm indian.jar manifest.man Indian.class

NetBean 6.1 IDE For Indian JavaBean
ï‚·

ï‚·

ï‚·

ï‚·

Click File | New Project to create a new project, a grouping of related files. Follow
the wizard steps below.
1. Choose Project - General | Java Application
2. Name and Location - Uncheck Create Main Class, check Set as Main Project
Click File | New File to create a new file. Follow the wizard steps below.
1. Choose File Type - Java GUI Forms | JApplet Form
2. Class Name - Use Default
Installing Counter JavaBeans - JavaBeans that have been jarr'ed can be downloaded
and added to the Palette .
o Tools | Pallette Manager
1. Click Add from JAR
2. Select JAR file - Locate and select indian.jar
3. Select Components - Highlight indian
4. Select Palette Category - Highlight Beans
o Beans should now contain Indian class
Visual programming - Since applets are visual it is possible to program by dragging
and dropping components from the toolbar.
o Click Design tab.
o To see the layout manager:
 Right click in gray design area | Set Layout | Flow Layout
o To add a visual object, right click the gray area:
 Add From Palette | Swing | JButton
 Add From Palette | Beans | Indian

Then the net beans IDE look like this:

46

JNTUH

WEB TECHNOLOGIES

47

JNTUH

WEB TECHNOLOGIES

48

JNTUH

WEB TECHNOLOGIES

Create a simple Bean with a label which is the count of number of clicks.
Counter.java

import java.awt.*;

public class Counter extends Panel {
private long count=0;
private Label label;
private long maxValue=20;
public void setMaxValue(long max) {
maxValue = max;
}
public long getMaxValue() { return maxValue; }
public Counter() {
setBackground(Color.blue);
setForeground(Color.white);
label = new Label(""+count);
add(label);
}
public void increment () {
if (count < maxValue) {
count++;
label.setText(count+" ");
}
else label.setText("!!");
}
}
1.

Compile the source code for the Bean and generate the Counter.class in
the command prompt :

49

JNTUH

WEB TECHNOLOGIES

    javac Counter.java
2.

Create a manifest file in a text editor.
The manifest file specifies the name of the class file and indicates that it is a
JavaBean. The manifest file becomes part of the JAR file. You can name the
manifest file manifest.man. It contains the following two lines:
Name: Counter.class
Java­Bean: True
 
(On Windows, be sure to include a carriage return at the end of the text in the
manifest file.)

3..

Create the executable JAR file.
Use the form of the jar command to include the manifest file along with the
Counter.class file (Type the command on one line):
jar cfm counterEvent.jar manifest.man Counter.class

NetBean 6.1 IDE For Counter JavaBean
ï‚·

ï‚·

ï‚·

ï‚·

Click File | New Project to create a new project, a grouping of related files. Follow
the wizard steps below.
1. Choose Project - General | Java Application
2. Name and Location - Uncheck Create Main Class, check Set as Main Project
Click File | New File to create a new file. Follow the wizard steps below.
1. Choose File Type - Java GUI Forms | JApplet Form
2. Class Name - Use Default
Installing Counter JavaBeans - JavaBeans that have been jarr'ed can be downloaded
and added to the Palette .
o Tools | Pallette Manager
1. Click Add from JAR
2. Select JAR file - Locate and select counterEvent.jar
3. Select Components - Highlight Counter
4. Select Palette Category - Highlight Beans
o Beans should now contain Counter class
Visual programming - Since applets are visual it is possible to program by dragging
and dropping components from the toolbar.
o Click Design tab.
o To see the layout manager:
 Right click in gray design area | Set Layout | Flow Layout
o To add a visual object, right click the gray area:
 Add From Palette | Swing | JButton
 Add From Palette | Beans | Counter
50

JNTUH

WEB TECHNOLOGIES

Then the net beans IDE look like this:

Connecting the Button to the Counter Bean
CounterFrame.java

public class CounterFrame extends javax.swing.JFrame {
public CounterFrame() {
initComponents();
}
private void initComponents() {
counter1 = new Counter();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
51

JNTUH

WEB TECHNOLOGIES

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(204, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(counter1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE).addGap(175, 175, 175))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup().addComponent(jButton1) .addGap(99, 99, 99)))));
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup().addGap(63, 63, 63).addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 75,
Short.MAX_VALUE).addComponent(counter1,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE).addGap(109, 109, 109)));
pack(); }
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
counter1.increment();

}

public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(CounterFrame.class.getName()).log(java.util.logging.Lev
el.SEVERE, null, ex);

52

JNTUH

WEB TECHNOLOGIES

} catch (InstantiationException ex)
{
java.util.logging.Logger.getLogger(CounterFrame.class.getName()).log(java.util.log
ging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex)
{ java.util.logging.Logger.getLogger(CounterFrame.class.getName()).log(java.util.logging.L
evel.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex)
{ java.util.logging.Logger.getLogger(CounterFrame.class.getName()).log(java.util.logging.L
evel.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new CounterFrame().setVisible(true);
}
});
}
private Counter counter1;
private javax.swing.JButton jButton1;
}

To run : Shift+F6

53

JNTUH

WEB TECHNOLOGIES

54

JNTUH

WEB TECHNOLOGIES

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.

Traffic.java

import java.awt.Panel;
import java.awt.event.*;
import java.io.PrintStream;
import java.io.Serializable;
import javax.swing.JTextField;
import java.beans.*;
public class Traffic extends Panel
implements Serializable, PropertyChangeListener
{
public Traffic()
{
tx = new JTextField(12);
state="Ready";
tx.setHorizontalAlignment(JTextField.LEFT);
tx.setText("Ready");
tx.setEnabled(false);
add(tx);
}
public void change()
{ if(state.equals("Ready"))
{ state="Move";
tx.setText(state);
}
else if(state.equals("Move"))
{ state="Stopped";
55

JNTUH

WEB TECHNOLOGIES

tx.setText(state);
}
else if(state.equals("Stopped"))
{
state="Ready";
tx.setText(state);
}}
public void propertyChange(PropertyChangeEvent e)
{
change();
}
private JTextField tx;
private String state;
}

TrafficLight.java

import java.awt.*;
import java.beans.*;
import java.io.*;
import java.util.Date;
public class TrafficLight extends Panel
implements Runnable, Serializable, PropertyChangeListener
{private Color color;
private Label label;
private PropertyChangeSupport changes;
private int interval;
transient Thread runner;

public TrafficLight()
{
56

JNTUH

WEB TECHNOLOGIES

setSize(50, 50);
color = Color.red;
label = new Label();
label.setSize(100,100);
label.setBackground(Color.red);
add(label);
changes = new PropertyChangeSupport(this);
changes.addPropertyChangeListener(this);
interval = 5;
runner = new Thread(this);
runner.start();
}
public void addPropertyChangeListener(PropertyChangeListener propertychangelistener)
{
changes.addPropertyChangeListener(propertychangelistener);
}
public void removePropertyChangeListener(PropertyChangeListener propertychangelistener)
{
changes.removePropertyChangeListener(propertychangelistener);
}
public int getInterval()
{
return interval;
}
public void setInterval(int i)
{
interval = i;
if(runner != null)
runner.interrupt();
}
public int getSeconds()
57

JNTUH

WEB TECHNOLOGIES

{
return (int)((new Date()).getTime() / 1000L);
}
public void run()
{
int i = getSeconds();

do
{
try
{
Thread.sleep(interval * 1000);
}
catch(InterruptedException interruptedexception) { }
int j = getSeconds();
changes.firePropertyChange("seconds", new Integer(i), new Integer(j));
i = j;
} while(true);
}
public void propertyChange(PropertyChangeEvent propertychangeevent)
{
if(color == Color.red)
{
label.setBackground(Color.orange);
color = Color.orange;
} else
if(color == Color.orange)
{
label.setBackground(Color.green);
color = Color.green;
} else
58

JNTUH

WEB TECHNOLOGIES

if(color == Color.green)
{
label.setBackground(Color.red);
color = Color.red;
}

}
}
1. Compile the source code for the Bean and generate the Traffic.class and
TrafficLight.class in the command prompt :
    javac Traffic.java
javac TrafficLight.java
2.

Create a manifest file in a text editor.
The manifest file specifies the name of the class file and indicates that it is a
JavaBean. The manifest file becomes part of the JAR file. You can name the
manifest file manifest1.man and manifest2.man . It contains the
following two lines:
manifest1.man
Name: Traffic.class
Java­Bean: True
manifest2.man
 Name: TrafficLight.class
Java­Bean: True

3.

Create the executable JAR file.
Use the form of the jar command to include the manifest file along with the
Traffic.class and TrafficLight.class file (Type the command on one line):
jar cf Traffic.jar manifest.man Traffic.class
jar cf TrafficLight.jar manifest.man TrafficLight.class

NetBean 6.1 IDE For Light JavaBean

59

JNTUH
ï‚·

ï‚·

ï‚·

ï‚·

WEB TECHNOLOGIES

Click File | New Project to create a new project, a grouping of related files. Follow
the wizard steps below.
1. Choose Project - General | Java Application
2. Name and Location - Uncheck Create Main Class, check Set as Main Project
Click File | New File to create a new file. Follow the wizard steps below.
1. Choose File Type - Java GUI Forms | JApplet Form
2. Class Name - Use Default
Installing Counter JavaBeans - JavaBeans that have been jarr'ed can be downloaded
and added to the Palette .
o Tools | Pallette Manager
1. Click Add from JAR
2. Select JAR file - Locate and select counterEvent.jar
3. Select Components - Highlight TrafficLight
4. Select Palette Category - Highlight Beans
o Beans should now contain TrafficLight class
Visual programming - Since applets are visual it is possible to program by dragging
and dropping components from the toolbar.
o Click Design tab.
o To see the layout manager:
 Right click in gray design area | Set Layout | Flow Layout
o To add a visual object, right click the gray area:
 Add From Palette | Swing | JButton
 Add From Palette | Beans | TrafficLight

Then the net beans IDE look like this:

To run : Shift+F6
60

JNTUH

WEB TECHNOLOGIES

61

JNTUH

WEB TECHNOLOGIES

SERVLETS (HELLOSERVLET)

HelloServlet.java
import java.io.*;
import javax.servlet.*;

public class HelloServlet extends GenericServlet
{
public void service(ServletRequest request, ServletResponse response)
throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter pw=response.getWriter();
pw.println("<h1>Hello!</h1>");
pw.close();
}
}
web.xml
<web-app>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>
</web-app>

62

JNTUH

WEB TECHNOLOGIES

63

JNTUH

WEB TECHNOLOGIES

SERVLETS (DATA RETREIVAL)
PostParameter.html
<!DOCTYPE html>
<html>
<body>
<form name="Form1" method="post" action="PostParameterServlet">
<table>
<tr>
<td>Employee</td>
<td><input type="text" name="e" size="25" value=""></td>
</tr>
<tr>
<td>Phone</td>
<td><input type="text" name="p" size="25" value=""></td>
</tr>
</table>
<input type=submit value="Submit">
</body>
</html>

PostParameterServlet.java
import java.io.*;
import javax.servlet.*;
import java.util.*;

public class PostParameterServlet extends GenericServlet
{
public void service(ServletRequest request, ServletResponse response)
throws ServletException ,IOException
{
response.setContentType("text/html");
64

JNTUH

WEB TECHNOLOGIES
PrintWriter pw=response.getWriter();
Enumeration e=request.getParameterNames();

while(e.hasMoreElements())
{
String pname=(String)e.nextElement();
pw.print(pname + "=");
String pvalue=request.getParameter(pname);
pw.println(pvalue);
}
pw.close();
}
}
web.xml
<web-app>
<servlet>
<servlet-name>PostParameterServlet</servlet-name>
<servlet-class>PostParameterServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>PostParameterServlet</servlet-name>
<url-pattern>/PostParameterServlet</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>PostParameter.html</welcome-file>
</welcome-file-list>
</web-app>

65

JNTUH

WEB TECHNOLOGIES

66

JNTUH

WEB TECHNOLOGIES

SERVLETS (USING COOKIES)
start.html
<html>
<body>
<form action="first.com" method="post">
<table>
<tr>
<td>Enter the number</td>
<td>

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

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

firstinfo.java
import java.sql.*;
import javax.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class firstinfo extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res) throws
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
67

JNTUH

WEB TECHNOLOGIES
String number = req.getParameter("num");
Cookie numasd = new Cookie("numa",number);
res.addCookie(numasd);
out.print("<html>");
out.print("<body>");
out.print("<form action=second.com
method=post>");
out.print("<table>");

out.print("<tr><td>Enter Second number</td><td><input
type=text name=secnum></td> </tr>");
out.print("<tr><td align=right><br><input type=submit
value=send></td></tr></table>");
out.print("</form></body></html>");
out.close();
}
}

secondinfo.java
import java.sql.*;
import javax.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class secondinfo extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res) throws
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String number = req.getParameter("secnum");

68

JNTUH

WEB TECHNOLOGIES
Cookie[] c = req.getCookies();
out.print("<html>");
out.print("<body>");
out.print("<table>");
for(int i=0;i<c.length;i++)
{
out.print("<tr><td>"+c[i].getName()+"</td>");
out.print("<td>"+c[i].getValue()+"</td></tr>");
}
out.print("</table>");
out.print(number);
out.print("</body>");
out.print("</html>");
out.close();
}

}

web.xml
<web-app>
<servlet>
<servlet-name>firstinfo</servlet-name>
<servlet-class>firstinfo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>firstinfo</servlet-name>
<url-pattern>/first.com</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>secondinfo</servlet-name>
<servlet-class>secondinfo</servlet-class>
69

JNTUH

WEB TECHNOLOGIES

</servlet>
<servlet-mapping>
<servlet-name>secondinfo</servlet-name>
<url-pattern>/second.com</url-pattern>
</servlet-mapping>
</web-app>

70

JNTUH

WEB TECHNOLOGIES

71

JNTUH

WEB TECHNOLOGIES

REQUEST DISPATCHER

login.html
<form action="go" method="get">
Name:<input type="text" name="userName"/><br/>
Password:<input type="password" name="userPass"/><br/>
<input type="submit" value="login"/>
</form>

Simple.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;

public class Simple extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String p=request.getParameter("userPass");
if(p.equals("servlet"))
{
RequestDispatcher rd=request.getRequestDispatcher("welcome");
rd.forward(request, response);
}
else{
out.print("Sorry username or password error!");
RequestDispatcher rd=request.getRequestDispatcher("login.html");
rd.include(request, response);
72

JNTUH

WEB TECHNOLOGIES
}

}
}

WelcomeServlet.java
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;

public class WelcomeServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("userName");
out.print("Welcome "+n);
}
}

web.xml

<web-app>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>Simple</servlet-name>
<servlet-class>Simple</servlet-class>
</servlet>
73

JNTUH

WEB TECHNOLOGIES

<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>WelcomeServlet</servlet-name>
<servlet-class>WelcomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Simple</servlet-name>
<url-pattern>/go</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>WelcomeServlet</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>login.html</welcome-file>
</welcome-file-list>
</web-app>

74

JNTUH

WEB TECHNOLOGIES

75

JNTUH

WEB TECHNOLOGIES

SERVLETS – SESSION TRACKING

index.html
<form action="servlet1">
Name:<input type="text" name="userName"/><br/>
<input type="submit" value="go"/>
</form>

FirstServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class FirstServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response){
try{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("userName");
out.print("Welcome "+n);
HttpSession session=request.getSession();
session.setAttribute("uname",n);
out.print("<a href='servlet2'>visit</a>");
out.close();
}catch(Exception e){System.out.println(e);}
}
}
SecondServlet.java
import java.io.*;
import javax.servlet.*;
76

JNTUH

WEB TECHNOLOGIES

import javax.servlet.http.*;

public class SecondServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
IOException,ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
HttpSession session=request.getSession(false);
String n=(String)session.getAttribute("uname");
out.print("Hello "+n);
out.close();
}
}

77

JNTUH

WEB TECHNOLOGIES

78

JNTUH

WEB TECHNOLOGIES

79

JNTUH

WEB TECHNOLOGIES

JSP (HELLO WORLD)

<html>
<head><title>Hello World JSP Page.</title></head>
<body>
<font size="10"><%="Hello World!" %></font>
</body>
</html>

80

JNTUH

WEB TECHNOLOGIES

JSP (DATA RETREIVAL)

hello.html
<html>
<body>
<form action="main.jsp" method="GET">
First Name: <input type="text" name="first_name">
<br />
Last Name: <input type="text" name="last_name" />
<input type="submit" value="Submit" />
</form>
</body>
</html>

main.jsp
<html>
<head>
<title>Using GET Method to Read Form Data</title>
</head>
<body>
<center>
<h1>Using GET Method to Read Form Data</h1>
<ul>
<li><p><b>First Name:</b>
<%= request.getParameter("first_name")%>
</p></li>
<li><p><b>Last Name:</b>
<%= request.getParameter("last_name")%>
</p></li>
</ul>
</body>
81

JNTUH

WEB TECHNOLOGIES

</html>

82

JNTUH

WEB TECHNOLOGIES

JSP(USING COOKIES)

Login.html
<body>
<form action=First.jsp method=post>
Enter Name : <input type="text" name="ename"><br>
Enter city : <input type="text" name="city"><br>
Enter age : <input type="text" name="age"><br>
<input type="submit" value="send">
</form>
</body>

First.jsp
<body>
<%
String ename=request.getParameter("ename");
String city=request.getParameter("city");
String age=request.getParameter("age");

Cookie cname=new Cookie("Employee_Name",ename);
Cookie ccity=new Cookie("Employee_City",city);
Cookie ccage=new Cookie("Employee_age",age);

response.addCookie(cname);
response.addCookie(ccity);
response.addCookie(ccage);
%>
<a href="readCookies.jsp">READ COOKIES </a>
</body>

readCookies.jsp
83

JNTUH

WEB TECHNOLOGIES

<body text=red>
<h1 align=center>Cookie Values Are ... </h1>
<hr>
<%
Cookie[] c=request.getCookies();
out.print("<table align=center>");
for(int i=0;i<c.length;i++){ out.print("<tr><td>"+c[i].getName()
+"</td><td>"+c[i].getValue()+"</td></tr>");}
%>
</body>

84

JNTUH

WEB TECHNOLOGIES

85

JNTUH

WEB TECHNOLOGIES

86

JNTUH

WEB TECHNOLOGIES

JSP USING JAVA BEANS
STUDENT DETAILS USING EXPRESSION TAGS

student.jsp
<jsp:useBean id="sb1" class="sp.StudBean"/>
<html>
<body>
<h2 style=color:blue>Student Details By using Expression tag<br>
sno=<%= sb1.getSno() %><br>
sname=<%= sb1.getSname() %><br>
saddr=<%= sb1.getMarks() %>
</h2>
</body>
</html>

StudBean.java
package sp;
public class StudBean
{
int sno;
String sname;
float marks;
public StudBean()
{
}
public void setSno(int sno)
{
this.sno=sno;
}
public int getSno()
{
87

JNTUH

WEB TECHNOLOGIES

return sno;
}
public void setSname(String sname)
{
this.sname=sname;
}
public String getSname()
{
return sname;
}
public void setMarks(float marks)
{
this.marks=marks;
}
public float getMarks()
{
return marks;
}
}

88

JNTUH

WEB TECHNOLOGIES

89

JNTUH

WEB TECHNOLOGIES

STUDENT DETAILS BY USING SET PROPERTY

student.jsp

<jsp:useBean id="sb1" class="sp.StudBean"/>
<html>
<body>
<h2 style=color:blue>Student Details By using set property<br>
<jsp:setProperty name="sb1" property="sno" value="100"/>
<jsp:setProperty name="sb1" property="sname" value="balu"/>
<jsp:setProperty name="sb1" property="marks" value="75.5"/>

sno=<jsp:getProperty name="sb1" property="sno"/><br>
sname=<jsp:getProperty name="sb1" property="sname"/><br>
marks=<jsp:getProperty name="sb1" property="marks"/>
</h2>
</body>
</html>

StudBean.java
package sp;
public class StudBean
{
int sno;
String sname;
float marks;
public StudBean()
{
}
public void setSno(int sno)
{
90

JNTUH

WEB TECHNOLOGIES

this.sno=sno;
}
public int getSno()
{
return sno;
}
public void setSname(String sname)
{
this.sname=sname;
}
public String getSname()
{
return sname;
}
public void setMarks(float marks)
{
this.marks=marks;
}
public float getMarks()
{
return marks;
}
}

91

JNTUH

WEB TECHNOLOGIES

92

JNTUH

WEB TECHNOLOGIES

JSP USING JAVA BEANS

bean.html
<html>
<body bgcolor="#CC9900">
<form action="bean.jsp" method="post">
<h2>
Enter Username:
<input type="text" name="name"><br>
Select Lanaguage:
<select name="lang">
<option value="java">java</option>
<option value=".net">.net</option>
<option value="c++">c++</option>
</select><br>
<input type="submit" value="submit">
</form>
</body>
</html>

bean.jsp
<jsp:useBean id="obj" class="tb.TechBean">
<jsp:setProperty name="obj" property="*"/>
</jsp:useBean>
<body bgcolor=#CC6633>
<h2>The result of bean values
name:
<jsp:getProperty name="obj" property="name"/><br>
language:
<jsp:getProperty name="obj" property="lang"/><br>
langComments:
93

JNTUH

WEB TECHNOLOGIES

<jsp:getProperty name="obj" property="langComments"/><br>
</h2>
</body>

TechBean.java
package tb;
public class TechBean
{
String name;
String lang;
public TechBean()
{
}
public void setName(String name)
{
this.name=name;
}
public String getName()
{
return name;
}
public void setLang(String lang)
{
this.lang=lang;
}
public String getLang()
{
return lang;
}
public String getLangComments()
{
94

JNTUH

WEB TECHNOLOGIES

if(lang.equals("java"))
{
return "king of oops";
}
if(lang.equals(".net"))
{
return "king of mstech";
}
if(lang.equals("c++"))
{
return "partialoops";
}
else
return "no idea";
}
}

95

JNTUH

WEB TECHNOLOGIES

96

JNTUH

WEB TECHNOLOGIES

CREATE TABLE USING JDBC
import java.sql.*;
public class create
{
public static void main(String args[])throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3307/sushma","root","root");
String qry="create table student11(sno int(5),sname varchar(20),saddr varchar(30))";
Statement st=con.createStatement();
int k=st.executeUpdate(qry);
st.close();
con.close();
}
}

INSERTING VALUES INTO TABLE USING JDBC
import java.sql.*;
97

JNTUH

WEB TECHNOLOGIES

public class insert
{
public static void main(String args[])throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3307/sushma","root","root");
String qry="insert into student1 values(11,'abc','def')";
Statement st=con.createStatement();
int k=st.executeUpdate(qry);
st.close();

con.close();
}
}

98

JNTUH

WEB TECHNOLOGIES

EXECUTION OF QUERY USING SERVLETS-JDBC
db.html
<html>
<body text=red>

<h2 align=center> DBExample Info </h2>
<hr>
<form action="db.com" method="post">
<table align=center>
<tr>
<td>Enter your query</td>
<td><input type="text" name="query"
size="50"></td><td><input type="submit" value="SEND"></td>
</tr>
</table>
</form>
</body>
</html>
DBServlet.java
import javax.servlet.http.*;
import javax.servlet.*;
import javax.sql.*;
import java.sql.*;
import java.io.*;
public class DBServlet extends HttpServlet
{ public void service(ServletRequest req,ServletResponse res) throws
ServletException,IOException
{
PrintWriter out=res.getWriter();
res.setContentType("text/html");

99

JNTUH

WEB TECHNOLOGIES
String query=req.getParameter("query");
//DBLogic
out.print("<body bgcolor=blue text=white>");
out.print("<hr><br><br>");

try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3307/sushma
","root","root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery(query);
ResultSetMetaData rsmd=rs.getMetaData();
out.print("<table align=center border=1>");
while(rs.next())
{ out.print("<tr>");
for(int c=1;c<=rsmd.getColumnCount();c++)
{
out.print("<td>"+rs.getString(c)+"</td>");}
out.print("</tr>"); }
out.print("</table>");
con.close();
st.close();
}
catch (Exception e)
{ out.print("<h1>"+e+"</h1>");}
out.close();
}
}

100

JNTUH

WEB TECHNOLOGIES

101

JNTUH

WEB TECHNOLOGIES

DYNAMIC WEB PAGES USING SERVLETS AND JDBC
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>
<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="login.html">LOGIN</a> <a href="reg.html">
REGISTRATION</a></div></pre>
</body>
</html>
login.html:
<html>
<body ><br /><br /><br />
<form name="myform" method="post" action="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" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>

reg.html:
<!DOCTYPE>
<html >
<body ><br /><br />
<form name="myform" method="post" action="reg">
<div align="center"><pre>
NAME :<input type="text" name="name" /><br />
ADDRESS :<input type="text" name="addr" /><br />
LOGINID :<input type="text" name="id" /><br />
PASSWORD :<input type="password" name="pwd" /></pre><br /><br />
<input type="submit" value="ok" />
102

JNTUH

WEB TECHNOLOGIES

</div>
</form>
</body>
</html>
catalog.html:
<!DOCTYPE >
<html xmlns="http://www.w3.org/1999/xhtml">
<body ><br /><br /><br />
<form method="post" action="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"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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">
<body ><br /><br />
<form method="post" action="reg">
<div align="center"><pre>
NAME :<input type="text" name="name" /><br />
PASSWORD :<input type="password" name="pwd" />
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"/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear"
name="button2"/>
</div>
</form>
</body>
</html>
103

JNTUH

WEB TECHNOLOGIES

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><br /><br /><br />
<form name="myform" method="post" action="profile">
<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" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div></form></body></html>
login.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(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body>");
String id=req.getParameter("id");
String pwd=req.getParameter("pwd");
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sushma","root","root");
Statement stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
if(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)
{
104

JNTUH

WEB TECHNOLOGIES

pw.println("SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\"login.html\">press LOGIN to RETRY</a>");
}
else
{
pw.println("VALID LOGIN ID<br>");
pw.println("<h3><ul>");
pw.println("<li><a href=\"profile.html\">USERPROFILE </a></li><br><br>");
pw.println("<li><a href=\"catalog.html\">BOOKSCATALOG</a></li><br><br>");
pw.println("<li><a href=\"order.html\">ORDERCONFIRMATION</a></li><br><br>");
}
pw.println("</body></html>");
}
catch(Exception e)
{ resp.sendError(500,e.toString());
}
}
}

profile.java
import java.sql.*;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class profile extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body >");
String id=req.getParameter("id");
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sushma","root","root");
Statement stmt=con.createStatement();
String sqlstmt="select * from login where id="+id+"";
ResultSet rs=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>");
105

JNTUH

WEB TECHNOLOGIES

pw.println("</div>");
flag=1;
}
if(flag==0)
{
pw.println("SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\"profile.html\">press HERE to RETRY</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}

reg.java:
import java.sql.*;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class reg extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body>");
String name=req.getParameter("name");
String addr=req.getParameter("addr");
String id=req.getParameter("id");
String pwd=req.getParameter("pwd");
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sushma","root","root");
Statement stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
106

JNTUH

WEB TECHNOLOGIES

{
if(id.equals(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>");
pw.println("<a href=\"reg.html\">press REGISTER to RETRY</a>");
}
else
{
Statement stmt1=con.createStatement();
stmt1.executeUpdate("insert into login values(' "+name+"' ,'"+addr+"',' "+id+"',' "+pwd+"
')");
pw.println("YOUR DETAILS ARE ENTERED<br><br>");
pw.println("<a href=\"login.html\">press LOGIN to login</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{ resp.sendError(500,e.toString());
} }}
catalog.java
import java.sql.*;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class catalog extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body >");
String title=req.getParameter("title");
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sushma","root","root");
Statement stmt=con.createStatement();
String sqlstmt="select * from books where title="+title+"";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
107

JNTUH

WEB TECHNOLOGIES

{
pw.println("<div align=\"center\">");
pw.println("TITLE :"+rs.getString(1)+"<br>");
pw.println("AUTHOR :"+rs.getString(2)+"<br>");
pw.println("COST :"+rs.getString(3)+"<br>");
pw.println("</div");
flag=1;
}
if(flag==0)
{
pw.println("SORRY INVALID TITLE TRY AGAIN <br><br>");
pw.println("<a href=\"catalog.html\">press HERE to RETRY</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
order.java:
import java.sql.*;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class order extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body >");
String id=req.getParameter("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");
int count=Integer.parseInt(count1);
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sushma","root","root");
108

JNTUH

WEB TECHNOLOGIES

Statement stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=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=\"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;
pw.println("AMOUNT :"+amount+"<br><br><br><br>");
Statement stmt1=con.createStatement();
stmt1.executeUpdate("insert into details values('"+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=\"order.html\">press HERE to RETRY</a>");
}
}
pw.println("</body></html>");
con.close();
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}

109

JNTUH

WEB TECHNOLOGIES

web.xml:
<web-app>
<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>
</servlet>
<servlet>
<servlet-name>order</servlet-name>
<servlet-class>order</servlet-class>
</servlet>
<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>
<servlet-mapping>
<servlet-name>order</servlet-name>
<url-pattern>/order</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>catalog</servlet-name>
<url-pattern>/catalog</url-pattern>
</servlet-mapping>
</web-app>
Output:

110

JNTUH

WEB TECHNOLOGIES

111

JNTUH

WEB TECHNOLOGIES

112

JNTUH

WEB TECHNOLOGIES

113

JNTUH

WEB TECHNOLOGIES

114

JNTUH

WEB TECHNOLOGIES

115

JNTUH

WEB TECHNOLOGIES

116

JNTUH

WEB TECHNOLOGIES

CATALOG-JDBC-INSERT & DISPLAY
<%@ page language="java" import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%
Connection conn=null;
ResultSet rs=null;
Statement stmt=null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=DriverManager.getConnection("jdbc:mysql://localhost:3307/Catalog_DB","root","root
");
stmt=conn.createStatement();
if(request.getParameter("action")!=null)
{
String Bname=request.getParameter("Bname");
String Bauth=request.getParameter("Bauth");
stmt.executeUpdate("insert into Catalog_table(name,author)
values('"+Bname+"','"+Bauth+"')");
rs=stmt.executeQuery("select * from Catalog_table");
%>
<html>
<body>
<center>
<h1>catalog page</h1>
<table border="1">
<tr>
<td>srno</td>
<td>bookname</td>
<td>author</td>
</tr>
<%
int num=1;
while(rs.next())
{
%>
<tr>
<td><%=num%></td>
<td><%=rs.getString("name")%></td>
<td><%=rs.getString("author")%></td>
</tr>
<%
num++;
}
rs.close();
stmt.close();
117

JNTUH

WEB TECHNOLOGIES

%>
</table>
</center>
</body>
</html>
<%
}else{
%>
<html>
<body>
<center>
<form action="Catalog.jsp" method="post" name="entry">
<input type="hidden" value="list" name="action">
<table border="2">
<tr>
<td>
<table>
<tr>
<td>BOOK Name</td>
<td><input name="Bname" type="text"></td>
</tr>
<tr>
<td>BOOK author</td>
<td><input name="Bauth" type="text"></td>
</tr>
<tr>
<td><input type="submit" value="submit"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
<% } %>

118

JNTUH

WEB TECHNOLOGIES

119

JNTUH

WEB TECHNOLOGIES

CREATE A DATABASE WITH BOOKS INFORMATION. THE BOOKS
CATALOGUE SHOULD BE DYNAMICALLY LOADED FROM THE DATABASE.
catret.jsp
<%@ page language="java" import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%
Connection conn=null;
ResultSet rs=null;
Statement stmt=null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=DriverManager.getConnection("jdbc:mysql://localhost:3307/Catalog_DB","root","root
");
if(request.getParameter("action")!=null)
{
String Bname1=request.getParameter("Bname");
stmt=conn.createStatement();
String sqlstmt="select * from Catalog_table where name='"+Bname1+"'";
rs=stmt.executeQuery(sqlstmt);
%>
<html>
<body>
<center>
<h1>catalog page</h1>
<table border="1">
<tr>
<td>srno</td>
<td>bookname</td>
<td>author</td>
</tr>
<%
while(rs.next())
{
%>
<tr>
<td><%=rs.getString("id")%></td>
<td><%=rs.getString("name")%></td>
<td><%=rs.getString("author")%></td>
</tr>
<%
}
rs.close();
120

JNTUH

WEB TECHNOLOGIES

stmt.close();
%>
</table>
</center>
</body>
</html>
<%
}else{
%>
<html>
<body>
<h1>enter the book name</h1>
<form action="catret.jsp" method="get" name="entry">
<input type="hidden" value="list" name="action">
<input type="text" name="Bname">
<br>
<input type="submit" value="submit">
</form>
</body>
</html>
<% } %>

121

JNTUH

WEB TECHNOLOGIES

122

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close