All Programs WT
All Programs WT
AIM: Design the following static web pages required for an online book store web site.
1) 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.
CSE
ECE Description of the Web Site
EEE
CIVIL
Fig 1.1
2) LOGIN PAGE:
Submit Reset
3) 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:
EEE
Book : AI $ 63
CIVIL Author : S.Russel
Publication :
Princeton hall
Book : HTML in 24 $ 50
hours
Author : Sam Peter
Publication : Sam
publication
Source Code
Index.html
<frameset rows="200px,*">
<frame src="top.html" />
<frameset cols="150px,*">
<frame src="left.html" />
<frame src="home.html" name="body" id="body" />
</frameset>
</frameset>
Top.html
<html>
<head>
<title>Top Page</title>
</head>
<body>
<table width="100%">
<tr><td><img src="images/logo.jpg" alt="logo" /></td><td
colspan="4"><h1>ONLINE BOOK STORE </h1></td>
</tr><tr><td><br><br></td></tr>
<tr ><td><a href="home.html" target="body">HOME</a></td>
<td><a href="login.html" target="body">Login</a></td><td><a
href="registration.html" target="body">Registration</a></td>
<td><a href="catalogue.html" target="body">Catalogue</a></td>
<td><a href="cart.html" target="body">Cart</a></td>
</tr>
</table>
</body>
</html>
Left.html
<html>
<head>
<title>Top Page</title>
</head>
<body>
<a href="cse.html" target="body">CSE</a><br />
<a href="ece.html" target="body">ECE</a><br />
<a href="eee.html" target="body">EEE</a><br />
<a href="civil.html" target="body">CIVIL</a><br />
</body>
</html>
Login.html
<html>
<head>
<title>Login Page</title>
</head>
<body>
Username: <input name="uname" type="text" /><br />
Password: <input type="text" name="password" /><br />
<input type="submit" value="Submit" /> <input type="reset" value="Reset" />
</body>
</html>
Catalogue.html
<html>
<head>
<title>Catalogue Page</title>
</head>
<body>
<table>
<tr><td><img src="images/xml.jpg" /><br /><br /></td>
<td>Book : XML Bible<br />Author : Winston<br />Publication : Wiely<br /></td>
<td>$ 40.5</td>
<td><input type="image" src="images/cart.jpg" /></td></tr>
<tr><td><img src="images/ai.jpg" /><br /><br /></td>
<td>Book : AI<br />Author : S.Russel<br />Publication : Princeton hall</td><td>$
63</td><td><input type="image" src="images/cart.jpg" /></td></tr>
<tr><td><img src="images/java.jpg" /><br /><br /></td>
<td>Book : Java 2<br />Author : Watson<br />Publication : BPB publications</td>
<td>$ 35.5</td><td><input type="image" src="images/cart.jpg" /></td></tr>
<tr><td><img src="images/html.jpg" /><br /><br /></td>
<td>Book : HTML in 24 hours<br />Author : Sam Peter<br />Publication : Sam
publication</td>
<td>$ 50</td><td><input type="image" src="images/cart.jpg" /></td></tr>
</table>
</body>
</html>
Home.html
<html>
<head>
<title>Home Page</title>
</head>
Description of Online Book Store
</body>
</html>
Execution Procedure
Step1: type all html programs in notepad or any text editor and save .html format.
Step2: open web browser and open index.html
Step3: traverse all pages from index.html.
EXP NO: 2
Aim: Design the following static web pages required for an online book store web site.
i. Registration Page ii. Cart Page
CART PAGE:
The cart page contains the details about the books which are added to the cart.
5) REGISTRATION PAGE:
Description
Through table and form tag we can design pages.
The form tag you can add to your web pages a guestbook, order forms, surveys, get feedback or
whatever. The basic construction of a html form is this...
<FORM> begin a form
<INPUT> ask for information in one of several different ways...
<INPUT> ...there can be as many input areas as you wish
</FORM> end a form
<TABLE>
The main tag. Used to tell the browser "this is a table", along with some attributes like size,
border width and a few other things.
<TR>
TableRow defines a horizontal row of <TD> (TableData) cells.
<TD>
Specifies an indiviual block or cell in a table row
Source Code
Registraion.html
<HTML>
<HEAD>
</HEAD>
<BODY bgcolor='#999900'>
<form name='register' action='register.jsp' onsubmit="return validate(this);">
<table align='center' cellspacing='20'>
<tr>
<td>Enter Name</td>
<td><input type='text' name="name"></td>
</tr>
<tr>
<td>Enter Password</td>
<td><input type='password' name="password"></td>
</tr>
<tr>
<td>Enter Email</td>
<td><input type='text' name="email"></td>
</tr>
<tr>
<td>Select Gender</td>
<td>
Male<input type='radio' name="gender" value='male'>
Female<input type='radio' name="gender" value='female'>
Other<input type='radio' name="gender" value='other'>
</td>
</tr>
<tr>
<td>Date of birth</td>
<td>
<select name='date'>
<option value='---date----'>date</option>
<script>
for(i=1;i<=31;i++)
document.write("<option value="+i+">"+i+"</option>")
</script>
</select>
<select name='month'>
<option value='---month---'>month</option>
<script>
for(i=1;i<=12;i++)
document.write("<option value="+i+">"+i+"</option>")
</script>
</select>
<select name="year">
<option value='---year---'>year</option>
<script>
for(i=1900;i<=2100;i++)
document.write("<option value="+i+">"+i+"</option>")
</script>
</select>
</td>
</tr>
<tr>
<td>Languages Known</td>
<td>
Telugu<input type='checkbox' name='telugu' value='telugu'>
Hindhi<input type='checkbox' name='hindhi' value='hidhi'>
Tamil<input type='checkbox' name='tamil' value='tamil'>
English<input type='checkbox' name='english' value='english'>
</td>
</tr>
<tr>
<td>Address</td>
<td><textarea name='address' rows='5' cols='25'></textarea></td>
</tr>
<tr>
<td>Mobile Number</td>
<td><input type="text" name="mobile"></td>
</tr>
<tr>
<td>
<input type='submit' value='Register'>
</td>
<td>
<input type='reset' value='Clear'>
</td>
</tr>
</table>
</form>
</BODY>
</HTML>
Output:
Cart.html
<html>
<head>
<title>Cart Page</title>
</head>
<body>
<table ><tr><th>Book name</th><th>Price</th><th>Quantity</th><th>Amount</th></tr>
<tr><td>Java 2</td><td>$35.5</td><td>2</td><td>$70</td></tr>
<tr><td>XML bible</td><td>$40.5</td><td>1</td><td>$40.5</td></tr>
<tr><td colspan="3" align="right"><b>Total amount -</b></td><td>$130.5</td></tr>
</table>
</body>
</html>
CSE.html
<html>
<head>
<title>CSE Page</title>
</head>
Ece.html
<html>
<head>
<title>ECE Page</title>
</head>
Eee.html
<html>
<head>
<title>EEE Page</title>
</head>
Civil.html
<html>
<head>
<title>CIVIL Page</title>
</head>
Source code:
<HTML>
<HEAD>
<style type="text/css">
p.right
{
text-align:right;
font-size:30pt;
color:red;
text-transform:uppercase;
font-style:italic;
font-family:Bookman old style;
}
p.center
{
text-align:center;
font-size:25pt;
color:green;
text-decoration:overline;
text-transform:lowercase;
font-family:arial;
}
p.left
{
text-align:left;
font-size:20pt;
color:blue;
text-decoration:underline;
font-family:calibri;
}
h1.center
{
text-align:center;
color:maroon;
text-decoration:line-through;
text-transform:capitalize;
font-family:Bookman old style;
}
p.cls
{
font-size:15pt;
color:red;
word-spacing:50;
letter-spacing:-2;
}
</style>
</HEAD>
<BODY>
<p class="right">This is paragraph 1</p>
<p class="center">This is paragraph 2</p>
<p class="left">This is paragraph 3</p>
<h1 class="center">this is heading 1</h1>
<p class="cls">This is paragraph 4</p>
</BODY>
</HTML>
Output:
2) Set a background image for both the page and single elements on the page. You can define the
background image for the page like this:
BODY {background-image:url(myimage.gif),}
Source code:
<HTML>
<HEAD>
<style type='text/css'>
body
{
background-image:url(college.jpg);
background-repeat:no-repeat;
}
p
{
background-image:url(logo.jpg);
background-repeat:no-repeat;
font-size:30pt;
text-align:right;
background-position:top right;
}
</style>
</HEAD>
<BODY>
<p>This is paragraph 1</p>
</BODY>
</HTML>
Output:
<BODY>
<H1>Defining styles for Links</H1>
<p>Here you can change default properties of the link</p>
<a href="https://www.twitter.com">Twitter</a>
</BODY>
</HTML>
Output:
LAYER 2 ON TOP:
<div style="position:relative, font-size:50px, z-index:3,">LAYER 1</div> <div
style="position:relative, top:-50, left:5, color:red, font-size:80px, z-
index:4">LAYER 2</div>
Source code:
<HTML>
<HEAD>
</HEAD>
<BODY>
<strong>This is layer1</strong>
<div style="z-index:2;position:relative;font-size:30pt;color:orange">Top Layer 1</div>
<div style="z-index:1;position:relative;top:-30px;font-size:30pt;color:green">Bottom Layer1</div>
<strong>This is layer2</strong>
<div style="z-index:3;position:relative;font-size:30pt;color:orange">Top Layer 2</div>
<div style="z-index:4;position:relative;top:-30px;font-size:30pt;color:green">Bottom Layer
2</div>
</BODY>
</HTML>
Output:
<body>
<b>
<a href="mypage.htm" class="xlink">CROSS LINK</a>
<br>
<a href="mypage.htm" class="hlink">HELP LINK</a>
</b>
</body>
</html>
Source code:
<HTML>
<HEAD>
<style type="text/css">
*
{
text-align:center;
}
</style>
</HEAD>
<BODY>
<a href="https://www.gmail.com" style="cursor:wait">Wait cursor</a><br>
<a href="https://www.gmail.com" style="cursor:crosshair">cross hair cursor</a><br>
<a href="https://www.gmail.com" style="cursor:text">text cursor</a><br>
<a href="https://www.gmail.com" style="cursor:e-resize">Resize cursor</a><br>
<a href="https://www.gmail.com" style="cursor:move">Move cursor</a><br>
<a href="https://www.gmail.com" style="cursor:help">Help cursor</a><br>
<a href="https://www.gmail.com" style="cursor:ne-resize">Ne resize cursor</a><br>
<a href="https://www.gmail.com" style="cursor:se-resize">se resize cursor</a><br>
</BODY>
</HTML>
Output:
EXP NO: 4
AIM:
i. Write a JavaScript to validate the fields of the login page.
ii. Write a JavaScript to validate the fields of the Registration page
Description
JavaScript is a lightweight interpreted programming language with rudimentary object-oriented
capabilities. Syntactically, the core JavaScript language resembles C, C++ and Java, with
programming constructs such as the if statement, the while loop, and the && operator. The
similarity ends with this syntactic resemblance, however. JavaScript is an untyped language,
which means that variables do not have to have a type specified.
The <SCRIPT> and </SCRIPT> tags are used to embed JavaScript code within an HTML file.
Source Code:
Registration.html:
<HTML>
<HEAD>
<script>
function validate()
if(register.name.value=="")
register.name.focus();
return false;
if(register.name.value.length<8)
register.name.focus();
return false;
if(register.password.value=="")
{
register.password.focus();
return false;
if(register.password.value.length<10)
register.name.focus();
return false;
var x=register.email.value;
var atpos=x.indexOf("@");
var at2pos=x.lastIndexOf("@");
var dotpos=x.lastIndexOf(".");
if(atpos<1||(atpos!=at2pos)||dotpos<1||atpos+2>dotpos||dotpos+2>=x.length)
register.email.focus();
return false;
if(register.gender.value=="")
register.gender.focus();
return false;
if(isNaN(register.date.value)||isNaN(register.month.value)||isNaN(register.year.value))
register.date.focus();
return false;
if((register.telugu.checked==false)&&(register.hindhi.checked==false)&&(register.tamil.
checked==false)&&(register.english.checked==false))
register.telugu.focus();
return false;
if(register.address.value=="")
register.address.focus();
return false;
if(register.address.value.length<50)
return false;
if(isNaN(register.mobile.value))
register.mobile.focus();
return false;
if((register.mobile.value.length<10)||(register.mobile.value.length>10))
register.mobile.focus();
return false;
return true;
</script>
</HEAD>
<BODY bgcolor='#999900'>
<tr>
<td>Enter Name</td>
<tr>
<td>Enter Password</td>
</tr>
<tr>
<td>Enter Email</td>
</tr>
<tr>
<td>Select Gender</td>
<td>
</td>
</tr>
<tr>
<td>Date of birth</td>
<td>
<select name='date'>
<option value='---date----'>date</option>
<script>
for(i=1;i<=31;i++)
document.write("<option value="+i+">"+i+"</option>")
</script>
</select>
<select name='month'>
<option value='---month---'>month</option>
<script>
for(i=1;i<=12;i++)
document.write("<option value="+i+">"+i+"</option>")
</script>
</select>
<select name="year">
<option value='---year---'>year</option>
<script>
for(i=1900;i<=2100;i++)
document.write("<option value="+i+">"+i+"</option>")
</script>
</select>
</td>
</tr>
<tr>
<td>Languages Known</td>
<td>
</tr>
<tr>
<td>Address</td>
</tr>
<tr>
<td>Mobile Number</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
</table>
</form>
</BODY>
</HTML>
Output:
ii)Login.html:
<HTML>
<HEAD>
<script>
function validate()
var x=login.email.value;
var atpos=x.indexOf("@");
var at2pos=x.lastIndexOf("@");
var dotpos=x.lastIndexOf(".");
if(atpos<1||(atpos!=at2pos)||dotpos<1||atpos+2>dotpos||dotpos+2>=x.length)
return false;
if(login.password.value=="")
login.password.focus();
return false;
if(login.password.value.length<10)
login.password.focus();
return false;
return true;
</script>
</HEAD>
<BODY bgcolor='#999900'>
<center>
<table>
</tr>
</table>
</form>
</center>
</BODY>
</HTML>
Output:
Week 5
Aim:
Write an XML file which will display the Book information which includes the following:
1) Title of the book
2) Author Name
3) ISBN number
4) Publisher name
5) Edition
6) Price
Write a Document Type Definition (DTD) to validate the above XML file.
Display the XML file as follows.
The contents should be displayed in a table. The header of the table should be in color GREY. And the
Author names column should be displayed in one color and should be capitalized and in bold. Use your
own colors for remaining columns.
Use XML schemas XSL and CSS for the above purpose.
Note: Give at least for 4 books. It should be valid syntactically.
Hint: You can use some xml editors like XML-spy
Description
Extensible Markup Language (XML) is a meta-markup language that provides a format for
describing structured data. This facilitates more precise declarations of content and more
meaningful search results across multiple platforms. In addition, XML is enabling a new
generation of Web-based data viewing and manipulation applications.
In the HTML you use tags to tell the browser to display data as bold or italic; in XML you use
tags only to describe data, such as city name, temperature, and barometric pressure. In XML, you
use style sheets such as Extensible Stylesheet Language (XSL) and Cascading Style Sheets
(CSS) to present the data in a browser. XML separates the data from the presentation and the
process, enabling you to display and process the data as you wish by applying different style
sheets and applications.
Source Code
a) Demonstrating DTD file
book.dtd
<!ELEMENT BOOKS (book)>
<!ELEMENT book (title,auther,ISBNnumber,publishername,editior,price)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT auther (#PCDATA)>
<!ELEMENT ISBNnumber (#PCDATA)>
<!ELEMENT publishername (#PCDATA)>
<!ELEMENT editor (#PCDATA)>
<!ELEMENT price (#PCDATA)>
Books1.xml
<?xml version="1.0" ?>
<!DOCTYPE books SYSTEM "books.dtd">
<books>
<book>
<title>java server page</title>
<author>hans bergsten</author>
<isbn>81-265</isbn>
<publisher>O'relilly</publisher>
<edition>second</edition>
<price>200</price>
</book>
<book>
<title>c</title>
<author>balaguruswamy</author>
<isbn>81-695</isbn>
<publisher>tata</publisher>
<edition>second</edition>
<price>400</price>
</book>
<book>
<title>web program</title>
<author>chirs bates</author>
<isbn>81-265</isbn>
<publisher>wiley</publisher>
<edition>second</edition>
<price>300</price>
</book>
</books>
b) Demonstrating XSD
books.css
books
{
color:orange;
}
book
{
color:Red;
}
title
{
color:blue;
font-weight:bold;
margin-left:10pt;
display:block;
}
author
{
color:red;
font-weight:bold;
margin-left:10pt;
}
isbn
{
color:green;
font-weight:bold;
margin-left:10pt;
}
edition
{
color:red;
font-weight:bold;
margin-left:10pt;
}
publisher
{
color:green;
font-weight:bold;
margin-left:10pt;
}
Books.xsd
Books.xsl
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="books.css"?>
<books xmlns:xsi="http:www.w3.org/2001/xmlschema-instance"
xsi:noNamespaceSchemaLocation="books.xsd">
<book>
<title>web program</title>
<author>chirs bates</author>
<isbn>81-265</isbn>
<publisher>wiley</publisher>
<edition>second</edition>
<price>300</price>
</book>
<book>
<title>java server page</title>
<author>hans bergsten</author>
<isbn>81-265</isbn>
<publisher>O'relilly</publisher>
<edition>second</edition>
<price>200</price>
</book>
<book>
<title>c</title>
<author>balaguruswamy</author>
<isbn>81-695</isbn>
<publisher>tata</publisher>
<edition>second</edition>
<price>400</price>
</book>
</books>
c) Demonstrating XSL
books.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title> books</title></head>
<body>
<table border="1">
<tr><th>title</th>
<th> auther</th>
<th> isbn</th>
<th>publisher</th>
<th>edition</th>
<th>price</th>
</tr>
<xsl:for-each select="/books/book">
<tr>
<td bgcolor="green"><xsl:value-of select="title"/></td>
<td bgcolor="red"><xsl:value-of select="author"/></td>
<td bgcolor="cyan"><xsl:value-of select="isbn"/></td>
<td bgcolor="yellow"><xsl:value-of select="publisher" /></td>
<td bgcolor="silver"><xsl:value-of select="edition" /></td>
<td bgcolor="blue"><xsl:value-of select="price" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Books3.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="books.xsl"?>
<books>
<book>
<title>java server page</title>
<author>hans bergsten</author>
<isbn>81-265</isbn>
<publisher>O'relilly</publisher>
<edition>second</edition>
<price>200</price>
</book>
<book>
<title>c</title>
<author>balaguruswamy</author>
<isbn>81-695</isbn>
<publisher>tata</publisher>
<edition>second</edition>
<price>400</price>
</book>
<book>
<title>web program</title>
<author>chirs bates</author>
<isbn>81-265</isbn>
<publisher>wiley</publisher>
<edition>second</edition>
<price>300</price>
</book>
</books>
Execution Procedure
Step1: Type all html programs in notepad or any text editor and save the files.
Step2: open appropriate xml files in web browser for getting output.
Output
ii. Write a PHP program to validate the fields of the Registration page
i) AIM: create a login page using HTML and process the login form in PHP using
super globals ($_GET or $_POST ) and validate the fields.
Login.html:
<html>
<head>
<title></title>
</head>
<body>
<form name='form' action='loginvalidation.php' method='get'>
<table>
<tr>
<td>Enter Name</td>
<td><input type='text' name='name'></td>
</tr>
<tr>
<td>Enter Password</td>
<td><input type='password' name='password'></td>
</tr>
<tr>
<td><input type='submit' value='login'></td>
</tr>
</table>
</form>
</body>
</html>
Loginvalidation.php:
<?php
//Reading Login Form using $_GET
$name=$_GET['name'];
$password=$_GET['password'];
$flag=true;
$msg="";
if($name=="")
{
$flag=false;
$msg="<h1>Please enter your name</h1>";
}
else if(strlen($name)<6)
{
$flag=false;
$msg="<h1>Name should be minimum 6 characters</h1>";
}
else if($password=="")
{
$flag=false;
$msg="<h1>Please enter your password</h1>";
}
else if(strlen($password)<6)
{
$flag=false;
$msg="<h1>Pasword should be minimum 6 characters</h1>";
}
else
{
echo "<h1>Login Success</h1>";
}
if(!$flag)
{
echo $msg;
}
?>
Output:
Open browser and type:
http://localhost/loginvalidation/login.html
register.html:
<html>
<head>
<title></title>
</head>
<body>
<form name='form' action='registervalidation.php' method='post'>
<table>
<tr>
<td>Enter Name</td>
<td><input type='text' name='name'></td>
</tr>
<tr>
<td>Enter Password</td>
<td><input type='password' name='password'></td>
</tr>
<tr>
<td>Enter Email</td>
<td><input type='text' name='email'></td>
</tr>
<tr>
<td>Enter Mobile</td>
<td><input type='text' name='mobile'></td>
</tr>
<tr>
<td>Enter Address</td>
<td>
<textarea name="address" cols="22" rows="5"></textarea>
</td>
</tr>
<tr>
<td><input type='submit' value='register'></td>
</tr>
</table>
</form>
</body>
</html>
Registervalidation.php:
<?php
//Reading Login Form using $_GET
$name=$_POST['name'];
$password=$_POST['password'];
$email=$_POST['email'];
$mobile=$_POST['mobile'];
$address=$_POST['address'];
$flag=true;
$msg="";
if($name=="")
{
$flag=false;
$msg="<h1>Please enter your name</h1>";
}
else if($password=="")
{
$flag=false;
$msg="<h1>Please enter your password</h1>";
}
else if($email=="")
{
$flag=false;
$msg="<h1>Please enter your email</h1>";
}
else if($mobile=="")
{
$flag=false;
$msg="<h1>Please enter your mobile</h1>";
}
else if($address=="")
{
$flag=false;
$msg="<h1>Please enter your address</h1>";
}
else
{
echo "<h1>Registration Success</h1>";
}
if(!$flag)
{
echo $msg;
}
?>
Output:
Open browser and type:
http://localhost/registervalidation/register.html
DESCRIPTION:
Login.html:
<HTML>
<HEAD>
</HEAD>
<BODY bgcolor='#999900'>
<center>
<form name='login' action='retrieve.jsp' method="post">
<table>
<tr><td colspan='2' align='center'><h2>Login Page</h2></td></tr>
<tr><td>Enter Name</td><td><input type='text' name='name'></td></tr>
<tr><td>Enter Password</td><td><input type='password'
name='password'></td></tr>
<tr><td><input type='submit' value='Login'></td>
<td><input type='reset' value='Reset'></td>
</tr>
</table>
</form>
</center>
</BODY>
</HTML>
Retrieve.jsp:
<%@page import="java.sql.*"%>
<%
String name=request.getParameter("name");
String password=request.getParameter("password");
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/gec","root","root");
PreparedStatement ps=con.prepareStatement("select * from register where name=? and
password=?");
ps.setString(1,name);
ps.setString(2,password);
ResultSet rs=ps.executeQuery();%>
<%if(rs.next())
{%>
<center>
<table border='1'>
<tr>
<th>Name</th>
<th>Email</th>
<th>Gender</th>
<th>Date of Birth</th>
<th>Known Languages</th>
<th>Address</th>
<th>Mobile Number</th>
</tr>
<tr>
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
<td><%=rs.getString(6)%></td>
<td><%=rs.getString(7)%></td>
<td><%=rs.getString(8)%></td>
</tr>
<%}
else
{
out.println("Incorrect username or password");
}
%>
</table>
<center>
<%
}
catch(Exception e)
{
out.println(e);
}
%>
Save these files in the Root folder and Paste the Root folder in the following location:
D:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps
Run the server from following location:
D:\Program Files\Apache Software Foundation\Tomcat 7.0\bin
Now open the browser and type:
http://localhost:2025/Retrieve%20JSP/login.html
Output:
WEEK 8: Design a JSP to insert the details of the users who register through
the registration page and store the details in to the database.
DESCRIPTION:
Registration.html:
<HTML>
<HEAD>
<script>
function validate()
{
if(register.name.value=="")
{
alert("Please enter name...");
register.name.focus();
return false;
}
if(register.name.value.length<8)
{
alert("name should be minimum 8 characters....");
register.name.focus();
return false;
}
if(register.password.value=="")
{
alert("Please enter password...");
register.password.focus();
return false;
}
if(register.password.value.length<8)
{
alert("password should be minimum 8 characters....");
register.password.focus();
return false;
}
var x=register.email.value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
var at2pos=x.lastIndexOf("@");
if(atpos<1||dotpos<1||(atpos!=at2pos)||atpos+2>dotpos||dotpos+2>=x.length)
{
alert("Please enter valid email address");
register.email.focus();
return false;
}
if(register.gender.value=="")
{
alert("Please select gender");
register.gender.focus();
return false;
}
if(isNaN(register.date.value)||isNaN(register.month.value)||isNaN(register.ye
ar.value))
{
alert("Invalid date of birth");
register.date.focus();
return false;
}
if((register.telugu.checked==false)&&(register.hindhi.checked==false)&&(r
egister.tamil.checked==false)&&(register.english.checked==false))
{
alert("Please select languages");
register.telugu.focus();
return false;
}
if(register.addr.value=="")
{
alert("Please enter address");
register.addr.focus();
return false;
}
if(isNaN(register.mobile.value))
{
alert("Please enter digits only");
register.mobile.focus();
return false;
}
if((register.mobile.value=="")||(register.mobile.value.length>10)||(register.m
obile.value.length<10))
{
alert("Please enter valid mobile number");
register.mobile.focus();
return false;
}
return true;
}
</script>
</HEAD>
<BODY bgcolor='#999900'>
<form name='register' action='registration.jsp' onsubmit="return
validate(this);">
<table align='center' cellspacing='20'>
<tr>
<td>Enter Name</td>
<td><input type='text' name="name"></td>
</tr>
<tr>
<td>Enter Password</td>
<td><input type='password' name="password"></td>
</tr>
<tr>
<td>Enter Email</td>
<td><input type='text' name="email"></td>
</tr>
<tr>
<td>Select Gender</td>
<td>
Male<input type='radio' name="gender" value='male'>
Female<input type='radio' name="gender" value='female'>
Other<input type='radio' name="gender" value='other'>
</td>
</tr>
<tr>
<td>Date of birth</td>
<td>
<select name='date'>
<option value='---date----'>date</option>
<script>
for(i=1;i<=31;i++)
document.write("<option value="+i+">"+i+"</option>");
</script>
</select>
<select name='month'>
<option value='---month---'>month</option>
<script>
for(i=1;i<=12;i++)
document.write("<option value="+i+">"+i+"</option>");
</script>
</select>
<select name="year">
<option value='---year---'>year</option>
<script>
for(i=1900;i<=2100;i++)
document.write("<option value="+i+">"+i+"</option>");
</script>
</select>
</td>
</tr>
<tr>
<td>Languages Known</td>
<td>
Telugu<input type='checkbox' name='telugu' value='telugu'>
Hindhi<input type='checkbox' name='hindhi' value='hindhi'>
Tamil<input type='checkbox' name='tamil' value='tamil'>
English<input type='checkbox' name='english' value='english'>
</td>
</tr>
<tr>
<td>Address</td>
<td><textarea name="addr" rows='5' cols='25'></textarea></td>
</tr>
<tr>
<td>Mobile Number</td>
<td><input type='text' name="mobile"></td>
</tr>
<tr>
<td>
<input type='submit' value='Register'>
</td>
<td>
<input type='reset' value='Clear'>
</td>
</tr>
</table>
</form>
</BODY>
</HTML>
Registration.jsp:
<%@page import="java.sql.*"%>
<%
String name=request.getParameter("name");
String password=request.getParameter("password");
String email=request.getParameter("email");
String gender=request.getParameter("gender");
String date=request.getParameter("date");
String month=request.getParameter("month");
String year=request.getParameter("year");
String telugu=request.getParameter("telugu");
String hindhi=request.getParameter("hindhi");
String english=request.getParameter("english");
String tamil=request.getParameter("tamil");
String addr=request.getParameter("addr");
String mobile=request.getParameter("mobile");
String languages="";
if(telugu!=null)
{
languages=languages+telugu+",";
}
if(hindhi!=null)
{
languages=languages+hindhi+",";
}
if(english!=null)
{
languages=languages+english+",";
}
if(tamil!=null)
{
languages=languages+tamil+",";
}
//Connection to database
Class.forName("com.mysql.jdbc.Driver");
Connection
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/gec","root","roo
t");
PreparedStatement ps=conn.prepareStatement("insert into register
values(?,?,?,?,?,?,?,?)");
ps.setString(1,name);
ps.setString(2,password);
ps.setString(3,email);
ps.setString(4,gender);
ps.setString(5,date+"-"+month+"-"+year);
ps.setString(6,languages);
ps.setString(7,addr);
ps.setString(8,mobile);
int i=ps.executeUpdate();
if(i!=0)
{
out.println("<h1>Registered Successfully.....</h1>");
}
conn.close();
%>
AIM: Use PHP to MySQL database connection steps and retrieve the data from the register table
and display to the user.
Login.html:
<HTML>
<HEAD>
</HEAD>
<BODY bgcolor='#999900'>
<center>
<table>
</tr>
</table>
</form>
</center>
</BODY>
</HTML>
Login.php:
<?php
//Reading Values from form
$name =$_POST['name'];
$password =$_POST['password'];
$dbhost = "localhost:3306";
$dbuser = "root";
$dbpass = "root";
if (!$conn) {
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<center>
<table border='1'>
<tr>
<th>Name</th>
<th>Email</th>
<th>Gender</th>
<th>Date of Birth</th>
<th>Known Languages</th>
<th>Address</th>
<th>Mobile Number</th>
</tr>";
while($row = $result->fetch_assoc()) {
echo "<tr>
<td>".$row["name"]."</td>
<td>".$row["email"]."</td>
<td>".$row["gender"]."</td>
<td>".$row["dob"]."</td>
<td>".$row["languages"]."</td>
<td>".$row["addr"]."</td>
<td>".$row["mobile"]."</td>
</tr>";
echo "</table>";
else
$conn->close();
?>
Output:
Registration.html:
<HTML>
<HEAD>
</HEAD>
<BODY bgcolor='#999900'>
<form name='register' method="post" action='register.php' onsubmit="return
validate(this);">
<table align='center' cellspacing='20'>
<tr>
<td>Enter Name</td>
<td><input type='text' name="name"></td>
</tr>
<tr>
<td>Enter Password</td>
<td><input type='password' name="password"></td>
</tr>
<tr>
<td>Enter Email</td>
<td><input type='text' name="email"></td>
</tr>
<tr>
<td>Select Gender</td>
<td>
Male<input type='radio' name="gender" value='male'>
Female<input type='radio' name="gender" value='female'>
Other<input type='radio' name="gender" value='other'>
</td>
</tr>
<tr>
<td>Date of birth</td>
<td>
<select name='date'>
<option value='---date----'>date</option>
<script>
for(i=1;i<=31;i++)
document.write("<option value="+i+">"+i+"</option>");
</script>
</select>
<select name='month'>
<option value='---month---'>month</option>
<script>
for(i=1;i<=12;i++)
document.write("<option value="+i+">"+i+"</option>");
</script>
</select>
<select name="year">
<option value='---year---'>year</option>
<script>
for(i=1900;i<=2100;i++)
document.write("<option value="+i+">"+i+"</option>");
</script>
</select>
</td>
</tr>
<tr>
<td>Languages Known</td>
<td>
Telugu<input type='checkbox' name='telugu' value='telugu'>
Hindhi<input type='checkbox' name='hindhi' value='hindhi'>
Tamil<input type='checkbox' name='tamil' value='tamil'>
English<input type='checkbox' name='english' value='english'>
</td>
</tr>
<tr>
<td>Address</td>
<td><textarea name="addr" rows='5' cols='25'></textarea></td>
</tr>
<tr>
<td>Mobile Number</td>
<td><input type='text' name="mobile"></td>
</tr>
<tr>
<td>
<input type='submit' value='Register'>
</td>
<td>
<input type='reset' value='Clear'>
</td>
</tr>
</table>
</form>
</BODY>
</HTML>
Register.php:
<?php
//Reading Values from form
$name =$_POST['name'];
$password =$_POST['password'];
$email =$_POST['email'];
$gender =$_POST['gender'];
$dob=$_POST['date']."-".$_POST['month']."-".$_POST['year'];
$languages="";
if($_POST['telugu']!=null)
{
$languages=$languages.$_POST['telugu'].",";
}
if($_POST['hindhi']!=null)
{
$languages=$languages.$_POST['hindhi'].",";
}
if($_POST['tamil']!=null)
{
$languages=$languages.$_POST['tamil'].",";
}
if($_POST['english']!=null)
{
$languages=$languages.$_POST['english'].",";
}
$addr =$_POST['addr'];
$mobile =$_POST['mobile'];
//Connecting to Mysql Using PHP
$dbhost = "localhost:3306";
$dbuser = "root";
$dbpass = "root";
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
$sql = "INSERT INTO gec.register VALUES ".
"('$name','$password','$email','$gender','$dob','$languages','$addr','$mobile')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
}
else
{
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
Output:
Open the browser and type following URL
http://localhost/Register%20PHP/registration.html