Code 1

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Code 1 as PDF for free.

More details

  • Words: 2,240
  • Pages: 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: Narayana chips (p)Ltd.


Website development for a Company
HRD


64

Website development for a Company


65

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: Human Resource Department <%@ page language="java" %> <%@ page import="java.sql.*" %> <% PreparedStatement ps=null; ResultSet rs=null; Connection con=null; String id1=null;

66

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

"); } } %>

68

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: Aptitude Test <Script language="JavaScript"> var i=899; function timer() { SetInterval ("timers ()", 1000); }

69

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("
"); id1=rs.getString (1); out.print (""+id+" < a href='http://192.168.100.47:8080/prj/details.jsp?id="+id1+"'> "+id1+""); out.print("
"); out.print(""+name+""); out.print(""); out.print(""); out.print(rs.getString(2)); out.print("
"); out.print(""+address+""); out.print("");

67

Website development for a Company out.print(""); out.print(rs.getString(9)); out.print("
You are not qualified in the  Aptitude  Test
.
"); } Window.onLoad=start(); Window.onLoad=timer(); Window.onLoad=state();

70

Website development for a Company

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

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]){ %>
<% out.print((l+i)+". "); out.print(""+rs.getString(2)+""); %>
<% out.print(""+rs.getString(3)+"    ");

Website development for a Company %>
<% out.print(""+rs.getString(4)+"    "); %> <% out.print(""+rs.getString(5)+"    "); %> <% out.print(""+rs.getString(6)+


"); %>

<% i++; } } %>


<% }

73

Website development for a Company else { out.print("<script language='javascript'>alert('Oh ! No, You can't Refresh or Reload this page');"); %> home.bmp
<% } } %>

74

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: <% 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

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++; %>

76

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: <% out.print("
Logout  ]
"); %>
"); } %>
Welcome,    <% while(rs.next()) if(rs.getString(1).equals(id)) { %>
<% out.print(rs.getString(2)); %> <% String subject=rs.getString(3);

77

Website development for a Company

String datetime=rs.getString(4); out.print(""+subject+""); %>


<% out.print(datetime+"


78

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: Sending the mail <% out.print("
Logout  ]
"); 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 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 (); %>


Message send.


80

Website development for a Company

<% out.print("
"); out.print(""); out.print(""); %>
<% } else if(m==0) { out.print("
No such employee exist in the company.

"); } } %>

81

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: Online Leave Taking <% out.print("
Logout ]
"); out.print("
"); out.print("Welcome,    "); out.print(id+"@ncp.com"); out.print("
"); out.print("
"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

82

Website development for a Company

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); %> "); %>

83

Website development for a Company
Employee ID :  <% out.print(""+id+""); out.print("
Your leaves remaining are "+leavesrem+"
Select how many days you want : 
FROM : 
TO : 
Nature of leave : 




84

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: Details of Employee <% 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)) { %>

Employee Details



Website development for a Company

86

Website development for a Company

ID :  <%out.print(rs1.getString(1));%>
First Name :  <%out.print(name);%>
Last Name :  <%out.print(rs1.getString(3));%>

Father Name :  <%out.print(rs1.getString(4));%>
Date of Birth :  <%out.print(rs1.getString(6));%>
Gender :  <%out.print(rs1.getString(7));%>
Qualification : 

87

Website development for a Company
<%out.print(rs1.getString(8));%>
Address :  <%out.print(rs1.getString(9));%>
Phone Number :  <%out.print(rs1.getString(10));%>
Martial Status :  <%out.print(rs1.getString(11));%>

88

Website development for a Company
Position :  <%out.print(rs1.getString(13));%>
Salary :  <%out.print(rs1.getString(14));%>
Admit Date :  <%out.print(rs1.getString(16));%>
<% }}}

89

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("
"); out.print(""); out.print(""); out.print(""); out.print("

"); }}} %>



91

Related Documents

Code 1
November 2019 6
Code
June 2020 11
Code
November 2019 28
Code
July 2020 8
Code
October 2019 32
Code
November 2019 26
"); out.println(fathername+" "+rs2.getString(4)+""); out.print("
"); out.print(dob); out.print(""); out.print(""); out.print(rs2.getString(6)); out.print("
"); out.print(gender); out.print(""); out.print(""); out.print(rs2.getString(7));

90

Website development for a Company out.print("
"); out.print(address); out.print(""); out.print(""); out.print(rs2.getString(9)); out.print("