Sie sind auf Seite 1von 31

Website development for a Company 61

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.
Website development for a Company 62

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


Website development for a Company 63

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%>
<img src=ncp.gif width=50 height=70></img>
Website development for a Company 64

<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>
<td width=13% background=banner.bmp>
Website development for a Company 65

<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>
Website development for a Company 66

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;
String id1=null;
Website development for a Company 67

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>");
out.print("<td align=left valign=middle>");
Website development for a Company 68

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>
Website development for a Company 69

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);
}
Website development for a Company 70

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&nbsp;are&nbsp;not&nbsp;qualified&nbsp;in&nbsp;the&nbsp;
Aptitude&nbsp; 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();
</script>
Website development for a Company 71

<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;
}
Website development for a Company 72

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)+".&nbsp;");
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)+"
value=3>"+rs.getString(3)+"&nbsp;&nbsp;&nbsp;&nbsp;");
Website development for a Company 73

%>
<td width=25% valign=top>
<%
out.print("<input type=radio name="+(char)(c+i)+"
value=4>"+rs.getString(4)+"&nbsp;&nbsp;&nbsp;&nbsp;");
%>
<td width=25% valign=top>
<%
out.print("<input type=radio name="+(char)(c+i)+"
value=5>"+rs.getString(5)+"&nbsp;&nbsp;&nbsp;&nbsp;");
%>
<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>

<%
}
Website development for a Company 74

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>
Website development for a Company 75

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;
}
}
}
Website development for a Company 76

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>
Website development for a Company 77

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>[&nbsp;
<a href='http://192.168.100.47:8080/prj/logout.jsp?id="+id+"'>Logout</a>
&nbsp;]</div>");
%>
<br/><table width=100% align=center border=0 height=30
bgcolor=lightgreen><tbody><tr><td width=400>
<font color=red size=4>Welcome,&nbsp;&nbsp;&nbsp;</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);
Website development for a Company 78

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>
Website development for a Company 79

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>[&nbsp;
<a
href='http://192.168.100.47:8080/prj/logout.jsp?id="+mailfrom+"'>Logout</a>
&nbsp;]</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))
m++;
Prepared Statement ps2=con1.prepareStatement ("select * from
Website development for a Company 80

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/>
<tr width=20%>
<td align=center>
Website development for a Company 81

<%
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&nbsp;to&nbsp;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>
Website development for a Company 82

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>[&nbsp;
<a
href='http://localhost:8080/prj/logout.jsp?id="+id+"'>Logout</a>&nbsp;]</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,&nbsp;&nbsp;&nbsp;
</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/>");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Website development for a Company 83

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 :&nbsp;</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&nbsp;:&nbsp;</b>
<td>
</tr>
<tr>
<td width=40% align=right>
<b>FROM&nbsp;:&nbsp;</b>
<td><input type=text name="dayfrom">
</tr>
<tr>
<td width=40% align=right>
<b>TO&nbsp;:&nbsp;</b>
<td><input type=text name="dayto">
</tr>
<tr>
Website development for a Company 84

<td width=40% align=right >


<b>Nature of leave&nbsp;:&nbsp;</b>
<td><input type=text name="cause">
</tr>
</tbody></table>

<br/><br/>
<center>
<input type=submit value="Apply Leave">
</center>
</form>
</body>
</html>
Website development for a Company 85

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>
</center>
<table width=500 height=360 align=center border=0 background=bg37.jpg><tbody>
Website development for a Company 86

<tr>
<td width=50% align=right height=20><font color=red
size=3>ID&nbsp;:&nbsp;</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&nbsp;Name&nbsp;:&nbsp;</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&nbsp;Name&nbsp;:&nbsp;</font>
<td width=50% align=left height=20><font color=white size=3><b>

<%out.print(rs1.getString(3));%>

</b></font>

</tr>
<tr>
Website development for a Company 87

<td width=50% align=right height=20><font color=red


size=3>Father&nbsp;Name&nbsp;:&nbsp;</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&nbsp;of&nbsp;Birth&nbsp;:&nbsp;</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&nbsp;:&nbsp;</font>
<td width=50% align=left height=20><font color=white size=3><b>

<%out.print(rs1.getString(7));%>

</b></font>
</tr>
<tr>

<td width=50% align=right height=20><font color=red


size=3>Qualification&nbsp;:&nbsp;</font>
Website development for a Company 88

<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&nbsp;:&nbsp;</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&nbsp;Number&nbsp;:&nbsp;</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&nbsp;Status&nbsp;:&nbsp;</font>
<td width=50% align=left height=20><font color=white size=3><b>

<%out.print(rs1.getString(11));%>
</b></font>
Website development for a Company 89

</tr>
<tr>
<td width=50% align=right height=20><font color=red
size=3>Position&nbsp;:&nbsp;</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&nbsp;:&nbsp;</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&nbsp;Date&nbsp;:&nbsp;</font>
<td width=50% align=left height=20><font color=white size=3><b>
<%out.print(rs1.getString(16));%>
</b></font>
</tr></tbody></table>
<%
}}}
Website development for a Company 90

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>");
out.print(rs2.getString(7));
Website development for a Company 91

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>