Java Server Pages
Java Server Pages
Java Server Pages
<html>
<head>
<title>My first JSP page
</title>
</head>
<body>
<%@ page language="java" %> //directive tag
<% out.println("Hello World"); %>//expression tag
</body>
</html>
Output:
1) JSP Directives <%@ -- -- %>
a) include: The include directives allows the
insertion of another file into the defining page.
This insertions happens at translation time.
The syntax is:<%@include file=“URL”%>
Ex: <%@ include file="/header.jsp" %>
first.jsp
<html>
<body>
<h2>This is the beginning of first.jsp</h2>
<%@ include file="second.jsp" %> //directive
<h2>This is the end of first.jsp</h2>
</body>
</html>
Conti..
second.html
<html>
<body>
<center>
<h1>This is from Date.jsp in build library <br>
The date is
<%= new java.util.Date() %> //expression tag
</h1>
</center>
</body>
</html>
Output
Page directive
Language – “scriptingLanguage”
Extends – “classname”
Import – “importList” – java.lang.*, javax.servlet.*,
javax.servlet.jsp.*, and javax.servlet.http.* are imported
implicitily
Session “true|false”
Buffer – “none|sizekb”
autoFlush- “true|false”
isThreadSafe – “true|false”
Info – “info_text”
errorPage – “error_URL”
isErrorPage – “true|false”
contentType – “contentInfo”
pageEncoding – “pageEncodingInfo
Page Directive attibute description:
import
Results in a Java import statement being inserted
into the resulting file.
Ex: <%@ page import="java.util.*" %>
contentType
autoFlush
To autoflush the contents. A value of true, the
default, indicates that the buffer should be
flushed when it is full. A value of false, rarely
used, indicates that an exception should be
thrown when the buffer overflows. A value of
false is illegal when also using buffer="none".
Ex: <%@ page autoFlush="true" %>
Conti.. Page Directive
session
session="true"
When this value is true session data is
available to the JSP page otherwise not. By
default this value is true.
Ex: <%@page language="java“ session="true"%>
buffer
To set Buffer Size. The default is 8k and it is
advisable that you increase it.
Ex: <%@ page buffer="20kb" %>
Conti.. Page Directive
language
language="java"
This tells the server that the page is using
the java language. Current JSP
specification supports only java language.
Ex: <%@ page language="java" %>
Conti… Page Directive
extends
extends="mypackage.myclass"
This attribute is used when we want to extend
any class. We can use comma(,) to import
more than one packages.
Ex: <%@page language="java"
import="java.sql.* , mypackage.myclass" %>
Conti… Page Directive
info
Defines a String that gets put into the
translated page, just so that you can get it
using the generated servlet's inherited
getServletInfo() method.
isThreadSafe
Indicates if the resulting servlet is thread safe.
Ex: <%@ page isThreadSafe="true" %>
Conti… Page Directive
pageEncoding
Defines the character encoding for the JSP.
The default is "ISO-8859-1"(unless the
contentType attribute already defines a
character encoding, or the page uses XML
document syntax).
Program for “checking session’
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page session="true" %> //declaration tag
<html>
<body>
<h2>This is static template data </h2>
<% if (session.isNew()) //scriplet
{ out.println("<h3>New Session</h3>");
}
%>
</body>
</html>
Output:
Conti…
Program for “Counter”
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<%@page contentType="text/html"%> //directive tag
<%@page language="java"%>// directive tag
<html>
<body>
<center>
<h3>This is from Date.jsp <br>
The date is
<%= new java.util.Date() %>//expression tag
</h3>
</center>
</body>
</html>
Output
2) Declaration Tag <%! --- %>
This tag allows the developer to declare
variables or methods.
The declaration are available for reference
by subsequent scriptlet, expression, or
other declaration.
Before the declaration you must have <
%! and end of the declaration is %>.
Conti…. Declaration tag
Code placed in this tag must end in a
semicolon ( ; ).
Declarations do not generate output so are
used with JSP expressions or scriptlets.
Ex:
<%!
private int counter = 0 ;
private String get Account ( int accountNo) ;
%>
Program for “Loop”
<%@page contentType="text/html“%> //directive tag
<HTML>
<HEAD>
<TITLE> JSP loop</TITLE>
</HEAD>
<BODY bgcolor=pink>
<font face=verdana color=darkblue>JSP loop<BR> <BR>
<%! //declaration tag
public String writeThis(int x)
{ String myText="";
for (int i = 1; i < x; i++ )
myText = myText + "<font size= i color=darkred
face=verdana>kirtis loop program</font><br>" ;
return myText;
}
%>
Conti…
This is a loop example from the
<br>
<%= writeThis(8) %> //expression tag
</font>
</BODY>
</HTML>
Output
3) JSP Expression <%= -- - %>
Expression are an evaluation of some Java
statement (without the”;”).
The result must be able to be cast to a String, and is
includes in the servlet’s output.
Expression may be used to set attributes of the
following action tags:
<jsp:setProperty>, <jsp:include>,<jsp:getProperty>,
<jsp:forward>, and <jsp:param>tags.
(we will see after words)
Conti… JSP Expression
The syntax is :-
<jsp:param name=“name” value=“value” />
The value may be populated with an
expression, as in:
<jsp:param name=“today”
value=“<%=new java.util.Date() %>” />
The receiving page obtains the parameter via
Request.getParameter(“name”) method.
Conti.. Control Tag
• The <jsp:include> Action Tag
The standard <jsp:include>action can be
coded as follows:
<jsp:include page: ”news.jsp” flush=“false” />
The name of this tag is jsp:include, the
attributes are page and flush and this
<jsp:include> instance does not have a body.
Conti… Control Tag
• The <jsp:forward> Action Tag
The forward tags is similar to the include tag,
except control over the target page and then
never returned to the original page for this
request.
The syntax foe using<jsp:forward>is:
<jsp:forward page=“URL”>
Conti.. Control Tag
paramTest1.jsp
<html>
<body>
<jsp:include page="paramTest2.jsp">
<jsp:param name="firstname" value="mary" />
</jsp:include>
</body>
</html>
Conti…
paramTest2.jsp
First name is <%=request.getParameter("firstname") %>
Last name is <%= request.getParameter("lastname") %>
Looping through all the first name
<% String first[]=request.getParameterValues("firstname");
for (int i=0;i<first.length;i++)
{ out.println(first[i]);
}
%>
Output
Comments
• Response
• Out
• Session
• Config
• Application
• Page
• pageContext
• exception
What are Implicit Objects?
<%!
public void method()
{ out.print (“Hello”);}
%>
// where out. Is implicit object
•The request and response implicit
objects
The request implicit object is an instance of
HttpServletRequest
Response is an instance of
HttpServletResponse objects
A typical use for the request is to get the
details of HTTP query string such as query
name and parameter
Ex:<%=request.getQueryString() %>
Conti… Implicit Objects
Ex:
<%
String remoteAddr=request.getRemoteAddr();
response.setContentType(“text/html;
charset=ISO-8859-1”);
%>
<html><body>
Hi ! Your IP address is <%=remoteAddr %>
</body></html>
• The out implicit object
Ex:
<html>
<body>
<%@ page session=“false” %>
Session ID = <%=session.getId() %>
</body>
</html>
• The config implicit object
Ex:
<html><body>
Servlet Name =<%=config.getServletName() %>
P region=<%=config.getInitParameter(“region”)%>
</body></html>
• The application implicit object
The application implicit object is an instance
of javax.servlet.ServletContext.
It refers to the overall web application
environment that the JSP belongs to.
According to the API docs :-
“Define a set of methods that a servlet uses
to communicate with its servlet container to
get the MIME type of a file, dispatch request,
or write to a log file.
• The page implicit object
The page implicit object is of type Object and it is
assigned a reference to the servlet that executing
the _jspService() method.
Thus in the Servlet generated by tomcat, the page
object is created as
object page=this;
• To access any of the methods of the servlet through
page, it must be first cast to type servlet
<%this.log(“log message”); %>
<%((HttpServlet)page).log(“another message”) ; %>
are equivalent
•The pageContext implicit object
Definition of JavaBeans:
JavaBeans have become a popular technique
for building reusable Java component.
It represents a simple Java class with some
properties. The bean properties are accessed
by Getter and Setter method. They are used
to separate Business logic from the
Presentation logic. Internally, a bean is just
an instance of a class.
Beans Tags Syntax Overview
Where ,
• bean name = the name that refers to the
bean.
• Bean class = name of the java class that
defines the bean.
• property = name of the property to be passed
to the bean.
• value = value of that particular property.
explanation for the different scopes
Page scope:-Visible only to the first Servlet
or JSP that the request is mapped
object:pageContext
<P><input type=submit</FORM>
</BODY>
</HTML>
Conti…
saveName.jsp
<jsp:useBean id="user" class="kirtipackage.UserData"
scope="session"/>
<jsp:setProperty name="user" property="*"/>
<html>
<body>
<a href="NextPage.jsp">Continue</A>
</body>
</html>
Conti…
nextPage.jsp
<jsp:useBean id="user" class="kirtipackage.UserData"
scope="session"/>
<html>
<body>
You entered<br>
Name: <%= user.getUsername() %><br>
Email: <%= user.getEmail() %><br>
Age: <%= user.getAge() %><br>
</body>
</html>
Conti…
Program for useBean and
getProperty
<html>
<head>
<title> JavaBeans in JSP</title>
</head>
<body>
<jsp:useBean id="test" class="kirtipackage.EmpBean" />
<jsp:setProperty name="test"
property="name"
value="kirtikumar" />
Name is :
<jsp:getProperty name="test" property="name" />
</body>
</html>
Output:
Program for addition of 2 no
<%@page contentType="text/html"%>
<html>
<head><title>JSP Page</title></head>
<body> Programe for addition of nos.<br>
<%=2+5%> is the sum of 2 and 5
</body>
</html>
Output screen of add pgam
Program for “client info”
<html>
<body>
Client computer details: <br><br>
<b>Ip address</b>: <br>
<%=request.getRemoteAddr()%> <br><br>
<b>Computer name</b>:
<br>
<%=request.getRemoteHost()%>
<br><br>
</body>
</html>
Output
program for “Transfer value”
myform.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<title>Linking</title>
</head>
<body>
<form action="myformconfirm.jsp" method="post">
Enter in a website name:<br>
<input type="text" name="website"><br>
<input type="submit" name="submit">
</form>
</body>
</html>
Conti…
myformconfirm.jsp
<html> <head>
<title>Linking implements</title>
</head>
<body>
<font size=3>
Your info has been received:
<br><br>
<%
String sName = request.getParameter("website");
out.print(sName);
%>
</font>
</body>
</html>
Output
JSP- JDBC Connectivity
<% try
{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=
DriverManager.getConnection("jdbc:odbc:kitti");
String sql1="select * from studentreg where UserName=?";
PreparedStatement psmt=con.prepareStatement(sql1);
psmt.setString (1,(String)session.getAttribute("u2")) ;
ResultSet r=psmt.executeQuery();
ResultSetMetaData rsmd=r.getMetaData();
%>
//this is report in row & column format
<table border="1" align="center" bgcolor="#CCAEEF">
<tr><th colspan="1">Student Information</th></tr>
<% while(r.next())
{ for(int i=1;i<=rsmd.getColumnCount();i++)
{ %>
<tr><td colspan="2"><%=rsmd.getColumnName(i) %>
:</td><td colspan="2"><%=r.getString(i)
%></td></tr>
<% } }
}
catch(Exception e)
{
out.println("e");
}
%>
</table>
</body>
</html>
Sregistration.jsp
<%@ page import="java.sql.*" errorPage="errormsg.jsp" %>
<html>
<body bgcolor="#CCAEEF">
<form action="registered.jsp" method=post>
<center><table cellpadding=4 cellspacing=2 border=1><th
colspan=2>
<font size=5>USER REGISTRATION</font><br>
<font size=1><sup>*</sup> Required Fields</font></th><tr>
<td valign=top> <b>First Name<sup>*</sup></b> <br>
<input type="text" name="firstName" value="" size=20
maxlength=20></td>
<td valign=top><b>Last Name<sup>*</sup></b><br>
<input type="text" name="lastName" size=20
maxlength=20></td></tr>
<tr> <td valign=top>
<b>E-Mail<sup>*</sup></b> <br>
<input type="text" name="email" size=20
maxlength=25><br></td>
<td valign=top> <b>Address<sup>*</sup></b> <br>
<input type="text" name="add" size=20
maxlength=125></td>
</tr>
<tr> <td valign=top colspan=2> <b>User
Name<sup>*</sup></b>
<input type="text" name="userName" size=20
maxlength=10> </td></tr>
<tr> <td valign=top> <b>Password<sup>*</sup></b> <br>
<input type="password" name="password" size=20
maxlength=10></td> </tr>
<tr> <td valign=top colspan=2> <b>Stream :
<select name="stream">
<option>Com Sci</option>
<option>Electronics</option>
<option>Mech</option>
<option>Civil</option></select></b> </td> </tr>
<tr>
<td align=center colspan=2>
<input type="submit" value="Submit"> <input type="reset"
value="Reset">
</td> </tr>
</table>
</center>
</form>
</body>
</html
Registrated.jsp
<%@ page import="java.sql.*" errorPage="error.jsp" %>
<html>
<body bgcolor="#CCAEEF">
<% try
{ String fname=request.getParameter("firstName");
String lname=request.getParameter("lastName");
String email=request.getParameter("email");
String address=request.getParameter("add");
String username=request.getParameter("userName");
String Password=request.getParameter("password");
String stream=request.getParameter("stream");
session.setAttribute("firstName",fname);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:kitti");
String sql1="insert into studentreg
(FirstName,LastName,EMail,Address,UserName,Password,S
tream) values(?,?,?,?,?,?,?)";
PreparedStatement psmt=con.prepareStatement(sql1);
psmt=con.prepareStatement(sql1);
psmt.setString(1,fname);
psmt.setString(2,lname);
psmt.setString(3,email);
psmt.setString(4,address);
psmt.setString(5,username);
psmt.setString(6,password);
psmt.setString(7,stream);
psmt.executeUpdate();
%>
<font color="purple" size="5"> <b> <%
out.println("Welcome " +
(String)session.getAttribute("firstName"));%>
</b></font> <br><br><br>
<a href="SLogin.jsp"><b>Back to Login Page
</b></a><br><br>
<% con.close() :}
catch(Exception e)
{ out.println(e);
} %>
</body>
</html>
Errormsg.jsp
<%@ page isErrorPage="true" %>
<html>
<head>
<title>Error Page:</title>
</head>
<body>
<h2>Somethings has gone wrong..</h2>
<%=exception%>
</body>
</html>
Error.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>JSP Page</title>
</head>
<body bgcolor="#CCAEEF">
<h1> No such user found<h1>
</body>
</html>
Library Management
Problem Statement:
In this program we add books of
different subject with author name, price, year
of book etc.
After adding we can search any book by
its name, if this this book found it will show
details of book in table format.
Home Page:
Adding of Book:
Search Book:
Details of Book:
JSP Code for Library Management
Home.jsp
<html>
<head>
<title>Library Management Page</title>
</head>
<body bgcolor="#ABCEEF">
<h2><center>Library Management
System</center></h2><br><br>
<a href="Addbooks.jsp"><font color="black"><b>ADD
BOOKS </b></font></a><br><br>
<a href="Searchbooks.jsp"><font
color="black"><b>SEARCH BOOKS
</b></font></a><br><br>
</body>
</html>
Addbook.jsp
<html>
<head>
<title>ADD BOOKS JSP Page</title>
</head>
<body bgcolor="#ABCEEF">
<form action="Addbooksback.jsp"
method="post"><font color="black">
<br><br><br><center><h2>Book Details</h2>
<table border="1" cellspacing="%20">
<tr><td><b>Title:</b></td> <td><input type="text"
name="t1" size="15"></td></tr>
<tr><td><b>Author:</b></td> <td><input type="text"
name="t2" size="15"></td></tr>
<tr><td><b>Publication:</b></td> <td><input
type="text" name="t3" size="15"></td></tr>
<tr><td><b>Price:</b></td> <td><input type="text"
name="p1" size="15"></td></tr>
<tr><td><b>Year:</b></td><td><input type="text"
name="y2" size="15"></td></tr>
</table>
<br>
<b><input type="submit" name="sub" value="submit" >
</b>
</center>
</font>
</form>
AddBookback.jsp
<%@page import="java.sql.*"%>
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<% String title=request.getParameter("t1");
String author=request.getParameter("t2");
String publication=request.getParameter("t3");
int price=Integer.parseInt(request.getParameter("p1"));
String year=request.getParameter("y2");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection ("jdbc:odbc:lib");
PreparedStatement pstmt=con.prepareStatement("insert into
Book (title,author,publication,price,year)values(?,?,?,?,?)");
pstmt.setString(1,title);
pstmt.setString(2,author);
pstmt.setString(3,publication);
pstmt.setInt(4,price);
pstmt.setString(5,year);
pstmt.executeUpdate();
response.sendRedirect("information.jsp");
%>
</body>
</html>
Searchbook.jsp
<html>
<body bgcolor="#ABCEEF"><br><br><br>
<form action="Searchbooksback.jsp" method="post">
<font color="black">
<table border="1" align="center">
<tr><td><b>Title:<input type="text"
name="t1"></b></td></tr>
<tr><td><b><center><input type="submit"
name="sub" value="submit"></center</b></td></tr>
</table>
</font>
</form>
</body>
</html>
Searchbookback.jsp
<%@page import="java.sql.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>JSP Page</title>
</head>
<body bgcolor="#ABCEEF">
<form action="LibraryManagement.jsp"
method="post">
<font color="black"><br><br>
<table border="1" align="left" cellpadding="10%">
<tr><td><b>Title</b></td><td><B>Author</B></td><td><B>
Publication</B></td><td><B>Price</td><td><B>Year
</B></td></tr>
<%
String title=request.getParameter("t1") ;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=
DriverManager.getConnection("jdbc:odbc:lib");
PreparedStatement pstmt=con.prepareStatement("select *
from book where title=?");
pstmt.setString(1,title);
ResultSet rs=pstmt.executeQuery();
while(rs.next()) { %>
<font color="black"><br><br>
<tr><td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getInt(4)%></td>
<td><%=rs.getString(5)%></td></tr>
</font> <%}%>
<tr><input type="submit" name="sub"
value="Back to HomePage"></tr>
</table>
</body>
</html>
Information.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="LibraryManagement.jsp"
method=post>
<h2> Book details updated successfully</h2>
<br> <input type="submit" name="back"
value="Back">
</form>
</body>
</html>
Employee Management System
Problem Statement:
In this program add information about
Employee like emp_id, post, name , birth
date etc..
After storing information about Employee
we can search them by post .
Home Page
Add Page
Search Page
Details of Employee
Home page
Employeemanagement.jsp
<html>
<head>
<title>JSP Page</title>
</head>
<body bgcolor="pink">
<center><h2>Employee Management System
</h2></center><br><br><br>
<a href="AddEmployee.jsp"><font color="black">ADD
EMPLOYEE </font></a><br><br>
<a href="Searchemployee.jsp"><font
color="black">SEARCH EMPLOYEE
</font></a><br><br>
</body>
</html>
AddEmployee.jsp
<html>
<head>
<title>JSP Page</title>
</head>
<body bgcolor="pink"><br><br><br>
<form action="AddEmployeeback.jsp" method="post">
<table border="1" align="center">
<tr><td>Employee_ID:</td><td><input type="text"
name="w1"></td></tr>
<tr><td>Employee_Name:</td><td><input type="text"
name="w2"></td></tr>
<tr><td>National_ID:</td><td><input type="text"
name="w3"></td></tr>
<tr><td>Post:</td>
<td> <select name="w4">
<option>Engineer</option>
<option>Doctor</option>
<option>Mechanical</option>
<option>Proffessor</option>
</select>
</td><tr>
<tr><td>Birth_Date:</td><td><input type="text"
name="w5"></td></tr>
<tr><td>Marital:</td><td><input type="text"
name="w6"></td></tr>
<tr><td>Gender:</td><td><input type="text"
name="w7"></td></tr>
<tr><td>Highest Degree Earned:</td>
<td>
<select name="w8">
<option>HighSchool</option>
<option>Bachelor</option>
<option>Master</option>
<option>PhD</option>
</select>
</td></tr>
<tr><td colspan="2"><center><input type="submit"
name="sub" value="submit"></center></td></tr>
</table>
</form>
</body>
</html>
Addemployeeback.jsp
<%@page import="java.sql.*" %>
<html>
<body>
<% try
{ int
empid=Integer.parseInt(request.getParameter("w1"));
String empname=request.getParameter("w2");
int
natid=Integer.parseInt(request.getParameter("w3"));
String post=request.getParameter("w4");
String bdate=request.getParameter("w5");
String marital=request.getParameter("w6");
String gender=request.getParameter("w7");
String degree=request.getParameter("w8");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:empl");
PreparedStatement pstmt=con.prepareStatement ("insert
into Employee
(eid,ename,nid,post,bdate,marital,gender,degree)
values(?,?,?,?,?,?,?,?)");
pstmt.setInt(1,empid);
pstmt.setString(2,empname);
pstmt.setInt(3,natid);
pstmt.setString(4,post);
pstmt.setString(5,bdate);
pstmt.setString(6,marital);
pstmt.setString(7,gender);
pstmt.setString(8,degree);
pstmt.executeUpdate();
con.commit();
pstmt.close();
con.close();
response.sendRedirect("information.jsp");
} catch(Exception e)
{ out.println(e);
} %>
</body>
</html>
Information.jsp
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<form action="Employeemanagement.jsp"
method="post">
<h2>Employee details updated successfully</h2>
<br>
<input type="submit" name="sub" value="Back">
</form>
</body>
</html>
Searchemployee.jsp
<html>
<head>
charset=UTF-8">
<title>JSP Page</title>
</head>
<body bgcolor="#ABCEEF"><br><br><br>
<form action="Searchemployeeback.jsp" method="post">
<font color="black"> <table border="1" align="center">
<tr><td><b>Post:</td> <td> <select name="w4">
<option>Engineer</option>
<option>Doctor</option>
<option>Mechanical</option>
<option>Proffessor</option>
</select> </td>
</table><br> <br>
<b><center><input type="submit" name="sub"
value="submit"></center></b>
</font>
</form>
</body>
</html>
Searchemployeeback.jsp
<%@page import="java.sql.*"%>
<html>
<title>JSP Page</title>
<body bgcolor="#ABCEEF">
<font color="black"><br><br>
<table border="1" align="center" cellpadding="10%">
<th colspan="8">Employee Details</th>
<tr><td><b>Employee_Id</b></td>
<td><b>Employee_Name</b></td>
<td><b>National_Id</td><td><b>Post</b></td><td><b>
Birth Date </b></td> <td> <b>Merital</b></td>
<td><b>Gender</b></td> <td> <b>Highest Degree</b>
</td></tr>
<%
String post=request.getParameter("w4");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:empl");
PreparedStatement
pstmt=con.prepareStatement("select * from
Employee where post=?");
pstmt.setString(1,post);
ResultSet rs=pstmt.executeQuery();
while(rs.next()) { %>
<font color="black"><br><br>
<tr><td><%=rs.getInt(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getInt(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>
</font> <% } %>
</table><br><br>
<center> <a href="Employeemanagement.jsp"> <font
color="black">Back To Home Page </font></a></center>
</body>
</html>
Teaching Staff Information System
</table>
</font>
</form>
</body>
</html>
Modifyrecordback.jsp
<%@page import="java.sql.*"%>
<html>
<body bgcolor="pink">
<%
try {
String scode=request.getParameter("q1");
String fname=request.getParameter("q2");
String minit=request.getParameter("q3");
String lname=request.getParameter("q4");
String wkdept=request.getParameter("q5");
String phnno=request.getParameter("q6");
String hdate=request.getParameter("q7");
String level=request.getParameter("q8");
String sex=request.getParameter("q9");
String bdate=request.getParameter("q10");
String salary=request.getParameter("q11");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:cust");
String sql1="update Customer set
Staff_Code=?,Staff_FName=?,Staff_MInit=?,Staff_LName=?,Staff_Wk
Dept=?,Staff_PNo=?,Staff_HDate=?,Staff_Level=?,Staff_Sex=?,Sta
ff_BDate=?,Staff_Salary=? where Staff_Code=? and
Staff_FName=?";
PreparedStatement psmt=con.prepareStatement(sql1);
psmt.setString(1,scode);
psmt.setString(2,fname);
psmt.setString(3,minit);
psmt.setString(4,lname);
psmt.setString(5,wkdept);
psmt.setString(6,phnno);
psmt.setString(7,hdate);
psmt.setString(8,level);
psmt.setString(9,sex);
psmt.setString(10,bdate);
psmt.setString(11,salary);
String staff_code=(String)session.getAttribute("c1");
String staff_fname=(String)session.getAttribute("c2");
psmt.setString(12,staff_code);
psmt.setString(13,staff_fname);
psmt.executeUpdate();
psmt.close();
con.close();
}
catch(Exception e)
{
out.println(e);
}
%>
<center>Staff Record Successfully<br><br>
<a href="Customermanagement.jsp">Back </a></center>
</body>
</html>
Searchrecord.jsp
<html>
<body bgcolor="#ABCEEF"><br><br><br>
<form action="Searchrecordback.jsp" method="post">
<font color="black">
<table border="1" align="center">
<tr><td><b>Search By:<select name="t1">
<option>Department</option>
<option>Level</option>
</select></b></td></tr>
<tr><td><b><center><input type="submit" name="sub"
value="submit"></center</b></td></tr>
</table>
</font>
</form>
</body>
</html>
Searchrecordback.jsp
<%@page import="java.sql.*"%>
<html>
<body bgcolor="#ABCEEF">
<form action="deptoption.jsp" method="post">
<%
String searchby=request.getParameter("t1");
if(searchby.equalsIgnoreCase("department"))
{%>
<h3>Select Department</h3>
Electronics<input type="radio" name="r1" value="Electronics"><br>
Mechanical <input type="radio" name="r1" value="Mechanical"><br>
Civil<input type="radio" name="r1" value="Civil"><br>
Electrical<input type="radio" name="r1" value="Electrical"><br>
Textile<input type="radio" name="r1" value="Textile"><br>
Computer<input type="radio" name="r1" value="Computer"><br><br>
<input type="submit" value="Submit">
<%}
else
{
%>
<h3>Select Level</h3>
Lecturer <input type="radio" name="r1" value="Lecturer"><br>
Teacher <input type="radio" name="r1" value="Teacher"><br>
Professor <input type="radio" name="r1" value="Professor">
<br><br>
<input type="submit" value="Submit">
<%
}%>
</form>
</body>
</html>
deoption.jsp
<%@page import="java.sql.*"%>
<html>
<body bgcolor="#ABCEEF">
<table border="1" align="center" cellpadding="10%">
<th colspan="11"><h2>Staff Information</h2></th>
<tr bgcolor="yellow"><td><b>Staff Code</b></td><td><b>First
Name</b></td><td><b>MInit Name</td><td><b>Last
Name</b></td><td><b>Work Dept</b></td><td><b>Phone
No</b></td><td><b>Hire
Date</b></td><td><b>Level</b></td><td><b>Sex</b></td><td><b>Bi
rth Date</b></td><td><b>Salary</b></td></tr>
<% try{
String deptname=request.getParameter("r1");
if((deptname.equalsIgnoreCase("Computer"))||
(deptname.equalsIgnoreCase("Civil")) ||
(deptname.equalsIgnoreCase("Mechanical"))||
(deptname.equalsIgnoreCase("Textile"))||
(deptname.equalsIgnoreCase("Electronic"))||
(deptname.equalsIgnoreCase("Electrical")))
{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:cust");
String sql1="select * from Customer where Staff_WkDept=?";
PreparedStatement psmt=con.prepareStatement(sql1);
psmt.setString(1,deptname);
ResultSet rs=psmt.executeQuery();
while(rs.next())
{ %> <tr bgcolor="pink"><td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></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>
<td><%=rs.getString(9)%></td>
<td><%=rs.getString(10)%></td>
<td><%=rs.getString(11)%></td>
</tr>
<% } psmt.close(); con.close();
}
else
{ String level=request.getParameter("r1");
if((deptname.equalsIgnoreCase("Professor"))||
(deptname.equalsIgnoreCase("Lecturer")) ||
(deptname.equalsIgnoreCase("Teacher")) )
{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:cust");
String sql1="select * from Customer where Staff_Level=?";
PreparedStatement psmt=con.prepareStatement(sql1);
psmt.setString(1,level);
ResultSet rs=psmt.executeQuery();
while(rs.next())
{ %>
<tr bgcolor="pink"><td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></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>
<td><%=rs.getString(9)%></td>
<td><%=rs.getString(10)%></td>
<td><%=rs.getString(11)%></td>
</tr>
<% }
psmt.close();
con.close();
} }}
catch(Exception e)
{ out.println(e);
}
%>
</table>
<center><a href="Customermanagement.jsp">
<font color="black"><h3><b>Back To Home Page
</b></h3></font></a></center>
</body>
</html>
Program for “Baby Game”
Input Form
Conti…
Output Form:
Home Page
BabyGame.jsp
<html>
<head>
<title>Baby Game Page</title>
</head>
<body bgcolor="#FFFFFF">
<form method="post" action="BabyGame1.jsp"
name="">
<center>
<h3>Baby Game</h3>
</center>
<br>
<table border cols=5 width="75%" >
<caption>Please enter your own name:
<input type="text" name="guesser"></caption><tr><td>
<br><input type="radio" name="gender" value="Female"
checked>Female
<p><input type="radio" name="gender" value="Male"
checked> Male
</p></td>