Page 1
Website development for a Company
5. IMPLEMENTATION
5.1 IMPLEMENTATION:
Java Server Pages is a simple, yet powerful technology
for creating and maintaining dynamic-content web pages. Based on the Java
programming language, Java Server Pages offers proven portability, open
standards, and a mature re-usable component model.
JSP’s are designed to work within a request / response –
processing model. In a request / response model, a client sends a request message
to a server and the server responds by sending back a reply message.
Requests can come in the form of a custom protocol.
HTTP URL
FTP URL
MIDDLE TIER PROCESS:
In many systems, a middle tier serves as a link between clients
and back-end services. By using a middle tier a lot of processing can be off-loaded
form both clients (making them lighter and faster) and servers (allowing them to
focus on their mission).
One advantage of middle tier processing is simply connection
management. A set of jsp’s could handle connections with hundreds of clients, if
clients, if not thousands, while recycling a pool of expensive connections to
database servers.
61
Page 2
Website development for a Company
Other middle tier roles include:
Business rule enforcement
Transaction Management
Mapping clients to redundant set of servers
Supporting different types of clients such as pure HTML and java capable
clients.
INSTALLING JAVA SERVER PAGES:
JSP’s are not run in the same sense as applets and applications.
Java Server pages provide functionality that extends a server. There are many web
servers that support java server pages. It is beyond the scope of this course to
cover the different ways to install jsp’s in each server.
USING JAVA WEB SERVER:
Sun Java Web Server (JWS) is a full-featured product. Nice feature
is it’s ability to detect when a java server pages has been updated. It detects when
new class files have been copied to the appropriate public_html directory and it
necessary, automatically reloads any running Jsp pages.
Java Server Pages are installed by moving them to the
C:\Java Web Server2.0\public_html directory
62
Page 3
Website development for a Company
5.3 CODING
The coding step of software development is a process of transition of the
detailed design into a programming language that is ultimately transformed into
machine executable instructions. This coding depends on the proper selection of
the language and coding style of the preliminary design level specified in the design
phase.
CODING FOR SCREENS:
HOMEPAGE:
LOGIC:
This screen gives references to all other screens present in the project.
The screen is developed using html language. This is the main screen
of the project.
CODE:
<html>
<head>
<title>Narayana chips (p)Ltd.</title>
</head>
<body bgcolor=white text=black link=black vlink="black" alink=red
onLoad="fun()">
<table border=0 width=100% align=center valign=middle>
<tbody>
<tr width=100%>
<td align=center width=13%>
63
Page 4
Website development for a Company
<img src=ncp.gif width=50 height=70></img>
<td align=center width=60%>
<img src=logo.gif width=45 height=70></img>
<td align=center>
<input type=button name=date1 style="background:lightblue">
</tr>
</tbody>
</table>
<table border=0 width=100% align=center valign=middle>
<tbody>
<tr width=100% height=80>
<td background="home1.bmp">
<div style="position:absolute;top:125;left:210">
<a href="http://192.168.100.47:8080/prj/aboutus.html"><b>AboutUS></a>
</div>
<div style="position:absolute;top:125;left:350">
<a href="http://192.168.100.47:8080/prj/products.html">
<b>Products</b></a>
</div>
<div style="position:absolute;top:125;left:500">
<a href="http://192.168.100.47:8080/prj/hrd.jsp"><b>HRD</b></a>
</div>
<div style="position:absolute;top:125;left:630">
<a href="http://192.168.100.47:8080/prj/sitemap.html">
<b>Site Map</b></a></div>
</tr>
</tbody>
</table>
<table border=0 width=100% align=center valign=middle cellspacing=0>
<tbody>
<tr width=100% height=210>
64
Page 5
Website development for a Company
<td width=13% background=banner.bmp>
<div style="position:absolute;top:210;left:35">
<a href="http://192.168.100.47:8080/prj/careers.html"><b>
<font size=4>Careers</font></b></a></div>
<div style="position:absolute;top:280;left:38">
<a href="http://192.168.100.47:8080/prj/login.html"><b>
<font size=4>Login</font></b></a></div>
<div style="position:absolute;top:355;left:35">
<a href="http://192.168.100.47:8080/prj/search.html"><b>
<font size=4>Search</font></b></a></div></td>
<td width=80%>
<img src=globe.wmf width=615 height=220 style="z-index:-1">
<div style="position: absolute;top=250;left:590;z-index:1">
<a href=http://192.168.100.47:8080/prj/aboutus.html>
<img src=enter.gif width=50 height=50 border=0></img></a></div>
</tr>
</tbody>
</table>
</form>
</body>
</html>
65
Page 6
Website development for a Company
HRD SCREEN:
LOGIC:
This is the screen that displays the employees that are working in the
company. It is a jsp file. The main statements that are used in this file are
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:company","user",
“pwd”);
PreparedStatement ps=con.prepareStatement ("select * from company");
ResultSet rs=ps.executeQuery ();
These statements are used for connecting to jdbc driver and to retrieve
the data from the database company.
CODE:
<html>
<head>
<title>Human Resource Department</title>
</head>
<body text=white bgcolor=Black link=yellow vlink=aqua alink=green>
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%
PreparedStatement ps=null;
ResultSet rs=null;
Connection con=null;
66
Page 7
Website development for a Company
String id1=null;
String id="ID : ";
String name="NAME : ";
String address="ADDRESS : ";
try
{
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:company","batch11",
“bandi”);
ps=con.prepareStatement ("select * from company");
rs=ps.executeQuery ();
while(rs.next ())
{
out. Print ("<br/><table width=90% height=120 bgcolor=gray
align=center>
<tbody>");
out. print("<tr><td align=right width=33% valign=middle>");
id1=rs.getString (1);
out.print ("<font color=orange><b>"+id+"</b></font>
<td align=left valign=middle>
< a href='http://192.168.100.47:8080/prj/details.jsp?id="+id1+"'>
<b>"+id1+"</b></a>");
out.print("</font></tr>");
out.print("<tr><td align=right valign=middle>");
out.print("<font color=lightblue>"+name+"</font>");
out.print("<td align=left valign=middle>");
out.print("<font color=white>");
out.print(rs.getString(2));
out.print("</font></tr>");
out.print("<tr><td align=right valign=middle>");
out.print("<font color=lightblue>"+address+"</font>");
67
Page 8
Website development for a Company
out.print("<td align=left valign=middle>");
out.print("<font color=white>");
out.print(rs.getString(9));
out.print("</font></tr></tbody></table");
out.print("<br/><br/><center>
<img src='pencil.gif'></img></center><br/>");
}
}
%>
</form>
</body>
</html>
68
Page 9
Website development for a Company
EXAM.JSP:
LOGIC:
This file is used to conduct the aptitude test. In this 15 questions are
displayed and these questions are retrieved randomly from the database by using
Random () function.
Random ran = new Random();
ran.nextInt(50);
The above function gives random numbers that are less than 50.
Timer is also maintained for the exam by using Script language.
Three methods are used here.
They are
1. start() ----- to start up the timer when examination is started.
2. timer() ----- to set the interval for the timer.
3. state() ----- to display the time on window status.
Code:
<html>
<head>
<title> Aptitude Test</title>
<Script language="JavaScript">
var i=899;
function timer()
{
SetInterval ("timers ()", 1000);
}
69
Page 10
Website development for a Company
function timers()
{
Window.Status=i;
i--; }
function state() {
window.status=900; } function start() {
setInterval("end()", 906000); }
function end() { alert("Oh! No ! Time over.");
document.Write("<tablewidth=80% align=center height=400>
<tbody>
<tr bgcolor=navy><td align=center>
<Font size=4color=yellow>
You are not qualified in the
Aptitude Test
<br/>. <br/>
<a href='http://192.168.100.47:8080/prj/homepage.html'>
<img src='home.bmp' border=0></img></a></tr></tbody></table>");
}
Window.onLoad=start();
Window.onLoad=timer();
Window.onLoad=state();
70
Page 11
Website development for a Company
</script>
<body>
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con1=DriverManager.getConnection ("jdbc:odbc:application",
"batch11", "bandi");
PreparedStatement ps2=con1.prepareStatement ("select * from
application”);
ResultSet rs2=ps2.executeQuery ();
while(rs2.next())
if((rs2.getString(3)).equals(id))
exam=rs2.getString (16);
if(exam.equals("NONE"))
{
String qry="update application set exam='YES' where
id='"+id+"'";
PreparedStatement ps1=con1.prepareStatement(qry);
ps1.executeUpdate();
for(int j=0;j<15;j++)
arr[j]=ran.nextInt(59)+1;
for(int j=0;j<15;j++)
for(int k=0;k<15;k++)
if(arr[j]<arr[k])
{
temp=arr[j];
arr[j]=arr[k];
arr[k]=temp;
}
71
Page 12
Website development for a Company
for(int k=0;k<15;k++)
for(int j=0;j<15;j++)
if((arr[k]==arr[j]) && (k!=j))
arr[j]=arr[k]+1;
Connection con=DriverManager.getConnection ("jdbc:odbc: exam", "batch11",
"bandi");
PreparedStatement ps=con.prepareStatement ("select * from exam order by qno");
ResultSet rs=ps.executeQuery ();
while(i<15 && rs.next())
{
f(rs.getInt(1)==arr[i]){
%>
<table width=90% align=center cellspacing=0 background=0012.jpg>
<tbody>
<tr bgcolor=lightblue height=30><td colspan=4>
<%
out.print((l+i)+". ");
out.print("<b>"+rs.getString(2)+"</b>");
%>
</tr>
</tbody>
</table>
<table width=90% align=center cellspacing=0>
<tbody>
<tr height=30><td width=25% valign=top>
<%
out.print("<input type=radio name="+(char)(c+i)+"
72
Page 13
Website development for a Company
value=3>"+rs.getString(3)+" ");
%>
<td width=25% valign=top>
<%
out.print("<input type=radio name="+(char)(c+i)+"
value=4>"+rs.getString(4)+" ");
%>
<td width=25% valign=top>
<%
out.print("<input type=radio name="+(char)(c+i)+"
value=5>"+rs.getString(5)+" ");
%>
<td width=25% valign=top>
<%
out.print("<input type=radio name="+(char)(c+i)+"
value=6>"+rs.getString(6)+<br><br><br>");
%>
</tr></tbody></table><br/>
<%
i++;
}
}
%>
<center><input type=submit value=Finish></center></form>
<%
73
Page 14
Website development for a Company
}
else
{
out.print("<script language='javascript'>alert('Oh ! No, You can't Refresh or
Reload this page');</script>");
%>
<a href="http://192.168.100.47:8080/prj/homepage.html">
<img src="home.bmp" alt="home.bmp" border=0></img></a></div>
<%
}
}
%>
</body>
</html>
74
Page 15
Website development for a Company
RESULT.JSP:
LOGIC:
This is used to find the result of the exam. First we retrieved the
question numbers that are displayed in the test from the exam file and then getting
the answers applied by the user. By comparing these answers with original
answers, we calculate the score.
CODE:
<html>
<body>
<% page language=java>
<%
while(i<15)
{
Connection con=DriverManager.getConnection ("jdbc:odbc:exam",
"batch11", "bandi");
PreparedStatement ps=con.prepareStatement ("select * from exam");
ResultSet rs=ps.executeQuery ();
while(rs.next())
{
if(rs.getInt(1)==bb[i])
{
ans[i++]=rs.getString(7);
break;
}
}
75
Page 16
Website development for a Company
}
for(int j=0;j<15;j++)
if(an[j]==null)
bb1[j]=8;
else
bb1[j]=Integer.parseInt(an[j]);
while(i<15 && rs4.next())
{
if(rs4.getInt(1)==bb[i])
{
if(bb1[i]==8)
an[i]=null;
else
an[i]=rs4.getString(bb1[i]);
i++;
}
}
for(int k=0;k<15;k++)
if(ans[k].equals(an[k]))
count++;
%>
</body>
</html>
76
Page 17
Website development for a Company
Mailing Screen:
Logic:
Employees use this page to see the offline messages send.
The main logic is retrieving the fields from the database mail and displaying it.
CODE:
<html>
<body>
<%
out.print("<div align=right>[
<a href='http://192.168.100.47:8080/prj/logout.jsp?id="+id+"'>Logout</a>
]</div>");
%>
<br/><table width=100% align=center border=0 height=30
bgcolor=lightgreen><tbody><tr><td width=400>
<font color=red size=4>Welcome, </font><font color=purple
size=4><u>
<%
while(rs.next()) if(rs.getString(1).equals(id))
{
%>
<tr height=40><td width=30% align=center>
<%
out.print(rs.getString(2));
%>
<td width=30% align=center>
<%
String subject=rs.getString(3);
77
Page 18
Website development for a Company
String datetime=rs.getString(4);
out.print("<a href='http://192.168.100.47:8080/prj/message.jsp?id="+id+"
&subject="+subject+"&datetime="+datetime+"'>"+subject+"</a>");
%>
<td width=40% align=center>
<%
out.print(datetime+"</tr>");
}
%>
</tbody></table>
</body>
</html>
78
Page 19
Website development for a Company
COMPOSE Screen:
LOGIC:
This page is used to send mails to other employees. Sending the
mail to other employee storing the data in the database of corresponding user for
whom the mail is send.
CODE:
<html>
<head>
<title>Sending the mail</title>
</head>
<body bgcolor=black text=white background="o002.jpg" vlink=red alink=aqua
link=lightblue>
<%
out.print("<div align=right>[
<a href='http://192.168.100.47:8080/prj/logout.jsp?id="+mailfrom+"'>Logout</
a>
]</div>");
try
{
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con1=DriverManager.getConnection ("jdbc:odbc:
“company","batch11", "bandi");
While (rs1.next ())
if((rs1.getString(1)).equals(mailto))
79
Page 20
Website development for a Company
m++;
Prepared Statement ps2=con1.prepareStatement ("select * from
company");
ResultSet rs2=ps2.executeQuery ();
While (rs2.next ())
if ((rs2.getString (1)). equals (mailfrom))
Password=rs2.getString (5);
if(flag==1)
{
If(m==1)
{
Connection con=DriverManager.getConnection ("jdbc:odbc: mail",
"batch11", "bandi");
Prepared Statement ps=con.prepareStatement ("insert into mail
(mailto, mailfrom, subject, datetime, data) values (?,?,?,?,?)");
Ps.clearParameters ();
Ps.setString (1, mailto);
Ps.setString (2, mailfrom);
Ps.setString (3, subject);
Ps.setString (4, datetime);
Ps.setString (5, data);
Ps.executeUpdate ();
%>
<br/><br/><br/>
<Table width=70% height=250 align=center>
<Tbody>
<tr width=80%><td align=center><font color=blue size=6>
Message send.
</font><tr/>
80
Page 21
Website development for a Company
<tr width=20%>
<td align=center>
<%
out.print("<form action='http://192.168.100.47:8080/prj/logincheck.jsp'
method=post>");
out.print("<input type=hidden name=id value="+mailfrom+">");
out.print("<input type=hidden name=password value="+password+">");
%>
<input type=submit value=Return to Mail>
</form>
</tbody>
</table>
<%
}
else if(m==0)
{
out.print("<form action='http://192.168.100.47:8080/prj/compose.jsp'>
<table align=center border=0 bgcolor=lightblue width=500 height=300>
<tbody><tr align=center valign=middle><td align=center>
<font size=4 color=white>No such employee exist in the company.
<br/><br/>
<input type=hidden name=id value="+mailfrom+">
<input type=submit value=Back></font></tr></tbody></table></form>");
}
}
%>
</body>
</html>
81
Page 22
Website development for a Company
LEAVE.JSP:
LOGIC:
This page allows the employees to take leave by online. Each
employee has a leave of 5 days in a month. If employees has sufficient leaves then
only the leave is granted otherwise it is rejected.
CODE:
<html>
<head>
<title>Online Leave Taking</title>
</head>
<body onLoad="startclock(); timerONE=window.setTimeout" bgcolor=white
text=black background=a051.jpg>
<%
out.print("<div align=right>[
<a href='http://localhost:8080/prj/logout.jsp?id="+id+"'>Logout</a> ]</
div>");
out.print("<br/><table width=100% align=center border=0 height=30
bgcolor=lightgreen><tbody><tr><td width=400>");
out.print("<font color=red size=4>Welcome,
</font><u><font color=purple size=4>");
out.print(id+"@ncp.com");
out.print("</font></u><td align=right><input type=button name=time1
style='background:white'></tr></tbody></table>");
out.print("<hr width=100% align=center noshade color=blue/>");
82
Page 23
Website development for a Company
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:company",
"batch11", "bandi");
PreparedStatement ps=con.prepareStatement("select * from company");
ResultSet rs=ps.executeQuery();
while(rs.next()) if(rs.getString(1).equals(id)) leavesrem=rs.getInt(17);
%>
<table width=500 align=center valign=middle height=220 border=0><tbody>
<tr><td width=40% align=right><b>Employee ID : </b>
<%
out.print("<td><b>"+id+"</b><input type=hidden name=id value="+id+">");
out.print("</tr><tr><td align=center colspan=2><b>Your leaves remaining are
"+leavesrem+" </b></tr>");
%>
<tr>
<td width=50% align=right><b>Select how many days you want : </b>
<td>
</tr>
<tr>
<td width=40% align=right>
<b>FROM : </b>
<td><input type=text name="dayfrom">
</tr>
<tr>
<td width=40% align=right>
<b>TO : </b>
<td><input type=text name="dayto">
</tr>
83
Page 24
Website development for a Company
<tr>
<td width=40% align=right >
<b>Nature of leave : </b>
<td><input type=text name="cause">
</tr>
</tbody></table>
<br/><br/>
<center>
<input type=submit value="Apply Leave">
</center>
</form>
</body>
</html>
84
Page 25
Website development for a Company
SEARCH.JSP:
LOGIC:
This page is used to display the internal details of the employee.
The main logic is first search the given name with the names in the database.
If the match found then all the fields of that tuple is displayed.
CODE:
<html>
<head>
<title>Details of Employee</title>
</head>
<body text=lightblue bgcolor=black>
<%
while(rs.next()) if(rs.getString(2).equals(fname)) m=m+1;
if(m==0)
out.print("No one found");
if(m==1)
{
PreparedStatement ps1=con.prepareStatement("select * from company");
ResultSet rs1=ps1.executeQuery();
while(rs1.next())
{
String name=rs1.getString(2);
if(name.equals(fname))
{
%>
<center>
<h2><u>Employee Details</u></h2>
85
Page 26
Website development for a Company
</center>
<table width=500 height=360 align=center border=0 background=bg37.jpg><tbody>
<tr>
<td width=50% align=right height=20><font color=red
size=3>ID : </font>
<td width=50% align=left height=20><font color=white size=3><b>
<%out.print(rs1.getString(1));%>
</b></font>
</tr>
<tr>
<td width=50% align=right height=20><font color=red
size=3>First Name : </font>
<td width=50% align=left height=20><font color=white size=3><b>
<%out.print(name);%>
</b></font>
</tr>
<tr>
<td width=50% align=right height=20><font color=red
size=3>Last Name : </font>
<td width=50% align=left height=20><font color=white size=3><b>
<%out.print(rs1.getString(3));%>
</b></font>
</tr>
86
Page 27
Website development for a Company
<tr>
<td width=50% align=right height=20><font color=red
size=3>Father Name : </font>
<td width=50% align=left height=20><font color=white size=3><b>
<%out.print(rs1.getString(4));%>
</b></font>
</tr>
<tr>
<td width=50% align=right height=20><font color=red
size=3>Date of Birth : </font>
<td width=50% align=left height=20><font color=white size=3><b>
<%out.print(rs1.getString(6));%>
</b></font>
</tr>
<tr>
<td width=50% align=right height=20><font color=red
size=3>Gender : </font>
<td width=50% align=left height=20><font color=white size=3><b>
<%out.print(rs1.getString(7));%>
</b></font>
</tr>
<tr>
87
Page 28
Website development for a Company
<td width=50% align=right height=20><font color=red
size=3>Qualification : </font>
<td width=50% align=left height=20><font color=white size=3><b>
<%out.print(rs1.getString(8));%>
</b></font>
</tr>
<tr>
<td width=50% align=right height=20><font color=red
size=3>Address : </font>
<td width=50% align=left height=20><font color=white size=3><b>
<%out.print(rs1.getString(9));%>
</b></font>
</tr>
<tr>
<td width=50% align=right height=20><font color=red
size=3>Phone Number : </font>
<td width=50% align=left height=20><font color=white size=3><b>
<%out.print(rs1.getString(10));%>
</b></font>
</tr>
<tr>
<td width=50% align=right height=20><font color=red
size=3>Martial Status : </font>
<td width=50% align=left height=20><font color=white size=3><b>
88
Page 29
Website development for a Company
<%out.print(rs1.getString(11));%>
</b></font>
</tr>
<tr>
<td width=50% align=right height=20><font color=red
size=3>Position : </font>
<td width=50% align=left height=20><font color=white size=3><b>
<%out.print(rs1.getString(13));%>
</b></font>
</tr>
<tr>
<td width=50% align=right height=20><font color=red
size=3>Salary : </font>
<td width=50% align=left height=20><font color=white size=3><b>
<%out.print(rs1.getString(14));%>
</b></font>
</tr>
<tr>
<td width=50% align=right height=20><font color=red
size=3>Admit Date : </font>
<td width=50% align=left height=20><font color=white size=3><b>
<%out.print(rs1.getString(16));%>
</b></font>
</tr></tbody></table>
<%
}}}
89
Page 30
Website development for a Company
If more than employees has same name then their corresponding id’s are displayed.
On clicking the corresponding id their internal details are displayed.
if(m>1)
{
PreparedStatement ps2=con.prepareStatement ("select * from
company");
ResultSet rs2=ps2.executeQuery ();
While (rs2.next ())
{
if(rs2.getString(2).equals(fname))
{
out.print("<br/><table width=90% height=120 bgcolor=gray
align=center><tbody>");
out.print("<tr><td width=10% height=33% align=right>");
out.println(fathername+"<td wdith=23% height=33%
align=left>
<a href='http://192.168.100.47:8080/prj/details.jsp?
Id="+rs2.getString(1)+"'>"+rs2.getString(4)+"</a>");
out.print("</font></tr>");
out.print("<tr><td width=10% height=33% align=right>");
out.print(dob);
out.print("<td width=23% height=33% align=left>");
out.print("<font color=white>");
out.print(rs2.getString(6));
out.print("</font></tr>");
out.print("<tr><td width=10% height=33% align=right>");
out.print(gender);
out.print("<td width=23% height=33% align=left>");
out.print("<font color=white>");
90
Page 31
Website development for a Company
out.print(rs2.getString(7));
out.print("</font></tr>");
out.print("<tr><td width=10% height=34% align=right>");
out.print(address);
out.print("<td width=23% height=33% align=left>");
out.print("<font color=white>");
out.print(rs2.getString(9));
out.print("</font></tr></tbody></table");
out.print("<br/><br/><img src='pencil.gif'
align=center/><br/>");
}}}
%><br/>
<center>
<a href="http://192.168.100.47:8080/prj/homepage.html"><img src=home.bmp
border=0></img></a>
<a href="http://192.168.100.47:8080/prj/aboutus.html"><img src=aboutus.bmp
border=0></img></a>
</center>
<hr width=100% color="red">
<font face="Times New Roman" color="yellow">
</font>
</body>
</html>
91