Академический Документы
Профессиональный Документы
Культура Документы
Develop static pages of an online Book Store by only using HTML (the pages should
resemble:www.amazon.com). The website should consist the following pages.
a. Home Page
b. Registration and User Login
c. Books Catalog
HomePage.html
Home page
Main.html:
<html>
<head>
<title>
Amazon</title>
</head>
<body bgcolor="cyan"> <center>
<strong><h1>Welcome to AMAZON</h1></strong>
<form method="post" action="login.html" target=_blank >
<h4>for books</h4><input type="submit" value="click here">
</form>
</center>
</body>
</html>
Registration and user Login
Registration.html
<html>
<head>
<title> form</title>
</head>
<body bgcolor=blue text=white>
<h1 align=center>creat your email id </h1>
<marquee><h2>this is google web page </h2></marquee>
<pre>
<form>
<b>
<h3>
first name <input type="text"></input><br>
second name <input type="text"></input><br>
email id <input type="text"></input><br>
password<input type="password"><br>
conform password <input type="password"><br>
gender
<input type="radio"name="radio"
value="radio">female</input>
<input type="radio"name="radio"
value="radio">male</input>
dateofbirth <br>
Y.Kiran Kumar
Page 1
day<input type="date"size="2"
></input>month<select name=month>
<option>jan
<option>feb
<option>mar
<optin>apr
<option>may
<option>june
<option>july
<opiton>aug
<option>sep
<option>oct
<option>nov
<option>dec
</select></input>year<select name=year>
<option>1986
<option>1987
<option>i988
</select></input>
select your country:<select name =country>
<option> usa
<option> india
<option> africa
</select><br>
area of interrest ::<br><br>
entertainment<input type="check box" value ="c1"></input>
games
<input type="check box" value="c2"></input>
select your qusetion<select name=question>
<option>what is your pet name?
<option>what is your favorite food ?
<option>what is your aim?
answer
comment:
</select><br>
<input type="text"><br>
Page 2
Output:
Login.html:
<html>
<head>
<title>
login page</title>
</head>
<body bgcolor="cyan"> <center>
<strong><h1> AMAZON </h1></strong></center>
<right>
<table align="right">
<tr>
<td><h4>user name</td>
<td><input type="text" ></td>
<td></td>
</tr>
<tr>
<td><h4>password</td>
<td><input type="password"></td>
<td></td>
</tr>
Y.Kiran Kumar
Page 3
<tr>
<td>
<form method="post" action="catalog.html" >
<input type="submit" value="submit" >
</form>
</td>
<td>
<form method="post" action="userpro.html" >
<input type="submit" value="register" >
<input type="reset" value="reset"></form></td>
</tr>
</table>
</body>
</html>
Books catalog
Catalog.html:
<html>
<head>
<title>
books catalog</title>
</head>
<body bgcolor="cyan">
<center><h1>AMAZON</h1></center>
<form method="post" action="shopping.html">
<left>
<table>
<tr>
<td><b><h3>frontend books</td>
<td></td></tr>
<tr>
<td></td>
<td><h4>C&Ds</td>
</tr>
<tr>
<td></td>
<td><h4>Ads</td>
</tr>
<tr>
<td></td>
<td><h4>JAVA
</td></tr>
<tr>
<td><b><h3>backend books</td>
<td></td>
</tr>
<tr>
Y.Kiran Kumar
Page 4
<td></td>
<td><h4>Oracle</td>
</tr>
<tr>
<td></td>
<td><h4>Ms SQL Server
</td></tr>
<tr>
<td></td>
<td><h4>MySql </td>
</tr>
</table>
</h4>
<center>
<b>for buy one of these books
<br>
</b><input type="submit" value="click here">
</center>
</form>
</body>
</html>
Main.html:
Y.Kiran Kumar
Page 5
Login.html:
Catalog.html:
Page 6
<script type="text/javascript">
FUNCTION CALSCORE()
{
var SCORE=0;
IF(document.feedback.q1[0].CHECKED)
SCORE=SCORE+5;
IF(document.feedback.q1[0].CHECKED)
SCORE=SCORE+5;
IF(document.feedback.q1[1].CHECKED)
SCORE=SCORE+3;
IF(document.feedback.q1[2].CHECKED)
SCORE=SCORE+2;
IF(document.feedback.q1[3].CHECKED)
SCORE=SCORE+1;
IF(document.feedback.q2[0].CHECKED)
SCORE=SCORE+5;
IF(document.feedback.q2[1].CHECKED)
SCORE=SCORE+3;
IF(document.feedback.q2[2].CHECKED)
SCORE=SCORE+2;
IF(document.feedback.q2[3].CHECKED)
SCORE=SCORE+1;
IF(document.feedback.q3[0].CHECKED)
SCORE=SCORE+5;
IF(document.feedback.q3[1].CHECKED)
SCORE=SCORE+3;
IF(document.feedback.q3[2].CHECKED)
SCORE=SCORE+2;
IF(document.feedback.q3[3].CHECKED)
SCORE=SCORE+1;
IF(document.feedback.q4[0].CHECKED)
SCORE=SCORE+5;
IF(document.feedback.q4[1].CHECKED)
SCORE=SCORE+3;
IF(document.feedback.q4[2].CHECKED)
SCORE=SCORE+2;
IF(document.feedback.q4[3].CHECKED)
SCORE=SCORE+1;
IF(document.feedback.q5[0].CHECKED)
SCORE=SCORE+5;
IF(document.feedback.q5[1].CHECKED)
SCORE=SCORE+3;
IF(document.feedback.q5[2].CHECKED)
SCORE=SCORE+2;
IF(document.feedback.q5[3].CHECKED)
SCORE=SCORE+1;
Y.Kiran Kumar
Page 7
window.alert("totalscore" +SCORE);
}
</script>
</head>
<body>
<h1><p style ="color ;pink;margin:20px">
<center>feed back form</center>
</p>
</h1>
<form name="feedback" onsubmit="CALSCORE()">
lecture name:<input type=text name=n2 size=10 value=" "><br>
subject:<input type=text name=n2 size=10 value=" "><br>
1.communication skills<br>
<input type=radio name=q1>excelent
<input type=radio name=q1>very good
<input type=radio name=q1>good
<input type=radio name=q1>average<br><br>
2.subject knowledge<br>
<input type=radio name=q2>excelent
<input type=radio name=q2>very good
<input type=radio name=q2>good
<input type=radio name=q2>average<br><br>
3.clarification of doubts.<br>
<input type=radio name=q3>excelent
<input type=radio name=q3>very good
<input type=radio name=q3>good
<input type=radio name=q3>average<br><br>
4.other knowledge.<br>
<input type=radio name=q4>excelent
<input type=radio name=q4>very good
<input type=radio name=q4>good
<input type=radio name=q4>average<br><br>
5.overall grading<br>
<input type=radio name=q5>excelent
<input type=radio name=q5>very good
<input type=radio name=q5>good
<input type=radio name=q5>average
<input type=button name="submit" value="submit" onclick=calscore()>
</form>
</body>
</html>
Y.Kiran Kumar
Page 8
OutPut:
Page 9
</body>
</html>
Right.html:
<html>
<body>
<br><br><br><br><br>
<h2 align="center">
<b><p> welcome to online book storage. Press login if you are
having id otherwise press registration.
</p></b></h2>
</body> </html>
Left.html:
<html>
<body bgcolor="pink">
<h3>
<ul>
<li><a href="login.html" target="right"><font color="black">
LOGIN</font></a></li><br><br>
<li><a href="profile.html" target="right"><font color="black">
USER PROFILE</font></a></li><br><br>
<li><a href="catalog.html" target="right"><font color="black">
BOOKS CATALOG</font></a></li><br><br>
<li><a href="scart.html" target="right"><font color="black">
SHOPPINGCART</font></a></li><br><br>
<li><a href="payment.html" target="right"><font color="black">
PAYMENT</font></a></li><br><br>
<br><br>
</ul>
</body>
</html>
Registration and user Login
Login.html:
<html>
<body bgcolor="pink"><br><br><br>
<script language="javascript">
function validate()
{
var flag=1;
if(document.myform.id.value==""||
document.myform.pwd.value=="")
{ alert("LoginId and Password must be filled")
flag=0;
}i
f(flag==1)
{ alert("VALID INPUT");
window.open("catalog.html","right");
Y.Kiran Kumar
Page 10
} else
{ alert("INVALID INPUT");
//document.myform.focus();
}}
</script>
<form name="myform">
<div align="center"><pre>
LOGIN ID:<input type="text" name="id"><br>
PASSWORD:<input type="password" name="pwd"><br><br>
</pre>
<input type="button" value="ok" onClick="validate()">
<input type="reset" value="clear" >
</div>
</form>
</body>
</html>
Catalog.html:
<html>
<body bgcolor="pink"><br><br><br>
<script language="javascript">
function validate()
{
var flag=1;
if(document.myform.id.value==""||
document.myform.title.value==""||
document.myform.no.value==""||
document.myform.cost.value=="")
{
flag=0;
}
str=document.myform.title.value;
var str1=document.myform.cost.value;
if(!((str=="c"&& str1==444) || (str=="jsp" && str1==555)))
{
flag=0;
}
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">
<input type="reset" value="clear">
</form>
</body>
</html>
if(flag==1)
{
Y.Kiran Kumar
Page 11
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform" action="scart.html" target="right">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id"><br>
TITLE :<input type="text" name="title"><br>
NO.OF BOOKS :<input type="text" name="no"><br>
COST OF BOOK :<input type="text"name="cost"><br>
</pre><br><br>
OUTPUT:
Main.html
Login.html:
Y.Kiran Kumar
Page 12
Catalog.html:
allstylesheets.html
Y.Kiran Kumar
Page 13
<html>
<head>
<h1><center><B><U>ALL STYLE SHEET</U></B></center></h1>
<title>use of internal and external style sheet</title>
<link rel="stylesheet" href="xyz.css" type="text/css">
<style type="text/css">
.vid{font-family:Bohamos;font-style:italic;color:red;text-align:center;}
.ani{font-family:vardana;font-style:bold;font-size:20;text-align:center;}
font{font-family:georgia;color:blue;font-size:20}
ul{list-style-type:circle}
</style>
</head>
<body>
<ol style="list-style-type:lower-alpha">
<b><u>SREE VIDYANIKETHAN GROUP OF COLLEGES</u></b><br><br><br>
<li>sree vidyanikethan eng college</li>
<li>sree vidyanikethan degree college</li>
<li>sree vidyanikethan institute of management</li>
<li>sree vidyanikethan college of nursing</li>
<li>sree vidyanikethan college of pharmacy</li>
</ol>
<p style="font-size:20pt;color:green">
<marquee>
SREE VIDYANIKETHAN GROUP OF COLLEGES</marquee>
</p>
<p class="ani">sree vidyanikethan group of college owned by M.Mohan babu<br>it is
approved by AICTE.It is affliated to jntua,ananthapur</p><br><br>
<h2 class="vid">sree vidyanikethan eng college</h2><br>
<font>sree vidyanikethan engineering clg conferred with Autonomous by the UGc</font><br>
<br>
<font>
<h2>list of cources offered</h2>
<ul>
<li>MCA</li>
<li>CSE</li>
<li>M.Tech</li>
<li>CSE</li>
<li>ITI</li>
<li>EEE</li>
<li>MECHANICAL</li>
</ul>
</font>
<h3>Results of MCA students</h3>
<table width="100%" cellspacing="2" cellpadding="2"border="5">
<tr>
<th>s.name</th>
<th>marks</th>
Y.Kiran Kumar
Page 14
<th>result</th>
</tr>
<tr>
<td align="center">k.guru</td>
<td align="center">85</td>
<td align="center">pass</td>
</tr>
<tr>
<td align="center">k.guru</td>
<td align="center">85</td>
<td align="center">pass</td>
</tr>
<tr>
<td align="center">k.guru</td>
<td align="center">85</td>
<td align="center">pass</td>
</tr>
</table>
</body>
</html>
5. Create and save an XML document at the server, which contains 10 users information. Write a
program, which takes User Id as an input and returns the user details by taking the user
information from the XML document.
Y.Kiran Kumar
Page 15
Page 16
Y.Kiran Kumar
Page 17
StudentData.xml
<?xml version="1.0" encoding="UTF-8"?>
<userInfo>
<user id="1">
<uname>Ramesh</uname>
<uaddress>Bangalore</uaddress>
<udob>12</udob>
</user>
<user id="2">
<uname>Phani</uname>
<uaddress>Hyderabad</uaddress>
<udob>13</udob>
</user>
<user id="3">
<uname>Muni</uname>
<uaddress>Chennai</uaddress>
<udob>14</udob>
</user>
</userInfo>
Y.Kiran Kumar
Page 18
Page 19
bookcatalog.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My Book Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>title</th>
<th>author</th>
<th>country</th>
<th>publication</th>
<th>price</th>
`
<th>year</th>
</tr>
<xsl:for-each select="catalog/book">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="author"/></td>
<td><xsl:value-of select="country"/></td>
<td><xsl:value-of select="publication"/></td>
<td><xsl:value-of select="price"/></td>
<td><xsl:value-of select="year"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Y.Kiran Kumar
Page 20
Output:
Page 21
Element element=(Element)list.item(i);
String nodeName=element.getNodeName();
if(nodeName.equals("book"))
{
bookcount++;
System.out.println("Book"+bookcount);
String isbn=element.getAttribute("ISBN");
System.out.println("\tISBN:\t"+isbn);
}
else if(nodeName.equals("title"))
{
System.out.println("\tTitle:\t"+element.getChildNodes().item(0).getNodeValue());
}
else if(nodeName.equals("author"))
{
System.out.println("\tAuthor:\t"+element.getChildNodes().item(0).getNodeValue());
}
}
} }
Output:
Z:\WAD>javac DomParserBookStore.java
Z:\WAD>java DomParserBookStore
Book1
ISBN: 0123456001
Title: Javaprogramming
Author: Tan
Book2
ISBN: 0123456002
Title: More Java Programming
Author: Jan Ah Tech
Book3
ISBN: 9788131758342
Title: Programming with java
Author: Sureshkumar
Author: Eswar reddy
Author: Raghavan
Y.Kiran Kumar
Page 22
SAXParserBookstore.java
import java.io.File;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXExceptions;
import org.xml.sax.helpers.DefaultHandler;
public class SAXParserBookstore
{
private string currentElement;
private int bookcount=1;
private SAXParserBookstore()
{
try
{
SAXParser Factory factory=SAXParserFactory.newInstance();
SAXParser saxParser=factory.newSAXParser();
SAXParser.parse(new File("bookstore.xml"),new MyHandler());
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String args[])
{
new SAXParserBookstore();
}
class MyHandler extends Default Handler
{
//callback to handle a element start tag
public void startElement(String uri,String localname,String qName,Attributes attributes)throws
SAXException
{
currentElement=qName;
if(currentElement.equals("book"))
{
Y.Kiran Kumar
Page 23
System.out.println("Book"+bookcount);
bookcount++;
String isbn=attributes.getValue("ISBN");
System.out.println("\t ISBN:\t"+isbn);
}
}
//call back to handle element and tag
public void endElement(String uri,String localName,String qName)throws SAXException
{
currentElement=" ";
}
//callback to handle the character text date inside an element
public void characters(char[] chars,int start,int length)throws SAX Exception
{
if(currentElement.equals("title"))
{
System.out.println("\t title:\t"++newString(chars,start,length));
}
else if(currentElement.equals("author"))
{
System.out.println("\t Author:\t"+newString(chars,start,length));
}
}}}
output:
Book1
ISBN: 0123456001
title: Javaprogramming
Author:
Tan
Book2
ISBN: 0123456002
title: More Java Programming
Author:
Tan Ah Tech
Book3
ISBN: 9788131758342
title: Programming with java
Author:
Eswar reddy
Y.Kiran Kumar
Page 24
8. a. Write a java program to get IP Address, Host Name and Port Numbers of a Local system
import java.io.*;
import java.net.*;
public class IPTest
{
public static void main(String args[])throws UnknownHostException
{
InetAddress addr=InetAddress.getLocalHost();
//getting IP Address of localhost-getHostAddress return IP Address
//in textual format
String ipAddress=addr.getHostAddress();
System.out.println("IP Address of localhost from java program:"+ipAddress);
//Nostname
String hostname=addr.getHostName();
System.out.println("Name of hostname:"+hostname);
//port Number 1024 to 65535 1720
for(int port=1024;port<=1720;port++)
{
try
{
ServerSocket server=new ServerSocket(port);
}
catch(IOException e)
{
System.out.println("There is a server on port"+port);
}
}
}
}
output:
IP Address of localhost from java program:100.100.100.177
Name of hostname:svimlab-177
There is a server on port1025
There is a server on port1662
There is a server on port1663
There is a server on port1664
There is a server on port1665
b. Write a Java Program using Datagram Communication.
Dserver.java
import java.net.*;
import java.io.*;
class DServer
{
Y.Kiran Kumar
Page 25
Y.Kiran Kumar
Page 26
Dclient.java
import java.net.*;
import java.io.*;
class DClient
{
public static void main(String args[])throws IOException
{
BufferedReader kybd=new BufferedReader(new InputStreamReader(System.in));
InetAddress localadrs=InetAddress.getLocalHost();
InetAddress remoteadrs=localadrs;
DatagramSocket dsocket=new DatagramSocket(3457);
int buffersize=2000;
byte[] outbuffer=new byte[buffersize];
DatagramPacket outgram;
System.out.println("start the dilog from this client");
boolean more=true;
while(more)
{
byte[] inbuffer=new byte[buffersize];
DatagramPacket ingram=new DatagramPacket(inbuffer,buffersize);
String send=kybd.readLine();
outbuffer=send.getBytes();
outgram=new DatagramPacket(outbuffer,outbuffer.length,remoteadrs,3456);
dsocket.send(outgram);
if((send.trim()).equals("exit"))
break;
dsocket.receive(ingram);
String data=new String(ingram.getData());
data=data.trim();
System.out.println("From Server:"+data);
if(data.equals("exit"))
break;
}
dsocket.close();
}
}
Y.Kiran Kumar
Page 27
output:
Z:\HTML>javac DClient.java
Z:\HTML>java DClient
start the dilog from this client
hai hello dis is yasaswini,persuing MCA
Page 28
4. copy web.xml to WEB-INF directory. Also provided information about the web application.
<web-app>
<servlet>
<servlet-name>sone</servlet-name>
<servlet-class>OurSrv</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sone</servlet-name>
<url-pattern>/done/srv</url-pattern>
</servlet-mapping>
</web-app>
Note: web.xml is called deploymentdescriptor.
5. copy the static resources under the webroot or the sub directories of the web-root. (we should not
copy the static resources under WEB-INF).
6. copy servlet classes under WEB-INF\classes.
10. Generate a Servlet, that will accept form data from HTML file which includes Name of the user and
favorite programming language described in terms of a LIST, and it must display user name and
language selected by a particular Client.
Request.html
<html>
<head>
<title>Request Processing</title>
</head>
<body bgcolor="megenta">
<form name="f" method="post" action="\servlet">
username:<input type="text" name="username"/>
<br><br>
select your Favarite programming language:
<select name="p1">
<option value="c">c</option>
<option value="Java">Java</option>
<option value="php">Php</option>
<option value="VB.Net">VB.NET</option>
</select>
<br><br>
<input type="submit" value="submit" />
</form>
</body>
</html>S
loginServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
Y.Kiran Kumar
Page 29
response)throws
11. Generate a Servlet page that showing the Session ID, Creation Time, Last Accessed Time
and Max Inactive Interval. Along with page should display links like Reload this page and Invalidate
the Session. When we press the Reload this page link the above information should be redisplayed. If
we press Invalidate the Session link the page will display one more link like create new session along
with it has to display message like session invalidated.
Y.Kiran Kumar
Page 30
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SessionExample extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession(true);
// print session info
Date created = new Date(session.getCreationTime());
Date accessed = new Date(session.getLastAccessedTime());
out.println("ID " + session.getId());
out.println("Created: " + created);
out.println("Last Accessed: " + accessed);
// set session info if needed
String dataName = request.getParameter("dataName");
if (dataName != null && dataName.length() > 0) {
String dataValue = request.getParameter("dataValue");
session.setAttribute(dataName, dataValue);
}
// print session contents
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = session.getAttribute(name).toString();
out.println(name + " = " + value);
}
}
}
OUTPUT:Session ID: E55B7AE87EEC8556A084BBFF47E96155
Created: Thu May 29 12:00:08 IST 2008
Last Accessed: Thu May 29 12:00:43 IST 2014
The following data is in your session:
ANANTH = 1234
RAM = 4321
Y.Kiran Kumar
Page 31
Page 32
<html>
<body>
<br><br>
<center>
<p>Copyright @ 2014</p>
</center>
</body>
</html>
Header.jsp
<%!
int pageCount=0;
void addCount(){
pageCount++;
}
%>
<%addCount();%>
<html>
<head>
<title>The include Directive Example</title>
</head>
<body>
<center>
<h2>The include Directive Example</h2>
<p>This has been visited<%=pageCount%>times</p>
</center>
<br><br>
</body>
</html>
13. Write a Java Program using TCP/IP Protocol.
import java.net.*;
import java.io.*;
class tcpip_server
{
public static void main(String args[]) throws IOException
{
ServerSocket n1=null;
try
{
n1=new ServerSocket(98);
}
catch(IOException e)
{
System.err.println("Port 98 could not be found");
System.exit(1);
Y.Kiran Kumar
Page 33
}
Socket c=null;
try
{
c=n1.accept();
System.out.println("Connection from "+c);
}
catch(IOException e)
{
System.out.println("Accept failed");
System.exit(1);
}
PrintWriter out=new PrintWriter(c.getOutputStream(),true);
BufferedReader in=new BufferedReader(new InputStreamReader(c.getInputStream()));
String n;
BufferedReader sin=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Ready to type now");
while((n=sin.readLine())!=null)
{
out.println(n);
}
out.close();
c.close();
n1.close();
}
}
import java.net.*;
import java.io.*;
class tcpip_client
{
public static void main(String args[]) throws IOException
{
Socket s=null;
BufferedReader b=null;
try
{
s=new Socket(InetAddress.getLocalHost(),98);
b=new BufferedReader(new InputStreamReader(s.getInputStream()));
}
catch(UnknownHostException u)
{
System.err.println("I don't know host");
System.exit(0);
Y.Kiran Kumar
Page 34
}
String inp;
while((inp=b.readLine())!=null)
{
System.out.println(inp);
}
b.close();
s.close();
}
}
14. Write a JSP program for finding total number of visitors in a site to keep track of active users at a given
instance of time, and also display the user session starting time.
Session.jsp
<%@ page import="java.io.*,java.util.*"%>
<%
Date lastAccessTime=new Date(session.getlastAccessTimeTime());
String title="welcome back to my website';
Integer visitCount=new Integer(0);
Integer visitCountkey=new String("visitCount");
String userIDkey=new String("userID");
String userID=new String("ABCD");
if(session.isNew())
{
title="welcome to my website";
session.setAttribute(userIDkey,userID)
session.setAttribute(visitCountKeey,visitCount);
}
visitCount=(Integer)session.getAttribute(visitCountkey);
visitCount=visitCount+1;
userID=(String)session.getAttribute(userIDkey);
session.setAttribute(visitCountKeey,visitCount);
%>
<html>
<head>
<title>Session Tracking</title>
</head>
<body>
<center>
<h1>Session Tracking</h1>
</center>
<table border="1" align="center">
<tr bgcolor="#949494">
<th>Session info</th>
Y.Kiran Kumar
Page 35
<th>Value</th>
</tr>
<tr>
<td>id</td>
<td><% out.print(Session.getId());%></td>
</tr>
<tr>
<td>Creation Time</td>
<td><% out.print(create Time);%></td>
</tr>
<tr>
<td>Time of last Access</td>
<td><% out.print(last AccessTime);%></td>
</tr>
<tr>
<td>user id</td>
<td><% out.print(userID);%></td>
</tr>
<tr>
<td>Number of visits</td>
<td><% out.print(visitCount);%></td>
</tr>
</table>
</body>
</html>
15. Write a JSP program that creates a cookie on username which is send from html file and display the
cookie value as a response. The cookie must be active based on the maximum active interval time.
<%
Cookie uid = new Cookie("username",request.getParameter("username"));
Cookie pass = new Cookie("password",request.getParameter("password"));
uid.setMaxAge(60*60*24);
pass.setMaxAge(60*60*24);
response.addCookie(uid);
response.addCookie(pass);
%>
<html>
<body>
<h1>Creation of cookies</h1><br>
User Id:<%=request.getParameter("username")%><br>
Password:<%=request.getParameter("password")%>
</body>
</html>
Y.Kiran Kumar
Page 36
<html>
<h1>Reading of Cookies</h1><br/>
<%
Cookie ck=null;
Cookie[] cks=null;
cks=request.getCookies();
if(cks!=null)
{
out.println("<h2>Found cookie name and values</h2>");
for(int i=0;i<cks.length;i++)
{
ck=cks[i];
out.println("Name of the cookie is:"+ck.getName()+",");
out.println("Value of the cookie is:"+ck.getValue()+"<br>");
}
Y.Kiran Kumar
Page 37
}
else{
out.println("<h2>No Cookies was found</h2>");
}
%>
</html>
<%
Cookie uid = new Cookie("username",request.getParameter("username"));
Cookie pass = new Cookie("password",request.getParameter("password"));
uid.setMaxAge(60*60*24);
pass.setMaxAge(60*60*24);
response.addCookie(uid);
response.addCookie(pass);
%>
<html>
<body>
<h1>Creation of cookies</h1><br>
User Id:<%=request.getParameter("username")%><br>
Password:<%=request.getParameter("password")%>
</body>
</html>
Y.Kiran Kumar
Page 38
<html>
<h1>Reading of Cookies</h1><br/>
<%
Cookie ck=null;
Cookie[] cks=null;
cks=request.getCookies();
if(cks!=null)
{
out.println("<h2>Found cookie name and values</h2>");
for(int i=0;i<cks.length;i++)
{
ck=cks[i];
out.println("Name of the cookie is:"+ck.getName()+",");
out.println("Value of the cookie is:"+ck.getValue()+"<br>");
}
Y.Kiran Kumar
Page 39
}
else{
out.println("<h2>No Cookies was found</h2>");
}
%>
</html>
16. Develop java program for following SQL operations using JDBC.
a. Create
b. Insert
c. Update and
d. Delete
Consider the following schema:
Employee (EmpName, EmpNo Primary Key, Department, Salary)
AccessDb.java
import java.io.*;
import java.sql.*;
class AccessDb
{
public static void main(String args[])throws IOException,SQLException
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:empdsn");
Statement st=con.createStatement();
Y.Kiran Kumar
Page 40
Y.Kiran Kumar
Page 41
17. Generate a JSP page that will store and retrieve the Employee information from the database.
The page should display the employee records in a tabular format.
Creation of a context file
Create any folder in any drive as (E:\Jsp). Inside that folder store your .jsp files. Give the Context
path name as jsp and docBase as E:\Jsp, here docBase means the total path where we are storing
our .jsp files. These changes are done in the server.xml file, which is present in (E:\Program
Files\Apache Software Foundation\Tomcat 6.0\conf) directory.
Server.xml file
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResources
LifecycleListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
Page 42
<Valve className="org.apache.catalina.valves.RequestDumperValve"/>
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
<Context path="/jsp" docBase="E:\Jsp" reloadable="true" debug="0" />
</Host>
</Engine>
</Service>
</Server>
Table creation
First create an employee table in Oracle and insert some data as below
Create table employee (empid varchar(10),empname varchar(10),sal int)
insert into employee values('e001','Raj',10000)
insert into employee values('e002','Harry',20000)
insert into employee values('e003','Sunil',30000)
insert into employee values('e004','Pollock',40000)
Y.Kiran Kumar
Page 43
Page 44
Y.Kiran Kumar
Page 45
Insert.jsp
<%@ page language="java" contentType="text/html"%>
<%@page import="java.io.*"%>
<%@page import="java.sql.*"%>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<% String fn=request.getParameter("t1");
String ln=request.getParameter("t2");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection con = DriverManager.getConnection("jdbc:odbc:murali");
out.println("Connection success...");
out.println("<br/>");
Statement st=con.createStatement();
int i=st.executeUpdate("insert into emp values('"+fn+"','"+ln+"')");
out.println("Data is successfully inserted!");
Y.Kiran Kumar
Page 46
Y.Kiran Kumar
Page 47
18. Write programs in Java to create three-tier applications using JSP and Databases
For conducting on-line examination.
For displaying student mark list.
Assume that student information is available in a Database which has been stored in a database
server.
Three-Tier Application Using JSP and Database (Online Examination)
OnlineExam.jsp
<%@ page language="java" import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%
String SeatNum,Name;
String ans1,ans2,ans3,ans4,ans5;
int a1,a2,a3,a4,a5;
a1=a2=a3=a4=a5=0;
Connection connect=null;
Statement stmt=null;
ResultSet rs=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:ExamStudent";
connect = DriverManager.getConnection(url," "," ");
if(request.getParameter("action")!=null)
{
SeatNum = request.getParameter("Seat_no");
Name = request.getParameter("Name");
ans1 =request.getParameter("group1");
if(ans1.equals("True"))
a1=5;
else
a1=0;
ans2 = request.getParameter("group2");
if(ans2.equals("True"))
a2=0;
else
a2=5;
ans3 = request.getParameter("group3");
if(ans3.equals("True"))
a3=0;
else
a3=5;
ans4 = request.getParameter("group4");
if(ans4.equals("True"))
a4=5;
else
a4=0;
ans5 = request.getParameter("group5");
if(ans5.equals("True"))
Y.Kiran Kumar
Page 48
a5=0;
else
a5=5;
int Total=a1+a2+a3+a4+a5;
stmt = connect.createStatement();
String query = "INSERT INTO StudentTable (" + "Seat_no,Name,Marks" + ")
VALUES ('" +SeatNum + "', '" + Name + "', '"+Total+ "')";
int result = stmt.executeUpdate(query);
stmt.close();
stmt = connect.createStatement();
query = "SELECT * FROM StudentTable WHERE Name="+"'"+Name+"'";
rs = stmt.executeQuery(query);
%>
<html><head><title>Student Mark List</title></head>
<body bgcolor=khaki>
<center>
<h2>Students Marksheet</h2>
<h3>Name of the College : Sree Vidyanikethan Engineering College</h3>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td><b>Seat_No</b></td>
<td><b>Name</b></td>
<td><b>Marks</b></td>
</tr>
<%
while(rs.next())
{
%>
<tr>
<td><%=rs.getInt(1)%></td>
<td> <%=rs.getString(2)%></td>
<td> <%=rs.getString(3)%></td>
</tr>
<%
}
rs.close();
stmt.close();
connect.close();
%>
</table>
</center>
<br/> <br/><br/>
<table>
<tr><td><b>Date:<%=new java.util.Date().toString() %></td></tr>
<tr><td><b>Signature: X.Y.Z. <b></td></tr>
</table>
<div>
Y.Kiran Kumar
Page 49
Page 50
<hr/>
<b>1. XML enables you to collect information once and reuse it in a
variety of ways.</b><br/>
<input type="radio" name="group1" value="True">True
<input type="radio" name="group1" value="False">False<br>
<br/>
<b>2. In Modern PC there is no cache memory.</b><br/>
<input type="radio" name="group2" value="True">True
<input type="radio" name="group2" value="False">False<br>
<br/>
<b>3. JavaScript functions cannot be used to create script fragments
that can be used over and over again</b><br/>
<input type="radio" name="group3" value="True">True
<input type="radio" name="group3" value="False">False<br>
<br/>
<b>4.The DriverManager class is used to open a connection to a
database via
a JDBC driver.</b><br/>
<input type="radio" name="group4" value="True">True
<input type="radio" name="group4" value="False">False<br>
<br/>
<b>5. The JDBC and ODBC does not share a common parent</b><br/>
<input type="radio" name="group5" value="True">True
<input type="radio" name="group5" value="False">False<br>
<hr/>
<center>
<input type = "submit" value="Submit">
<input type = "reset" value="Clear"><br><br>
</center>
</form>
<%}%>
Y.Kiran Kumar
Page 51