Advanced Java Full Notes Till 20 June
Advanced Java Full Notes Till 20 June
dt : 27/4/2022(day-1)
part-1 : CoreJava
=>Alphabets(Programming Components)
(a)Variables
(b)Methods
(c)Blocks
ii
(d)Constructors
ath
(e)Classes
(f)Interfaces
ip
(g)AbstractClasses
=>Programming Concepts
Application.
nk
as Web Application.
construct WebApplications:
[Link]
[Link]
[Link]
[Link]:
ii
Connectivity' and which is used to establish
ath
connection b/w JavaProgram and DB product.
ip
[Link]:
Ma
=>Servlet means 'Server program' and which
the response.
sh
[Link]:
ate
(a)Field Storage
(b)Object Storage
Ve
(c)File Storage
(d)DataBase Storage
(a)Field Storage:
field Storage.
*imp
(b)Object Storage:
ii
=>The memory generated to hold group members
ath
is known as Object Storage.
ip
class Addition
int a,b,c;
Ma
void add()
sh
{
c = a+b;
ate
Sop(c);
}
nk
}
Ve
ip
faq:
(ii)Object reference
sh
(iii)Object reference Variable
ate
(i)Object:
is known as Object.
Ve
(ii)Object reference:
as Object reference.
--------------------------------------------------
Summary:
ii
(ii)NonPrimitive DataType Variable
ath
(Reference DataType Variable)
ip
NonPrimitive DataType variables will hold Object references.
Ma
=========================================================
Note:
=>File Storage
=>DataBase Storage
Ve
ii
ip ath
Ma
============================================================
faq:
sh
define API?
JavaLib:
CoreJava:
AdvJava:
ii
(iii)[Link] - JSP parogramming
ath
============================================================
*imp
ip
(c)File Storage:
Ma
=>The smallest permanent storage of computer System,which is
File Storage.
sh
Note:
Diagram:
Ve
ii
ip ath
faq: Ma
define output stream?
output stream.
sh
ate
faq:
=>The Java program reading the data from the file storage is
nk
----------------------------------------------------------
Dt : 29/4/2022
faq:
define Stream?
[Link] Stream
[Link] Stream
[Link] Stream:
ii
=>The contineous flow of data in the form of 8-bits is known as
ath
ByteStream or Binary Stream.
ip
[Link] Stream:
Ma
=>The contineous flow of data in the form of 16-bits is known as
===========================================================
[Link] Redundancy
[Link] Inconsistency
[Link] Problems
[Link] Problems
[Link] problems
===================================================================
Note:
ii
for JavaApplications.
ath
===============================================================
*imp
ip
(d)DataBase Storage:
Ma
=>The largest Permanent Storage which is installed from
Note:
sh
=>In the process of establishing communication b/w JavaProgram
Diagram:
Ve
ii
ip ath
=======================================================
Ma
define "driver"?
Audio driver
Video driver
nk
N/W driver
...
Ve
ii
[Link] driver(Type-4)
ath
Note:
ip
=>In realtime we use 'Thin driver' for application development.
Ma
==================================================================
Dt : 30/4/2022
*imp
sh
Making System Environment ready to construct JDBC Application:
ate
ii
---------- --------------- ---------- ----------
ath
A111 Mouse 1200 12
ip
A105 CDR 1300 13
A104
A100
FDD
CDR
700
1200
3
45
Ma
sh
SQL>
ate
step-5 : Find DB-Jar file and copy into one User defined folder.
nk
C:\oraclexe\app\oracle\product\11.2.0\server\jdbc\lib
*imp
[Link]
ii
Oracle10 - [Link]
ath
Oracle11 - [Link]
oracle12 - [Link],[Link]
ip
other - [Link]
MySQL
Ma
- [Link]
SQLite - [Link]
C:\oraclexe\app\oracle\product\11.2.0\server\network\ADMIN
PortNo : 1521
ServiceName : XE
=====================================================
*imp
JDBC API:
ii
and Interfaces' used in JDBC application development.
ath
=>'[Link]' interface is the root of JDBC API.
ip
interface:
[Link]()
Ma
- this method will create implementation object Statement
interface.
sh
[Link]()
[Link]()
ate
[Link]()
[Link]()
nk
[Link]()
[Link]()
Ve
[Link]()
[Link]()
JavaProgram.
Hierarchy of 'Connection' interface:
ii
ath
===========================================================
ip
Dt : 2/5/2022
Note:
Ma
=>we use getConnection() method from '[Link]' class
throws [Link];
Ve
syntax:
("DB-url","uname","pword");
Diagram:
ii
ip ath
Ma
sh
ate
nk
Ve
==========================================================
*imp
Types of JDBC-statements:
=>JDBC statements are used to perform operations on DataBase
product.
[Link]
[Link]
[Link]
ii
ath
[Link]:
ip
used to execute normal queries without IN parameters.
Ma
=>The fllowing are some important methods from 'Statement'
interface:
(i)executeQuery()
sh
(ii)executeUpdate()
ate
(i)executeQuery():
Method Signature:
throws [Link];
(ii)executeUpdate():
throws [Link];
---------------------------------------------------------
Note:
ii
create the implementation object of 'Statement' interface.
ath
Method Signature of createStatement():
ip
throws [Link];
syntax:
Ma
Statement stm = [Link]();
sh
--------------------------------------------------------------
*imp
ate
step-1 : open IDE Eclipse,while opening name the WorkSpace and click
nk
'Launch'
ii
step-5 : Create class in Package and type the code
ath
RightClick on package->new->Class,name the class and click 'finish'
Program No :: 01
ip
package test;
import [Link].*;
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
while([Link]()) {
Ve
[Link]([Link](1)+"\t"
+[Link](2)+"\t"
+[Link](3)+"\t"
+[Link](4));
}//end of loop
[Link]();
}catch(Exception e) {[Link]();}
ii
ath
step-6 : Execute the program
====================================================
ip
Dt : 4/5/2022
faq:
define ResultSet?
Ma
=>ResultSet is an interface from [Link] package and which hold result
sh
of select query.
of 'ResultSet' interface.
first row.
=>we use next() method to move the cursor row-by-row and which is boolean
return type.
Diagram:
ii
ip ath
Ma
================================================================
Ex_Application-2: ( Program No :: 02 )
sh
write JDBC application to read Product details from Console and insert into
DB Table product45.
ate
package test;
import [Link].*;
import [Link].*;
public class DBCon2 {
nk
ii
}
ip ath
==============================================================
Assignment-1:
Ma
DB Table : Book45(bcode,bname,bauthor,bprice,bqty)
sh
Prog-1 : JDBC Application to read book details from Cosole and insert into
Prog-3 : JDBC Application to display book details based on book code. ( Program No :: 05 )
nk
==============================================================
Assignment-2:
Ve
DB Table : Employee45(eid,ename,edesg,bsal,totsal)
Prog-1 : JDBC Application to read employee details from Cosole and insert into
Note:
Calculate totSal based on bSal using the following formula:
totSal = bSal+HRA+DA;
DA = 63% of bSal
ii
Prog-2 : JDBC Application to display all Employee details ( Program No :: 07 )
ath
Prog-3 : JDBC Application to display Employee details based on eId.
( Program No :: 08 )
=====================================================================
ip
Ma
sh
ate
nk
Ve
Dt : 5/5/2022
Ex_Application :
Program : [Link]
package test;
ii
import [Link].*;
ath
import [Link].*;;
ip
public static void main(String[] args) {
try {
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
ResultSet rs = [Link]
if([Link]()) {
[Link]([Link](1)+"\t"+
[Link](2)+"\t"+[Link](3)+
"\t"+[Link](4));
}else {
[Link]("Invalid ProdCode...");
[Link]();
[Link]();
}catch(Exception e) {[Link]();}
ii
}
ath
o/p:
ip
A222
A222 KB 1300.0 13
Ma
================================================================
*imp
sh
[Link]:
(i)executeQuery()
(ii)executeUpdate()
Ve
(i)executeQuery():
Method Signature:
Method Signature:
----------------------------------------------------------------
ii
=>we use prepareStatement() method from 'Connection' interface to create the
ath
implementation object of 'PreparedStatement' interface.
ip
public abstract [Link] prepareStatement([Link])
syntax:
Ma
throws [Link];
PreparedStatement ps = [Link]("query-structure");
sh
========================================================================
Prog-1 : JDBC Application to read employee details from Console and insert into
ate
Note:
nk
totSal = bSal+HRA+DA;
DA = 63% of bSal
DB Table : Employee45(eid,ename,edesg,bsal,totsal)
create table Employee45(eid varchar2(10),ename varchar2(15),edesg varchar2(10),
Program : [Link]
package test;
ii
import [Link].*;
ath
import [Link].*;
ip
public static void main(String[] args) {
try {
Ma
Scanner s = new Scanner([Link]);
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
PreparedStatement ps = [Link]
[Link](1,eId);
[Link](2,eName);
[Link](3,eDesg);
ii
[Link](4, bSal);
ath
[Link](5, totSal);
ip
int k = [Link]();//Execution process
if(k>0) {
Ma
[Link]("Employee Details inserted Successfully...");
sh
}
[Link]();
ate
[Link]();
}catch(Exception e) {[Link]();}
nk
}
Ve
o/p:
A121
Raj
Enter the EmpDesg:
SE
12000
ii
ip ath
Ma
============================================================
faq:
Note:
Ve
=>we use setter methods to set the data to the fields based on parameter index
==============================================================
faq:
=>In PreparedStatement the query is compiled once and can be executed any
number of times by setting the values.
================================================================
Assignment:
DB Table : UserReg45(uname,pword,fname,lname,addr,mid,phno)
ii
Construct JDBC Application to perform the following operations based on User
ath
Choice:(Using PreparedStatement)
[Link]
ip
[Link]
[Link]:
Ma
=>read user details from console and insert in to DBtable UserReg45.
sh
[Link]:
ate
=>read uname and pword from the console and display the following msg:
Login Successfull...
nk
===========================================================================
Ve
Dt : 7/5/2022
DB Table : UserReg45
ii
( Program No :: 09 )
ath
Program : [Link]
package test;
ip
import [Link];
import [Link].*;
import [Link].*;
Ma
public class DBCon5 {
sh
public static void main(String[] args) {
try {
ate
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
while(true) {
[Link]("====Choice====");
[Link]("[Link]\[Link]\[Link]");
switch(choice)
case 1:
ii
[Link]("Enter the UserName:");
ath
String uName = [Link]();
ip
String pWord = [Link]();
Ma
[Link]("Enter the FirstName:");
[Link](1,uName);
[Link](2,pWord);
[Link](3,fName);
[Link](4,lName);
[Link](5,addr);
[Link](6,mId);
[Link](7,phNo);
int k = [Link]();
ii
if(k>0) {
ath
[Link]("User Registered Successfully");
ip
break;
case 2:
Ma
[Link]("Enter the UserName:");
String uN = [Link]();
sh
[Link]("Enter the PassWord:");
String pW = [Link]();
ate
[Link](1,uN);
nk
[Link](2, pW);
Ve
ResultSet rs = [Link]();
if([Link]()) {
[Link]("Login Successfull...");
}else {
[Link]("Invalid Login Process...");
break;
case 3:
[Link]("Program terminated...");
[Link](0);
ii
default:
ath
[Link]("Invalid Choice...");
}//end of switch;
ip
}//end of loop
//[Link]();
}catch(Exception e) {[Link]();}
Ma
}
sh
}
============================================================
ate
Ex_Application:
Program : [Link]
Ve
package test;
import [Link].*;
import [Link].*;
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
ii
PreparedStatement ps1 = [Link]
ath
("select * from Product45 where pcode=?");
ip
("update Product45 set pprice=?,pqty=pqty+? where pcode=?");
[Link](1,pCode);
Ma
ResultSet rs = [Link]();
sh
if([Link]()) {
[Link]("Old price:"+[Link](3));
ate
[Link]("Available qty:"+[Link](4));
[Link](1,newPrice);
[Link](2,newQty);
[Link](3, pCode);
int k = [Link]();
if(k>0) {
}else {
[Link]("Invalid ProdCode...");
ii
}
ath
[Link]();
}catch(Exception e) {[Link]();}
ip
}
}
Ma
===========================================================
Ex_Application:
sh
JDBC Application to delete Product on pCode?
ate
Program : [Link]
package test;
nk
import [Link].*;
import [Link].*;
Ve
try {
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
ii
("delete from Product45 where pcode=?");
ath
[Link](1,pCode);
ip
ResultSet rs = [Link]();
if([Link]()) {
[Link](1,pCode);
Ma
int k = [Link]();
sh
if(k>0) {
}else {
nk
[Link]("Invalid ProdCode...");
}
Ve
[Link]();
}catch(Exception e) {[Link]();}
=========================================================
Assignment: ( Program No :: 10 )
[Link]
[Link]
[Link]
ii
[Link](price and qty)
ath
[Link]
ip
Dt : 9/5/2020
*imp
[Link]:
Ma
=>CallableStatement is an interface from [Link] package and
sh
which is used to execute Procedures and Functions on DB-Product.
([Link])throws [Link];
Ve
syntax
CallableStatement cs = [Link]("Proc/Func");
define Procedure?
structure of procedure:
ii
(para_list) is
ath
begin
query1;
ip
query2;
end;
...
Ma
/
sh
define Function?
ate
Note:
structure of Function:
begin
query1;
query2;
....
return var;
ii
end;
ath
/
========================================================================
ip
*imp
Bank45(accno,custname,balance,acctype)
ate
CustDetails45(accno,addr,mid,phno)
nk
begin
ii
insert into CustDetails45 values(accno,addr,mid,phno);
ath
end;
ip
Ma
step-3 : construct JDBC application to execute procedure
( Program NO :: 11 )
Program : [Link]
sh
package test;
import [Link].*;
ate
import [Link].*;
try {
Ve
ii
[Link]("Enter the MailId:");
ath
String mId = [Link]();
ip
long phNo = [Link]();
Ma
Connection con = [Link]
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
sh
CallableStatement cs = [Link]
("{call CreateAccount45(?,?,?,?,?,?,?)}");
ate
[Link](1,accNo);
[Link](2,custName);
nk
[Link](3,bal);
[Link](4,accType);
Ve
[Link](5,addr);
[Link](6, mId);
[Link](7, phNo);
[Link]();
[Link]("Procedure executed Successfully...");
[Link]();;
[Link]();
}catch(Exception e) {[Link]();}
ii
}
ath
o/p:
ip
6123456
Raj
Ma
Enter the Balance:
sh
12000
savings
SrNagar
r@[Link]
7878781234
---------------------------------------------------------
Diagram:
ii
ath
=========================================================
Assignment:
ip
Create and execute procedure
Ma
Step-1 : Construct DB Tables
sh
EmpData45(eid,ename,edesg)
ate
EmpAddress45(eid,hno,sname,city,pincode)
EmpContact45(eid,mid,phno)
EmpSalary45(eid,bsal,totsal)
nk
=========================================================
Dt : 10/5/2022
Types of Procedures:
(i)IN-Parameter Procedures
(ii)OUT-Parameter Procedures
(i)IN-Parameter Procedures:
=>The procedures which take the data from JavaProgram and update
Ex:
above program([Link])
ii
ath
(ii)OUT-Parameter Procedures:
=>The procedures which take the data from DB-Tables and sent to
ip
JavaProgram are known as OUT-Parameter Procedures.
Ex:
Ma
Construct Procedure to display the Complete details of
sh
Customer based on accno.
ate
accno.
nk
begin
( Program No :: 12 )
Program : [Link]
ii
package test;
ath
import [Link].*;
import [Link].*;
ip
public class DBCon9 {
Ma
public static void main(String[] args) {
try {
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
nk
CallableStatement cs = [Link]
("{call RetrieveDetails45(?,?,?,?,?,?,?)}");
Ve
[Link](1, accNo);
[Link](2,[Link]);
[Link](3,[Link]);
[Link](4,[Link]);
[Link](5,[Link]);
[Link](6,[Link]);
[Link](7,[Link]);
[Link]();
[Link]("AccNo:"+accNo);
[Link]("CustName:"+[Link](2));
[Link]("Balance:"+[Link](3));
ii
[Link]("AccType:"+[Link](4));
ath
[Link]("Address:"+[Link](5));
[Link]("MailId:"+[Link](6));
ip
[Link]("PhoneNO:"+[Link](7));;
[Link]();
Ma
}catch(Exception e) {[Link]();}
}
sh
}
ate
o/p:
6123456
AccNo:6123456
Ve
CustName:Raj
Balance:12000.0
AccType:savings
Address:SrNagar
MailId:r@[Link]
PhoneNO:7878781234
-----------------------------------------------------------
faq:
ii
OUT-Parameter procedure.
ath
------------------------------------------------------------
faq:
ip
wt is the advantage of Procedures?
Ma
=>Using Procedures we can execute multiple queries at-a-time and
application.
sh
-----------------------------------------------------------
Assignment:
ate
based on eId.
nk
=================================================================
*imp
Ve
begin
return bal;
end;
ii
ath
step-2 : JDBC Application to execute function
( Program No :: 13 )
ip
Program : [Link]
package test;
import [Link].*;
Ma
import [Link].*;
sh
public class DBCon10 {
try {
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
CallableStatement cs = [Link]
("{call ? := RetrieveBalance45(?)}");
[Link](1,[Link]);
[Link](2,accNo);
[Link]();
[Link]("AccNo:"+accNo);
[Link]("Balance:"+[Link](1));
[Link]();
[Link]();
ii
}catch(Exception e) {[Link]();}
ath
}
ip
o/p:
6123456
Ma
AccNo:6123456
sh
Balance:12000.0
=========================================================
ate
Assignment:
=========================================================
Ve
=========================================================
Dt : 12/5/2022
process'.
ii
Behaviour:
ath
(i)User picks the DataBase connection from the Pool.
ip
(iii)After usage returns the Connection back to the pool.
Note:
Ma
=>we take the support of Vector<E> to construct Connection
sh
Pooling Process.
Hierarchy of Vector<E>:
Ve
ii
ath
-------------------------------------------------------
ip
Ex_program: ( Program No :: 14 )
[Link]
Ma
package test;
import [Link].*;
sh
import [Link].*;
ate
[Link]=url;
Ve
[Link]=uname;
[Link]=pword;
{
try {
while([Link]()<5)
Connection con=[Link]
(url,uname,pword);
ii
[Link](con);//Adding the connection to Pool
ath
[Link](con);
}//end of loop
ip
if([Link]()==5)
{
Ma
[Link]("Connection Pool is full...");
}
sh
}catch(Exception e) {[Link]();}
}//end of method
ate
{
nk
return con;
}//end of method
[Link]
ii
package test;
ath
import [Link].*;
import [Link].*;
public class DBCon12 {
public static void main(String[] args) {
ConnectionPool cp = new ConnectionPool
ip
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
Ma
[Link]();
[Link]("Pool Size:"+[Link]());
Connection con = [Link]();
[Link]("User using : "+con);
[Link]("Pool Size:"+[Link]());
[Link](con);
sh
[Link]("Pool Size:"+[Link]());
[Link]("====Display the Connection from
Pool====");
ate
[Link]((k)->
{
[Link](k);
});
nk
}
}
Ve
Ve
nk
ate
sh
Ma
ip ath
ii
Dt : 13/5/2022
*imp
ii
(a)addBatch()
ath
(b)executeBatch()
(c)clearBatch()
ip
(a)addBatch():
Ma
=>This addBatch() method is used to add query to the batch.
Method Signature:
sh
public abstract void addBatch([Link])
throws [Link];
ate
(b)executeBatch():
nk
Method Signature:
(c)clearBatch():
Method Signature:
-----------------------------------------------------
ii
package test;
ath
import [Link].*;
public class DBCon13 {
public static void main(String[] args) {
try {
Connection con = [Link]
ip
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
Statement stm = [Link](); Ma
[Link]
("insert into Product45 values('B123','ER',123,12)");
[Link]
("insert into Bank45
values(456,'Alex',234,'savings')");
sh
[Link]
("insert into CustDetails45
values(456,'SRN','a@..',7878)");
ate
[Link]("Data updated...");
}//end of loop
[Link]();
[Link]();
Ve
}catch(Exception e) {[Link]();}
}
}
Note:
[Link]
package test;
import [Link].*;
public class DBCon14 {
public static void main(String[] args) {
ii
try {
ath
Connection con = [Link]
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
PreparedStatement ps = [Link]
("insert into Product45 values(?,?,?,?)");
ip
[Link](1,"C111");
[Link](2,"TRY"); Ma
[Link](3,234);
[Link](4,12);
[Link]();
[Link](1,"C222");
[Link](2,"Catch");
sh
[Link](3,244);
[Link](4,11);
[Link]();
ate
[Link]("Data Updated...");
}
[Link]();
[Link]();
Ve
}catch(Exception e) {[Link]();}
}
}
Note:
faq:
DataBase only once and executes all the queries from the batch
ii
HighPerformance of an application.
ath
==========================================================
faq:
ip
wt is the diff b/w
(i)Batch Processing
(ii)Procedures
Ma
=>using Batch Processing we can execute only Non-Select queries
sh
on DataBase product,which means it is Batch Update processing.
===========================================================
*imp
nk
Bottom-of-table-data.
Ex:
ii
ath
*imp
ip
=>In Scrollable ResultSet object the cursor can be moved in two
Ma
directions,which means down the table data and upward the table data.
PreparedStatement ps = [Link]("query-S",type,mode);
nk
Type:
Mode:
Note:
'type' specifies the direction of the cursor and 'mode' specifies the
ii
ath
The following are some Methods used to control cursor on Scrollable
ip
ResultSet object:
Ma
afterLast() =>Moves the cursor after the Last row
sh
beforeFirst() =>Moves the cursor before the First row
ate
---------------------------------------------------------
Dt : 16/5/2022
ii
ath
Program : [Link]
package test;
import [Link].*;;
ip
public class DBCon15 {
public static void main(String[] args) { Ma
try {
Connection con = [Link]
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
Statement stm = [Link]
(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
sh
ResultSet rs = [Link]("select * from
Product45");
[Link]("====Display Product in
ate
reverse====");
[Link]();//Cursor pointing after last row
while([Link]()) {
[Link]([Link](1)+"\t"+[Link](2)+
nk
"\t"+[Link](3)+"\t"+[Link](4));
}//end of loop
[Link]();;
Ve
}catch(Exception e) {[Link]();}
}
}
o/p:
A545 ER 123.0 12
ii
B123 ER 123.0 12
ath
-------------------------------------------------------
ip
package test;
import [Link].*;
public class DBCon16 {
public static void main(String[] args) {
try {
Ma
Connection con = [Link]
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
PreparedStatement ps = [Link]
sh
("select * from Product45",
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ate
ResultSet rs = [Link]();
[Link]("====Display Product in
reverse====");
[Link]();//Cursor pointing after last row
while([Link]()) {
nk
[Link]([Link](1)+"\t"+[Link](2)+
"\t"+[Link](3)+"\t"+[Link](4));
Ve
}//end of loop
[Link]("====Display Last row====");
[Link]();//Cursor pointing to last row
[Link]([Link](1)+"\t"+[Link](2)+
"\t"+[Link](3)+"\t"+[Link](4));
[Link]("====Display First row====");
[Link]();//Cursor pointing to first row
[Link]([Link](1)+"\t"+[Link](2)+
"\t"+[Link](3)+"\t"+[Link](4));
[Link]("====Display row number 4====");
[Link](4);//Cursor pointing to 4th row
[Link]([Link](1)+"\t"+[Link](2)+
"\t"+[Link](3)+"\t"+[Link](4));
[Link]("====Display relative(+1)====");
[Link](+1);//Cursor moved forward by one row
[Link]([Link](1)+"\t"+[Link](2)+
"\t"+[Link](3)+"\t"+[Link](4));
ii
[Link]();
}catch(Exception e) {[Link]();}
ath
}
}
ip
o/p:
A545 ER 123.0 12
ate
B123 ER 123.0 12
B123 ER 123.0 12
====Display row number 4====
====Display relative(+1)====
=============================================================
*imp
ii
define 'RowSet'?
ath
=>RowSet object will encapsulate the rows generated from ResultSets
ip
=>RowSet is an interface from [Link] package and which is
(a)JDBCRowSet
sh
(b)CachedRowSet
=>WebRowSet
ate
(i)FilteredRowSet
(ii)JoinRowSet
nk
Hierarchy of RowSet:
Ve
-----------------------------------------------------
faq:
(i)JdbcRowSet
(ii)CachedRowSet
(i)JdbcRowSet:
active.
(ii)CachedRowSet:
ii
=>cachedRowSet will hold ResultSet,but connection to DataBase is
ath
Dis-Connected automatically.
--------------------------------------------------------------
ip
Note:
Ma
=>WebRowSet is used to transfer the data from one layer to another
=========================================================
ate
*imp
define RowSetFactory?
nk
RowSet:
(a)createJdbcRowSet()
(b)createCachedRowSet()
(c)createWebRowSet()
(d)createFilteredRowSet()
(e)createJoinRowSet()
(a)createJdbcRowSet():
'JdbcRowSet'.
Method Signature:
ii
public abstract [Link] createJdbcRowSet()
ath
throws [Link];
ip
(b)createCachedRowSet():
Ma
=>This method is used to create the implementation object of
'CachedRowSet'.
Method Signature:
sh
public abstract [Link] createCachedRowSet()
throws [Link];
ate
(c)createWebRowSet():
nk
'WebRowSet'.
Ve
Method Signature:
throws [Link];
(d)createFilteredRowSet():
=>This method is used to create the implementation object of
'FilteredRowSet'.
Method Signature:
throws [Link];
ii
(e)createJoinRowSet():
ath
=>This method is used to create the implementation object of 'JoinRowSet'.
Method Signature:
ip
public abstract [Link] createJoinRowSet()
throws [Link];
Ma
Note:
sh
=>we use the following methods from '[Link]'
interface.
nk
throws [Link];
Ve
([Link], [Link])
throws [Link];
===================================================================
Dt : 17/5/2022 (JDBC APP_17)
Ex_Program : [Link]
package test;
import [Link].*;
import [Link].*;
ii
public static void main(String[] args) {
ath
try {
ip
[Link]("[Link]");
Ma
RowSetFactory rsf = [Link]();
[Link]("===Choice====");
sh
[Link]("[Link]\[Link]");
switch(choice)
nk
case 1:
Ve
[Link]("jdbc:oracle:thin:@localhost:1521:xe");
[Link]("system");
[Link]("manager");
while([Link]()) {
[Link]([Link](1)+"\t"+
[Link](2)+"\t"+[Link](3)+"\t"+
[Link](4));
}//end of loop
ii
break;
ath
case 2:
ip
[Link]("jdbc:oracle:thin:@localhost:1521:xe");
[Link]("system");
[Link]("manager");
Ma
[Link]("select * from Bank45");
sh
[Link]();
while([Link]()) {
ate
[Link]([Link](1)+"\t"+
[Link](2)+"\t"+[Link](3)+"\t"+
nk
[Link](4));
}//end of loop
Ve
break;
default:
[Link]("Invalid Choice...");
}//end of switch;
[Link]();
}catch(Exception e) {[Link]();}
o/p:
===Choice====
[Link]
ii
[Link]
ath
Enter the Choice:
ip
6123456 Raj 9000.0 savings
313131
56565 Alex
Ram 3500.0 Savings
234.0 savings
Ma
456 Alex 234.0 savings
sh
=============================================================
[Link] Objects
nk
[Link] Objects
[Link] objects
Ve
[Link]<E> objects
[Link]<K,V> objects
[Link]<E> object
[Link] Object
[Link] Object
[Link] Object
ii
[Link] Object
ath
(i)JdbcRowSet Object
(ii)CachedRowSet Object
ip
=>WebRowSet Object
(i)FiltertedRowSet Object
(ii)JoinRowSet Object
Ma
[Link] Objects
sh
(i)DatabaseMetaData object
(ii)ParameterMetaData Object
ate
(iii)ResultSetMetaData Object
(iv)RowSetMetaData Object
nk
Diagram:
Ve
ii
ath
===================================================================
ip
define Metadata in JDBC?
is known as Metadata.
Ma
=>According to Object Oriented proggramming,Metadata means one object
sh
holding information about another object.
[Link]
[Link]
nk
[Link]
[Link]
Ve
[Link]:
syntax:
DatabaseMetaData dmd = [Link]();
[Link]:
syntax:
ii
ParameterMetaData pmd = [Link]();
ath
[Link] :
ip
=>ResultSetMetaData is an interface from [Link] package and
Ma
which is used to hold the information about ResultSet Object.
syntax:
[Link]:
ate
syntax:
Ve
Ex:
package test;
import [Link].*;
import [Link].*;
import [Link].*;
try {
[Link]("[Link]");
ii
Connection con = [Link]
ath
("jdbc:oracle:thin:@localhost:1521:XE","system","manager");
ip
[Link]("DriverVersion:"+[Link]());
Ma
PreparedStatement ps = [Link]
[Link](1,"");
sh
ParameterMetaData pmd = [Link]();
[Link]("Count:"+[Link]());
ate
ResultSet rs = [Link]();
[Link]("Column count:"+[Link]());
Ve
[Link]("jdbc:oracle:thin:@localhost:1521:XE");
[Link]("system");
[Link]("manager");
[Link]([Link]());
[Link]();
[Link]();
}catch(Exception e) {[Link]([Link]());}
ii
}
ath
}
============================================================
ip
faq:
define Stream?
Ma
=>The Continuous flow of data is known as Stream.
sh
Types of Streams:
[Link] Stream
nk
Stream.
=>Character Stream is preferable for Text data and not preferable for
----------------------------------------------------------
faq:
ii
wt is the diff b/w
ath
(i)input stream
(ii)output stream
ip
(i)input stream:
Ma
=>The stream into JavaProgram is known as input stream.
Ex:
sh
JavaProgram reading stream from file
(ii)output stream:
ate
Ex:
nk
=====================================================================
Ve
Note:
[Link]
[Link]
[Link]:
=>BLOB stands for 'Binary Large OBjects' and which is used to store binary
[Link]:
=>CLOB stands for 'Character Large OBjects' and which is used to store
ii
Character Stream data.(Text data)
ath
=======================================================================
*imp
ip
Servlet Programming:(Unit-2)
Diagram:
Ve
ii
ip ath
Ma
=========================================================
sh
ate
nk
Ve
Dt : 18/5/2022
Types of Applications:
(a)StandAlone Applications
(b)Web Applications
(c)Enterprise Applications
ii
(d)Mobile Applications
ath
(a)StandAlone Applications:
ip
=>The applications which are installed in one computer
Ma
and performs actions in the same computer are known as
StandAlone Applications.
Note:
ate
No HTML input
nk
No Server Environment
No DataBase Storage
Ve
(i)CUI Applications
(ii)GUI Applications
(i)CUI Applications:
ii
(ii)GUI Applications:
ath
=>The applications in which the user interacts through
ip
(GUI - Graphical User Interface)
Note:
Ma
=>we use AWT(Abstract Window Toolkit) and Swings to design
sh
GUI components
--------------------------------------------------
ate
(b)Web Applications:
Note:
Application Servers.
------------------------------------------------------
(c)Enterprise Applications:
ii
-------------------------------------------------------
ath
(d)Mobile Applications:
ip
are known as Mobile Applications.
==========================================================
faq:
Ma
define Server?
sh
=>Server means service provider,which means accepting the
define Client?
nk
Client.
Ve
imp
Types of Servers:
(i)WebServers
(ii)Application Servers
(i)WebServer:
html pages.
ii
=>Web server consumes less resources like CPU, Memory etc. as
ath
compared to application server.
ip
applications.
enterprise applications.
------------------------------------------------------------------
*imp
ii
ath
webserver - Tomcat 9.x
ip
vendor - Apache org
default port no
download
- 8080
- [Link](Open source)
Ma
sh
Note:
(i)Servlet container
(ii)JSP Container
nk
ii
User Name : Venkatesh
ath
Password : nit
(click next)
ip
step-3 : Start the Tomcat Server
Ma
=>To start Tomcat server click on 'startup' or 'Tomcat9w'
sh
from 'bin' of Tomcat
C:\Tomcat 9.0\bin
ate
nk
following URL:
Ve
[Link]
C:\Tomcat 9.0\bin
===========================================================
Dt : 19/5/2022
*imp
Servlet API:
ii
=>'[Link]' package is known as Servlet API and which
ath
provide classes and interfaces used in Servlet application
development.
ip
=>'[Link]' interface is the root of Servlet API.
-------------------------------------------------------
Note:
(a)GenericServlet
(b)HttpServlet
(a)GenericServlet:
ii
the following Life-Cycle methods are available
ath
(i)init()
(ii)service()
ip
(iii)destroy()
Ma
=>These methods are automatically executed in the same order.
(i)init()
(ii)service()/doPost()/doGet()
nk
(iii)destroy()
==================================================
*imp
click finish
ii
Add External Jars'->Browse and select '[Link]' file
ath
from 'lib' of Tomcat->open-Apply->Apply and Close.
ip
step-4 : Add Tomcat Server to IDE environment
Ma
Click Servers->click 'click this link to create new server'->
[Link]
<!DOCTYPE html>
Ve
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="dis" method="post">
UserName:<input type="text" name="uname"><br>
MailId:<input type="text" name="mid"><br>
<input type="submit" value="Display">
</form>
</body>
</html>
[Link]
package test;
import [Link].*;
import [Link].*;
import [Link].*;
ii
ath
@SuppressWarnings("serial")
@WebServlet("/dis")
ip
public void init()throws ServletException{
Ma
//NoCode
IOException{
PrintWriter pw = [Link]();
Ve
[Link]("text/html");
[Link]("====UserDetails===");
[Link]("<br>UserName:"+uName);
[Link]("<br>MailId:"+mId);
[Link]
ii
</welcome-file-list>
ath
</web-app>
ip
select the server and click finish. Ma
=====================================================
sh
ate
nk
Ve
Dt:21/5/2022
Assignment-1:(Solution)
[Link]
<!DOCTYPE html>
<html>
ii
<head>
ath
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="dis" method="post">
ip
ProductCode:<input type="text" name="pcode"><br>
ProductName:<input type="text" name="pname"><br>
Ma
ProductPrice:<input type="text" name="pprice"><br>
ProductQty:<input type="text" name="pqty"><br>
<input type="submit" value="Display">
</form>
</body>
</html>
sh
[Link]
ate
package test;
import [Link].*;
nk
import [Link].*;
import [Link].*;
Ve
@SuppressWarnings("serial")
@WebServlet("/dis")
//NoCode
}
public void service(ServletRequest req,ServletResponse res)
throws ServletException,IOException{
String pC = [Link]("pcode");
String pN = [Link]("pname");
float pP = [Link]([Link]("pprice"));
int pQ = [Link]([Link]("pqty"));
ii
PrintWriter pw = [Link]();
ath
[Link]("text/html");
[Link]("ProdCode:"+pC);
ip
[Link]("<br>ProdName:"+pN);
[Link]("<br>ProdPrice:"+pP);
[Link]("<br>ProdQty:"+pQ);
Ma
}
sh
public void destroy() {
//NoCode
ate
}
nk
[Link]
<web-app>
<welcome-file-list>
<welcome-file>[Link]</welcome-file>
</welcome-file-list>
</web-app>
===============================================================
Note:
syntax:
RequestDispatcher rd = [Link]("url-pattern/HTML/JSP");
[Link](req,res);
ii
[Link](req,res);
ath
Ex:
ip
[Link]
<!DOCTYPE html>
<html>
<head>
Ma
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
sh
<body>
<form action="choice" method="post">
Enter the Value1:<input type="text" name="v1"><br>
ate
</html>
[Link]
Ve
package test;
import [Link].*;
import [Link].*;
import [Link].*;
@SuppressWarnings("serial")
@WebServlet("/choice")
//NoCode
ii
throws ServletException,IOException{
ath
String s1 = [Link]("s1");
if([Link]("Add")) {
ip
RequestDispatcher rd=[Link]("ad");
}else {
[Link](req, res);
Ma
RequestDispatcher rd=[Link]("sb");
sh
[Link](req, res);
}
ate
//NoCode
}
Ve
[Link]
package test;
import [Link].*;
import [Link].*;
import [Link].*;
@SuppressWarnings("serial")
@WebServlet("/ad")
//NoCode
ii
}
ath
public void service(ServletRequest req,ServletResponse res)
throws ServletException,IOException{
ip
int v1 = [Link]([Link]("v1"));
Ma
int v2 = [Link]([Link]("v2"));
int v3 = v1+v2;
PrintWriter pw = [Link]();
sh
[Link]("text/html");
[Link]("Sum:"+v3+"<br>");
ate
RequestDispatcher rd = [Link]("[Link]");
[Link](req, res);
nk
//NoCode
[Link]
package test;
import [Link].*;
import [Link].*;
import [Link].*;
@SuppressWarnings("serial")
@WebServlet("/sb")
ii
public void init()throws ServletException{
ath
//NoCode
ip
public void service(ServletRequest req,ServletResponse res)
throws ServletException,IOException{
Ma
int v1 = [Link]([Link]("v1"));
int v2 = [Link]([Link]("v2"));
sh
int v3 = v1-v2;
PrintWriter pw = [Link]();
ate
[Link]("text/html");
[Link]("Sub:"+v3+"<br>");
nk
RequestDispatcher rd = [Link]("[Link]");
[Link](req, res);
Ve
//NoCode
}
[Link]
Diagram:
ii
ip ath
Ma
sh
-----------------------------------------------------------------
Assignment-1:
ate
=>MultiplicationServlet
nk
=>DivisionServlet
=>ModuloDivisionServlet
Ve
-------------------------------------------------------------
Assignment-2:
ip
Ma
sh
ate
nk
Ve
Dt : 23/5/2022
Assignment-2:(Solution)
[Link]
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
ii
<title>Insert title here</title>
ath
</head>
<body>
<form action="choice" method="post">
<input type="submit" value="Book" name="s1">
<input type="submit" value="Product" name="s1">
ip
</form> Ma
</body>
</html>
[Link]
<!DOCTYPE html>
sh
<html>
<head>
<meta charset="ISO-8859-1">
ate
[Link]
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="product" method="post">
ProdCode:<input type="text" name="pcode"><br>
ProdName:<input type="text" name="pname"><br>
ProdPrice:<input type="text" name="pprice"><br>
ProdQty:<input type="text" name="pqty"><br>
<input type="submit" value="DisplayProductDetails">
</form>
ii
</body>
</html>
ath
[Link]
package test;
ip
import [Link].*;
import [Link].*;
import [Link].*;
Ma
@SuppressWarnings("serial")
sh
@WebServlet("/choice")
//NoCode
nk
throws ServletException,IOException{
String s1 = [Link]("s1");
if([Link]("Book")) {
RequestDispatcher rd = [Link]("[Link]");
[Link](req, res);
}else {
RequestDispatcher rd = [Link]("[Link]");
[Link](req, res);
ii
//NoCode
ath
}
ip
[Link]
package test;
import [Link].*;
Ma
import [Link].*;
sh
import [Link].*;
@SuppressWarnings("serial")
ate
@WebServlet("/book")
//NoCode
Ve
throws ServletException,IOException{
PrintWriter pw = [Link]();
[Link]("text/html");
[Link]("====BookDetails====");
[Link]("<br>BookCode:"+[Link]("bcode"));
[Link]("<br>BookName:"+[Link]("bname"));
[Link]("<br>BookAuthor:"+[Link]("bauthor"));
[Link]("<br>BookPrice:"+[Link]("bprice"));
[Link]("<br>BookQty:"+[Link]("bqty"));
ii
[Link]("<br>");
ath
RequestDispatcher rd=[Link]("[Link]");
[Link](req, res);
ip
}
//NoCode
Ma
}
sh
}
[Link]
ate
package test;
import [Link].*;
nk
import [Link].*;
import [Link].*;
Ve
@SuppressWarnings("serial")
@WebServlet("/product")
//NoCode
}
throws ServletException,IOException{
PrintWriter pw = [Link]();
[Link]("text/html");
[Link]("====ProductDetails=====");
ii
[Link]("<br>ProdCode:"+[Link]("pcode"));
ath
[Link]("<br>ProdName:"+[Link]("pname"));
[Link]("<br>ProdPrice:"+[Link]("pprice"));
ip
[Link]("<br>ProdQty:"+[Link]("pqty"));
[Link]("<br>");
Ma
RequestDispatcher rd = [Link]("[Link]");
[Link](req, res);
sh
}
//NoCode
}
nk
[Link]
Ve
=====================================================================
*imp
define Java Bean Class?
=>The classes which are constructed with the following rules are known as
ii
Rule-3 : The class must be declared with 0-argument constructor or 0-parameter
ath
Constructor.
Rule-4 : The class must be declared with 'Setter' and 'Getter' methods.
ip
define Setter methods?
Ma
=>The methods which are used to load the data to object are known as 'Setter'
methods.
sh
=>The methods which are used to get the data from the object are known as
Getter methods.
nk
=>Every Variable in Class must have its own Setter method and Getter method.
Note:
=>These Java Bean Classes will generate bean objects and these bean objects
will hold data going on to DataBase or bean Objects will hold data coming from
DataBase.
-----------------------------------------------------------------
(i)Serializable objects
(ii)NonSerializable Objects
ii
(i)Serializable objects:
ath
=>The objects which support Serialization process are known as Serializable
ip
=>These Serializable objects can travel on N/W.
Ma
=>To generate Serializable objects the classes must be implemented from
[Link] interface.
sh
(ii)NonSerializable Objects:
=>The Objects which will not support Serialization process are known as
ate
NonSerializable objects.
Ex:
nk
-----------------------------------------------------------------
Ve
*imp
==============================================================
ii
ip ath
Ma
sh
ate
nk
Ve
Dt : 24/5/2022
*imp
ii
(i)setAttribute()
ath
(ii)getAttribute()
(iii)removeAttribute()
ip
(iv)getAttributeNames()
(i)setAttribute():
Ma
=>setAttribute() method is used to add 'attribute' to the objects.
sh
Method Signature:
(ii)getAttribute():
nk
=>This getAttribute() method is used to get the attribute from the Objects.
Method Signature:
Ve
(iii)removeAttribute():
Method Signature:
public abstract void removeAttribute([Link]);
(iv)getAttributeNames():
the objects.
Method Signature:
ii
------------------------------------------------
ath
Scope of 'attribute':
ip
of WebApplication.
Ma
=>'attribute' in ServletRequest object can be accessed by Second Servlet
==========================================================================
faq:
define DAO?
=>DAO stands for 'Data Access Object' and which is separate layer in MVC(Model
Diagram:
ii
ip ath
Note:
Ma
=>In the process of establishing communiation b/w Servlet Program and DataBase
ServletApplication : ProductApp
[Link]
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
ii
<title>Insert title here</title>
ath
</head>
<body>
<a href="[Link]">AddProduct</a>
<a href="view">ViewProducts</a>
</body>
ip
</html>
[Link]
<!DOCTYPE html>
Ma
<html>
<head>
<meta charset="ISO-8859-1">
sh
<title>Insert title here</title>
</head>
<body>
ate
</html>
[Link]
package test;
import [Link].*;
@SuppressWarnings("serial")
public class ProductBean implements Serializable{
private String code,name;
private float price;
private int qty;
public ProductBean() {}
public String getCode() {
return code;
}
public void setCode(String code) {
[Link] = code;
}
public String getName() {
return name;
}
public void setName(String name) {
ii
[Link] = name;
}
ath
public float getPrice() {
return price;
}
public void setPrice(float price) {
[Link] = price;
ip
}
public int getQty() { Ma
return qty;
}
public void setQty(int qty) {
[Link] = qty;
}
sh
}
ate
[Link]
package test;
nk
import [Link].*;
import [Link].*;
Ve
import [Link].*;
@SuppressWarnings("serial")
@WebServlet("/add")
throws ServletException,IOException{
[Link]([Link]("pcode"));
ii
[Link]([Link]("pname"));
ath
[Link]([Link]([Link]("pprice")));
[Link]([Link]([Link]("pqty")));
ip
PrintWriter pw = [Link]();
[Link]("text/html");
Ma
sh
int k = new InsertDAO().insert(pb);
if(k>0) {
ate
RequestDispatcher rd=
nk
[Link]("[Link]");
[Link](req, res);
Ve
//NoCode
}
}
[Link]
package test;
import [Link].*;
public class DBConnection {
private static Connection con=null;//reference variable
private DBConnection() {}
static
{
try {
ii
[Link]("[Link]");
ath
con = [Link]
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
}catch(Exception e) {[Link]();}
}
ip
public static Connection getCon()
{ Ma
return con;
}
}
[Link]
sh
package test;
import [Link].*;
ate
try {
Connection con = [Link]();
//Accessing the Connection
PreparedStatement ps = [Link]
Ve
package test;
import [Link].*;
import [Link].*;
ii
public ArrayList<ProductBean> al = new ArrayList<ProductBean>();
ath
public ArrayList<ProductBean> retrieve()
ip
try {
Ma
Connection con = [Link]();
PreparedStatement ps = [Link]
sh
("select * from Product45");
ResultSet rs = [Link]();
ate
while([Link]())
{
nk
[Link]([Link](1));
Ve
[Link]([Link](2));
[Link]([Link](3));
[Link]([Link](4));
}//end of loop
}catch(Exception e) {[Link]();}
return al;
[Link]
package test;
ii
import [Link].*;
ath
import [Link].*;
import [Link].*;
ip
import [Link].*;
@SuppressWarnings("serial")
@WebServlet("/view")
Ma
public class ViewProductsServlet extends GenericServlet{
sh
public void init()throws ServletException{
//NoCode
ate
throws ServletException,IOException{
PrintWriter pw = [Link]();
[Link]("text/html");
if([Link]()==0) {
}else {
Iterator<ProductBean> it = [Link]();
while([Link]())
ProductBean pb = (ProductBean)[Link]();
[Link]([Link]()+"  "+
[Link]()+"  "+[Link]()+
ii
"  "+[Link]()+"<br>");
ath
}//end of loop
}//end of else
ip
RequestDispatcher rd = [Link]("[Link]");
}
[Link](req, res);
Ma
public void destroy() {
sh
//NoCode
}
ate
[Link]
nk
<welcome-file>[Link]</welcome-file>
</welcome-file-list>
</web-app>
Diagram:
ii
ath
===============================================================
ip
Ma
sh
ate
nk
Ve
Dt:26/5/2022
define Iterator<E>?
(a)hasNext()
ii
(b)next()
ath
(c)remove()
(d)forEachRemaining()
ip
(a)hasNext():
Ma
=>hasNext() method will check the element is available or not,and generate
boolean result.
sh
Method Signature:
(b)next():
nk
=>This next() method is used to take the element from Collection<E> object.
Method Signature:
Ve
(c)remove():
Method Signature:
public default void remove();
(d)forEachRemaining():
Method Signature:
ii
public default void forEachRemaining([Link]<? super E>);
ip ath
define iterator() method?
Ma
=>iterator() method is used to create the implementation object of Iterator<E>
interface and the object will hold the reference of Collection<E> object,in this
process the iterator() method also generate cursor pointing before the first
sh
element of Collection<E> object.
ate
syntax:
Iterator<ProductBean> it = [Link]();
nk
=======================================================================
Assignment:
Ve
=>AddBook
=>ViewBooks
=>EditBookDetails(based on BookCode)
=>DeleteBook(based on BookCode)
==========================================================================
faq:
define request?
=>The query generated from user or client through WebBrowser is known as request.
Diagram:
ii
ath
Types of requests:
ip
=>Requests are categorized into two types:
[Link] request
[Link] request
Ma
sh
[Link] request :
=>The request generated to send the data to Server is known as POST request.
ate
=>Through POST request we can send all types of data like Text,Audio,Video,
=>The data which is sent through POST request is secured because the data is
Ve
...
</form>
=>we use doPost() method from HttpServlet to accept POST request.
Method Signature:
[Link])throws [Link],
[Link];
ii
ath
[Link] request"
=>The request generated to get the data from the Server is known as GET request.
ip
=>Through GET request we can send only text data.
Ma
=>Through GET request we can send only limited data,which means up to 4kb or 8kb.
=>The data which is sent through GET request is not secured,because the data is
...
</form>
Ve
<form action="url">
...
</form>
Method Signature:
[Link])throws [Link],
[Link];
ii
=============================================================
ip ath
Ma
sh
ate
nk
Ve
Dt : 27/5/2022
*imp
define Session?
ii
ath
define Session Tracking process?
=>The process of tracking the 'user state' from login to logout is known as
ip
Session Tracking process.
Ma
=>We use the following four techniques to perform Session Tracking process:
(a)Cookie
(b)HttpSession
sh
(c)URL re-write
(a)Cookie:
nk
cookie.
Ve
(i)Persistent Cookies
(ii)Non-Persistent Cookies
(i)Persistent Cookies:
=>The Cookies which are available in WebBrowser until user logs out are
(ii)Non-Persistent Cookies:
=>The Cookies which are destroyed automatically when the WebBrowser is closed
ii
are known as Non-Persistent Cookies.
ath
---------------------------------------------------------------------
ip
process.
Hierarchy of Cookie:
Ma
sh
ate
nk
-----------------------------------------------------------
ii
=>we use the following process to construct Cookie Session Tracking:
ath
step-1 : When the Login process is Successfull then construct the Cookie.
ip
syntax:
[Link](ck);
ate
systax:
syntax:
[Link](0);
-----------------------------------------------------------------------
Ex:
ii
ath
[Link]
package test;
ip
import [Link].*;
public class DBConnection {
private static Connection con=null;//reference variable
Ma
private DBConnection() {}
static
{
try {
[Link]("[Link]");
sh
con = [Link]
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
ate
}catch(Exception e) {[Link]();}
}
public static Connection getCon()
{
return con;
nk
}
}
Ve
[Link]
package test;
import [Link].*;
@SuppressWarnings("serial")
public class UserBean implements Serializable{
private String uName,pWord,fName,lName,addr,mId;
private long phNo;
public UserBean() {}
public String getuName() {
return uName;
}
public void setuName(String uName) {
[Link] = uName;
}
public String getpWord() {
return pWord;
}
public void setpWord(String pWord) {
[Link] = pWord;
}
ii
public String getfName() {
return fName;
ath
}
public void setfName(String fName) {
[Link] = fName;
}
public String getlName() {
ip
return lName;
} Ma
public void setlName(String lName) {
[Link] = lName;
}
public String getAddr() {
return addr;
}
sh
public void setAddr(String addr) {
[Link] = addr;
}
ate
[Link] = mId;
}
public long getPhNo() {
return phNo;
Ve
}
public void setPhNo(long phNo) {
[Link] = phNo;
}
[Link]
package test;
import [Link].*;
@SuppressWarnings("serial")
public class UserBean implements Serializable{
private String uName,pWord,fName,lName,addr,mId;
private long phNo;
public UserBean() {}
public String getuName() {
return uName;
}
public void setuName(String uName) {
ii
[Link] = uName;
}
ath
public String getpWord() {
return pWord;
}
public void setpWord(String pWord) {
[Link] = pWord;
ip
}
public String getfName() { Ma
return fName;
}
public void setfName(String fName) {
[Link] = fName;
}
public String getlName() {
sh
return lName;
}
public void setlName(String lName) {
ate
[Link] = lName;
}
public String getAddr() {
return addr;
nk
}
public void setAddr(String addr) {
[Link] = addr;
}
Ve
[Link]
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
ii
<title>Insert title here</title>
ath
</head>
<body>
<form action="reg" method="post">
UserName:<input type="text" name="uname"><br>
PassWord:<input type="text" name="pword"><br>
ip
FirstName:<input type="text" name="fname"><br>
LastName:<input type="text" name="lname"><br>
Ma
Address:<input type="text" name="addr"><br>
MailId:<input type="text" name="mid"><br>
PhoneNo:<input type="text" name="phno"><br>
<input type="submit" value="Register">
</form>
</body>
sh
</html>
[Link]
ate
package test;
import [Link].*;
public class RegisterDAO {
public int k=0;
nk
[Link]
package test;
ii
import [Link].*;
ath
import [Link].*;
import [Link].*;
import [Link].*;
ip
@SuppressWarnings("serial") Ma
@WebServlet("/reg")
[Link]([Link]("uname"));
nk
[Link]([Link]("pword"));
[Link]([Link]("fname"));
Ve
[Link]([Link]("lname"));
[Link]([Link]("addr"));
[Link]([Link]("mid"));
[Link]([Link]([Link]("phno")));
PrintWriter pw = [Link]();
[Link]("text/html");
if(k>0) {
RequestDispatcher rd=
[Link]("[Link]");
[Link](req, res);
ii
}
ath
}
ip
[Link]
[Link]
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<a href="view">ViewProducts</a>
ii
<a href="logout">Logout</a>
ath
</body>
</html>
[Link]
ip
package test;
import [Link].*;
import [Link].*;
Ma
public class LoginDAO {
sh
public UserBean ub=null;
try {
PreparedStatement ps = [Link]
[Link](1,[Link]("uname"));
[Link](2,[Link]("pword"));
ResultSet rs = [Link]();
if([Link]()) {
[Link]([Link](2));
[Link]([Link](3));
[Link]([Link](4));
[Link]([Link](5));
[Link]([Link](6));
ii
[Link]([Link](7));
ath
}
}catch(Exception e) {[Link]();}
ip
return ub;
}
}
Ma
[Link]
sh
package test;
import [Link].*;
ate
import [Link].*;
import [Link].*;
nk
import [Link].*;
@SuppressWarnings("serial")
Ve
@WebServlet("/log")
[Link]("text/html");
if(ub==null) {
RequestDispatcher rd=
[Link]("[Link]");
ii
[Link](req, res);
ath
}else {
ip
//Creating Cookie
Ma
[Link](ck);//Adding Cookie to response
RequestDispatcher rd =
sh
[Link]("[Link]");
[Link](req, res);
ate
}
nk
[Link]
Ve
package test;
import [Link].*;
@SuppressWarnings("serial")
public class ProductBean implements Serializable{
private String code,name;
private float price;
private int qty;
public ProductBean() {}
public String getCode() {
return code;
}
public void setCode(String code) {
[Link] = code;
}
public String getName() {
return name;
}
public void setName(String name) {
[Link] = name;
}
public float getPrice() {
ii
return price;
}
ath
public void setPrice(float price) {
[Link] = price;
}
public int getQty() {
return qty;
ip
}
public void setQty(int qty) { Ma
[Link] = qty;
}
}
sh
[Link]
package test;
ate
import [Link].*;
import [Link].*;
nk
try {
ResultSet rs = [Link]();
while([Link]())
ii
[Link]([Link](1));
ath
[Link]([Link](2));
[Link]([Link](3));
ip
[Link]([Link](4));
Ma
[Link](pb);//Adding bean to ArrayList
}//end of loop
}catch(Exception e) {[Link]();}
sh
return al;
}
ate
[Link]
nk
package test;
import [Link].*;
Ve
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
@SuppressWarnings("serial")
@WebServlet("/view")
throws ServletException,IOException{
PrintWriter pw = [Link]();
[Link]("text/html");
ii
Cookie c[] = [Link]();//Getting the Cookies
ath
if(c==null) {
[Link]("Session Expired...<br>");
ip
RequestDispatcher rd=
Ma
[Link]("[Link]");
[Link](req, res);
}else {
sh
String fName = c[0].getValue();
[Link]("page of "+fName+"<br>");
ate
RequestDispatcher rd=
[Link]("[Link]");
nk
[Link](req, res);
if([Link]()==0) {
}else {
Iterator<ProductBean> it = [Link]();
while([Link]())
{
ProductBean pb = (ProductBean)[Link]();
[Link]("<br>"+[Link]()+"  "+
[Link]()+"  "+[Link]()+
"  "+[Link]()+"<br>");
}//end of loop
ii
}//end of else
ath
}
ip
}
[Link]
package test;
Ma
import [Link].*;
sh
import [Link].*;
import [Link].*;
ate
import [Link].*;
@SuppressWarnings("serial")
nk
@WebServlet("/logout")
PrintWriter pw = [Link]();
[Link]("text/html");
[Link]("Session Expired....<br>");
}else {
c[0].setMaxAge(0);//Cookie destroyed
ii
RequestDispatcher rd=
ath
[Link]("[Link]");
[Link](req, res);
ip
}
Layout:
Ma
sh
ate
nk
Ve
=================================================================
Assignment:
DB Tables:
UserReg45(uname,pword,fname,lname,addr,mid,phno)
ii
AdminReg45(uname,pword,fname,lname,addr,mid,phno)
ath
BookDetails45(bcode,bname,bauthor,bprice,bqty)
ip
Ma
sh
ate
nk
Ve
Dt : 2/6/2022
Diagram:
ii
ip ath
Ma
=========================================================================
=>Cookies are stored in WebBrowser to track the user,which means Cookies are
sh
browser dependent or Client dependent.
ate
=====================================================================
*imp
Ve
(b)HttpSession:
ii
ath
public abstract void putValue([Link], [Link]);
ip
public abstract [Link][] getValueNames();
Ma
public abstract void removeValue([Link]);
Note:
ii
ip ath
Ma
sh
ate
nk
Ve
Dt : 3/6/2022
Layout:
ii
ip ath
Ma
sh
[Link]
<!DOCTYPE html>
ate
<html>
<head>
<meta charset="ISO-8859-1">
nk
<body>
<form action="log" method="post">
UserName:<input type="text"
name="uname"><br>
PassWord:<input type="password"
name="pword"><br>
<input type="submit" value="Login">
<a href="[Link]">NewUser?</a>
</form>
</body>
</html>
[Link]
<!DOCTYPE html>
<html>
ii
<head>
ath
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
ip
<body>
<a href="view">ViewProfile</a>
Ma
<a href="">EditProfile</a>
<a href="logout">Logout</a>
</body>
sh
</html>
[Link]
ate
package test;
import [Link].*;
nk
con=null;//reference variable
private DBConnection() {}
static
{
try {
[Link]("[Link]
leDriver");
con =
[Link]
ii
("jdbc:oracle:thin:@localhost:1521:xe"
ath
,"system","manager");
}catch(Exception e)
{[Link]();}
ip
} Ma
public static Connection getCon()
{
return con;
}
sh
}
ate
[Link]
package test;
nk
import [Link].*;
import [Link].*;
Ve
try {
[Link](1,[Link]("uname"));
[Link](2,[Link]("pword"));
ResultSet rs = [Link]();
if([Link]()) {
ii
ub = new UserBean();//Bean Object
ath
[Link]([Link](1));
[Link]([Link](2));
[Link]([Link](3));
ip
[Link]([Link](4));
Ma
[Link]([Link](5));
[Link]([Link](6));
[Link]([Link](7));
sh
}
}catch(Exception e) {[Link]();}
ate
return ub;
}
nk
[Link]
Ve
package test;
import [Link].*;
@SuppressWarnings("serial")
public class UserBean implements
Serializable{
private String
uName,pWord,fName,lName,addr,mId;
private long phNo;
public UserBean() {}
public String getuName() {
return uName;
}
ii
public void setuName(String uName) {
ath
[Link] = uName;
}
public String getpWord() {
ip
return pWord; Ma
}
public void setpWord(String pWord) {
[Link] = pWord;
}
sh
public String getfName() {
ate
return fName;
}
public void setfName(String fName) {
nk
[Link] = fName;
}
Ve
ii
return mId;
ath
}
public void setmId(String mId) {
[Link] = mId;
ip
} Ma
public long getPhNo() {
return phNo;
}
public void setPhNo(long phNo) {
sh
[Link] = phNo;
ate
}
nk
[Link]
Ve
package test;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
@SuppressWarnings("serial")
@WebServlet("/log")
PrintWriter pw = [Link]();
ii
[Link]("text/html");
ath
if(ub==null) {
RequestDispatcher rd=
ip
[Link]("[Link]");
Ma
[Link](req, res);
}else {
RequestDispatcher rd =
[Link]("[Link]");
nk
[Link](req, res);
}
Ve
[Link]
package test;
import [Link].*;
ii
ath
import [Link].*;
import [Link].*;
import [Link].*;
ip
@SuppressWarnings("serial")
@WebServlet("/view")
Ma
public class ViewProfileServlet extends HttpServlet{
PrintWriter pw = [Link]();
ate
[Link]("text/html");
HttpSession hs = [Link](false);
nk
if(hs==null) {
Ve
[Link]("Session Expired...<br>");
RequestDispatcher rd =
[Link]("[Link]");
[Link](req, res);
}else {
UserBean ub = (UserBean)[Link]("ubean");
[Link]("Page of "+[Link]()+"<br>");
RequestDispatcher rd=
[Link]("[Link]");
[Link](req, res);
[Link]("<br>"+[Link]()+"  "+
[Link]()+"  "+[Link]()+"  "+
ii
[Link]()+"  "+[Link]());
ath
}
ip
[Link] Ma
package test;
import [Link].*;
import [Link].*;
sh
import [Link].*;
import [Link].*;
ate
@SuppressWarnings("serial")
@WebServlet("/logout")
nk
throws ServletException,IOException{
PrintWriter pw = [Link]();
[Link]("text/html");
HttpSession hs = [Link](false);
if(hs==null) {
[Link]("Session Expired...<br>");
}else {
[Link]();//Session destroyed
RequestDispatcher rd=
ii
[Link]("[Link]");
ath
[Link](req, res);
ip
=========================================================================
Ma
Assignment:
=======================================================================
sh
ate
nk
Ve
Dt:4/6/2022
faq:
(i)getSession()
(ii)getSession(false)
(iii)getSession(true)
ii
ath
(i)getSession():
ip
Session Object is not available.
Ma
=>If available then getSession() method will access the existing session
object.
sh
(ii)getSession(false):
(iii)getSession(true):
=>If available then getSession(true) method will access the existing session
object.
===========================================================================
(c)URL re-write:
=>The process of adding parameter-values to url-pattern is known as URL re-write.
=>using URL re-write process we pass information from one Servlet program to
syntax:
url-pattern?para=value¶=value&...
ii
ath
Note:
ip
=>"&" symbol is the separator b/w parameters.
Ex Application:
Ma
[Link]
sh
package test;
import [Link].*;
public class DBConnection {
ate
[Link]("[Link]");
con = [Link]
Ve
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
}catch(Exception e) {[Link]();}
}
public static Connection getCon()
{
return con;
}
}
[Link]
package test;
import [Link].*;
import [Link].*;
ii
ProductBean retrieve(HttpServletRequest req)
ath
{
try {
ip
Connection con = [Link]();
Ma
//Accessing the Connection
PreparedStatement ps = [Link]
ResultSet rs = [Link]();
ate
while([Link]())
{
nk
pb = new ProductBean();
[Link]([Link](1));
Ve
[Link]([Link](2));
[Link]([Link](3));
[Link]([Link](4));
}//end of loop
}catch(Exception e) {[Link]();}
return pb;
[Link]
package test;
import [Link].*;
@SuppressWarnings("serial")
public class ProductBean implements Serializable{
ii
private String code,name;
ath
private float price;
private int qty;
public ProductBean() {}
public String getCode() {
return code;
ip
}
public void setCode(String code) {
Ma
[Link] = code;
}
public String getName() {
return name;
}
public void setName(String name) {
sh
[Link] = name;
}
public float getPrice() {
ate
return price;
}
public void setPrice(float price) {
[Link] = price;
nk
}
public int getQty() {
return qty;
}
Ve
[Link]
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="first" method="post">
Enter the ProdCode:<input type="text" name="pcode"><br>
<input type="submit" value="RetrieveProduct">
</form>
</body>
ii
</html>
ath
[Link]
package test;
import [Link].*;
ip
import [Link].*; Ma
import [Link].*;
import [Link].*;
@SuppressWarnings("serial")
sh
@WebServlet("/first")
ate
throws ServletException,IOException{
nk
PrintWriter pw = [Link]();
Ve
[Link]("text/html");
if(pb==null) {
[Link]("Invalid ProductCode...<br>");
RequestDispatcher rd=
[Link]("[Link]");
[Link](req, res);
}else {
[Link]("<a href='second?code="+[Link]()
+"&name="+[Link]()
+"&price="+[Link]()
+"&qty="+[Link]()+"'>ViewProductDetails</a>");
ii
}
ath
}
ip
[Link]
package test;
import [Link].*;
Ma
import [Link].*;
sh
import [Link].*;
import [Link].*;
ate
@SuppressWarnings("serial")
@WebServlet("/second")
nk
throws ServletException,IOException{
PrintWriter pw = [Link]();
[Link]("text/html");
[Link]("====ProductDetails====");
[Link]("<br>PCode:"+[Link]("code"));
[Link]("<br>PName:"+[Link]("name"));
[Link]("<br>PPrice:"+[Link]("price"));
[Link]("<br>PQty:"+[Link]("qty"));
[Link]
ii
<?xml version="1.0" encoding="UTF-8"?>
ath
<web-app>
<welcome-file-list>
<welcome-file>[Link]</welcome-file>
</welcome-file-list>
</web-app>
ip
Diagram: Ma
sh
ate
nk
Ve
[Link]
code=A111
&name=Mouse
&price=1200.0
&qty=12
[Link]
ii
q=gmail
ath
&oq=
&aqs=chrome.0.35i39i362l8.1558847477j0j7
ip
&sourceid=chrome
&ie=UTF-8
Ma
=====================================================================
sh
Assignment:
Construct Servlet Application to send Book details from one Servlet program to
ate
=======================================================================
nk
Ve
Dt : 6/6/2022
=>The data which is available in hidden form filds are not visible to the
end user.
ii
=>In Session tracking process we can also take the support hidden form fields
ath
to transfer the information from one Servlet program to another Servlet program.
ip
syntax:
<form action="url-pattern"...>
Ma
<input type="hidden" value="alex" name="n">
...
sh
</form>
ate
Ex_program:
[Link]
nk
package test;
import [Link].*;
public class DBConnection {
Ve
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
}catch(Exception e) {[Link]();}
}
public static Connection getCon()
{
return con;
}
}
[Link]
package test;
ii
import [Link].*;
ath
import [Link].*;
ip
ProductBean retrieve(HttpServletRequest req)
Ma
{
try {
PreparedStatement ps = [Link]
[Link](1,[Link]("pcode"));
ResultSet rs = [Link]();
Ve
while([Link]())
pb = new ProductBean();
[Link]([Link](1));
[Link]([Link](2));
[Link]([Link](3));
[Link]([Link](4));
}//end of loop
}catch(Exception e) {[Link]();}
return pb;
ii
[Link]
ath
package test;
import [Link].*;
@SuppressWarnings("serial")
public class ProductBean implements Serializable{
ip
private String code,name;
private float price; Ma
private int qty;
public ProductBean() {}
public String getCode() {
return code;
}
public void setCode(String code) {
sh
[Link] = code;
}
public String getName() {
ate
return name;
}
public void setName(String name) {
[Link] = name;
}
nk
[Link]
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
ii
<form action="first" method="post">
ath
Enter the ProdCode:<input type="text" name="pcode"><br>
<input type="submit" value="RetrieveProduct">
</form>
</body>
</html>
ip
[Link] Ma
package test;
import [Link].*;
import [Link].*;
sh
import [Link].*;
ate
import [Link].*;
@SuppressWarnings("serial")
nk
@WebServlet("/first")
throws ServletException,IOException{
PrintWriter pw = [Link]();
[Link]("text/html");
if(pb==null) {
[Link]("Invalid ProductCode...<br>");
RequestDispatcher rd=
[Link]("[Link]");
[Link](req, res);
}else {
ii
[Link]
ath
("<input type='hidden' value='"+[Link]()+"' name='code'>");
[Link]
ip
("<input type='hidden' value='"+[Link]()+"' name='name'>");
[Link]
Ma
("<input type='hidden' value='"+[Link]()+"' name='price'>");
[Link]
sh
("<input type='hidden' value='"+[Link]()+"' name='qty'>");
[Link]
ate
[Link]("</form>");
nk
}
Ve
[Link]
package test;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
@SuppressWarnings("serial")
@WebServlet("/second")
ii
throws ServletException,IOException{
ath
PrintWriter pw = [Link]();
[Link]("text/html");
ip
[Link]("====ProductDetails====");
Ma
[Link]("<br>PCode:"+[Link]("code"));
[Link]("<br>PName:"+[Link]("name"));
[Link]("<br>PPrice:"+[Link]("price"));
sh
[Link]("<br>PQty:"+[Link]("qty"));
}
ate
[Link]
nk
<welcome-file>[Link]</welcome-file>
</welcome-file-list>
</web-app>
=======================================================================
Assignment:
Construct Servlet Application to send Book details from one Servlet program to
ii
ip ath
Ma
sh
ate
nk
Ve
Dt : 7/6/2022
*imp
ServletContext:
ii
=>we use getServletContext() method to access the reference of ServletContext
ath
object.
ip
GenericServlet,HttpSession and ServletConfig.
syntax:
Ma
ServletContext sct = [Link]();
sh
ServletContext object.
nk
syntax:
<web-app>
Ve
<context-param>
</context-param>
.
.
</web-app>
ii
Note:
ath
=>Total WebApplication will have only one ServletContext object and the
ip
WebApplication.
Ma
-------------------------------------------------------------------
*imp
ServletConfig:
sh
=>ServletConfig is an interface from [Link] package and which is
object.
nk
object.
syntax:
ServletConfig sc = [Link]();
=>we use <init-param> tag part of <servlet> to initialize parameters to
ServletConfig object.
syntax:
<web-app>
ii
<servlet>
ath
.
<init-param>
ip
<param-name> name </param-name>
Ma
<param-value> value </param-value>
</init-param>
</servlet>
sh
<servlet-mapping>
.
ate
</servlet-mapping>
.
nk
</web-app>
Ve
Ex Application:
[Link]
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="dis" method="post">
Name:<input type="text" name="name"><br>
<input type="submit" value="Display">
</form>
</body>
</html>
[Link]
ii
<context-param>
ath
<param-name>a</param-name>
<param-value>2000</param-value>
</context-param>
<servlet>
ip
<servlet-name>DisplayServlet</servlet-name>
<servlet-class>[Link]</servlet-class>
Ma
<init-param>
<param-name>b</param-name>
<param-value>3000</param-value>
</init-param>
</servlet>
<servlet-mapping>
sh
<servlet-name>DisplayServlet</servlet-name>
<url-pattern>/dis</url-pattern>
</servlet-mapping>
ate
<welcome-file-list>
<welcome-file>[Link]</welcome-file>
</welcome-file-list>
nk
</web-app>
[Link]
Ve
package test;
import [Link].*;
import [Link].*;
import [Link].*;
@SuppressWarnings("serial")
public class DisplayServlet extends HttpServlet{
throws ServletException,IOException{
PrintWriter pw = [Link]();
[Link]("text/html");
[Link]("User : "+[Link]("name"));
ii
[Link]("<br>====ServletContext=====");
ath
ServletContext sct = [Link]();
ip
[Link]("<br>ServerInfo:"+[Link]());
Ma
[Link]("<br>ContextValue:"+[Link]("a"));
[Link]("<br>====ServletConfig====");
ServletConfig sc = [Link]();
sh
//Accessing Config Object
[Link]("<br>ServletName:"+[Link]());
ate
[Link]("<br>ConfigValue:"+[Link]("b"));
}
nk
ip
Ma
sh
ate
nk
Ve
Dt : 8/6/2022
[Link]
[Link]
[Link]/HttpServletRequest
[Link]/HttpServletResponse
ii
[Link]
ath
[Link]
[Link]
ip
[Link] Beans
(i)ServletContext
(ii)ServletConfig
nk
(i)ServletContext:
Ve
(ii)ServletConfig:
=>ServletConfig is instantiated automatically when Servlet program is loaded
=========================================================================
faq:
ii
(i)<contex-param>
ath
(ii)<init-param>
ip
(i)<contex-param>:
Ma
<context-param> tag is used to initialize parameters to ServletContext object.
(ii)<init-param>:
sh
<init-param> tag is the Sub-tag of <servlet> tag and which is used to
============================================================================
faq:
nk
(i)getParameter()
Ve
(ii)getInitParameter()
(i)getParameter():
============================================================================
*imp
ii
=>Filter is a Pre-Processing component before Servlet program.
ath
=>Filter and Servlet programs are executed with same url-pattern.
=>In the process of execution Filter programs will have highest priority in
ip
execution than Servlet programs
Diagram:
Ma
sh
ate
nk
Ve
Advantage of Filters:
=======================================================================
Note:
ii
[Link]
ath
[Link]
[Link]
ip
[Link]:
Ma
=>Filter is an interface from [Link] package and which is implemented
to filter program.
sh
=>The following are the Life-Cycle methods from 'Filter':
ate
throws [Link];
nk
[Link], [Link])
Ve
[Link]:
=>FilterChain is an interface from [Link] package and which is
=>This FilterChain will have the following doFilter() method to link the
ii
[Link]) throws [Link],
ath
[Link];
ip
[Link]:
Ma
=>FilterConfig is an interface from [Link] package and which is
getInitParameterNames();
-------------------------------------------------------------------------
Dt : 9/6/2022
Note:
=>we use the following tags part of [Link] to execute filter program:
<web-app>
ii
<filter>
ath
<filter-name> name </filter-name>
ip
<init-param>
<param-name>name</param-name>
<param-value>value</param-value>
Ma
</init-param>
sh
</filter>
<filter-mapping>
ate
<filter-name>name</filter-name>
<url-pattern>/url-pattern</url-pattern>
nk
</filter-mapping>
</web-app>
Ve
=========================================================================
Ex_Application-1:
[Link]
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="log" method="post">
UserName:<input type="text" name="uname"><br>
PassWord:<input type="password" name="pword"><br>
<input type="submit" value="Login">
<a href="[Link]">NewUser?</a>
</form>
ii
</body>
</html>
ath
[Link]
package test;
import [Link].*;
ip
public class DBConnection {
private static Connection con=null;//reference variable
Ma
private DBConnection() {}
static
{
try {
[Link]("[Link]");
con = [Link]
sh
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
}catch(Exception e) {[Link]();}
ate
}
public static Connection getCon()
{
return con;
nk
}
}
Ve
[Link]
package test;
import [Link].*;
import [Link].*;
try {
PreparedStatement ps = [Link]
ii
[Link](1,[Link]("uname"));
ath
[Link](2,[Link]("pword"));
ResultSet rs = [Link]();
ip
if([Link]()) {
Ma
fName = [Link](3);
}catch(Exception e) {[Link]();}
}
return fName;
sh
}
}
ate
[Link]
package test;
nk
import [Link].*;
import [Link].*;
Ve
import [Link].*;
@WebFilter("/log")
[Link]("text/html");
if(fName==null) {
RequestDispatcher rd =
ii
[Link]("[Link]");
ath
[Link](req, res);
}else {
ip
[Link]("fname", fName);
}
Ma
[Link](req, res);//linking Servlet_program
}
sh
}
[Link]
ate
package test;
import [Link].*;
nk
import [Link].*;
import [Link].*;
Ve
import [Link].*;
@SuppressWarnings("serial")
@WebServlet("/log")
PrintWriter pw = [Link]();
[Link]("text/html");
[Link]("Login Successfull...<br>");
ii
}
ath
}
[Link]
ip
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<welcome-file-list>
<welcome-file>[Link]</welcome-file>
</welcome-file-list>
Ma
</web-app>
Diagram:
sh
ate
nk
Ve
========================================================================
Dt : 11/6/2022
Filter_program-2:
Application to demonstrate FilterConfig.
[Link]
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="dis" method="post">
ii
UserName:<input type="text" name="uname"><br>
ath
<input type="submit" value="Display">
</form>
</body>
</html>
ip
[Link]
</filter>
<filter-mapping>
<filter-name>DisplayFilter</filter-name>
<url-pattern>/dis</url-pattern>
</filter-mapping>
nk
<welcome-file-list>
<welcome-file>[Link]</welcome-file>
</welcome-file-list>
Ve
</web-app>
[Link]
package test;
import [Link].*;
import [Link].*;
public class DisplayFilter implements Filter{
[Link]=fc;
ii
FilterChain chain)throws ServletException,IOException{
ath
PrintWriter pw = [Link]();
[Link]("text/html");
ip
[Link]("UserName:"+[Link]("uname"));
Ma
[Link]("<br>====FilterConfig====");
[Link]("<br>FilterName:"+[Link]());
[Link]("<br>FilterValue:"+[Link]("a"));
sh
}
}
ate
Diagram:
nk
Ve
ii
ip ath
Ma
========================================================================
sh
faq:
ate
(i)ServletConfig
(ii)FilterConfig
nk
Ve
(i)ServletConfig:
(ii)FilterConfig:
=>FilterConfig is instantiated automatically when the Filter program loaded
for execution.
================================================================
Note:
ii
================================================================
ip ath
Ma
sh
ate
nk
Ve
Dt : 14/6/2022
*imp
ii
Note:
ath
=>when event(action) is performed on Servlet object deligated to Listener and
the Listener will execute related method to handle the event,is known as
ip
Event-Delegation-Model.
Diagram:
Ma
sh
ate
nk
Ve
------------------------------------------------------------------
[Link]
[Link]
[Link]
[Link]:
Event_Class : ServletContextEvent
Event_Listener : ServletContextListener
ii
methods :
ath
public void contextInitialized([Link])
ip
[Link]:
Ma
Event_Class : ServletRequestEvent
sh
Event_Listener : ServletRequestListener
methods :
ate
[Link]:
Ve
Event_Class : HttpSessionEvent
Event_Listener : HttpSessionListener
methods :
============================================================================
[Link]
ii
package test;
ath
import [Link].*;
import [Link].*;
ip
@WebListener
Ma
public class ContextListener implements ServletContextListener
}
ate
}
Ve
[Link]
package test;
import [Link].*;
import [Link].*;
@WebListener
public class RequestListener implements ServletRequestListener{
ii
}
ath
}
[Link]
ip
package test;
import [Link].*;
import [Link].*;
Ma
@WebListener
sh
public class SessionListener implements HttpSessionListener,
HttpSessionAttributeListener{
ate
[Link]("Session Created....");
nk
[Link]("Session Destroyed...");
}
public void attributeRemoved(HttpSessionBindingEvent hsbe) {
========================================================================
faq:
ii
Types of Listeners in Servlet Programming"
ath
=>Listeners in Servlet programming are categorized into three types:
ip
[Link] Level Listener
======================================================
structure of [Link] from Servlet Programming:
<web-app>
<context-param></context-param>
<listener>
Listener_Class_name
ii
</listener>
ath
<servlet>
<servlet-name></servlet-name>
ip
<servlet-class></servlet-class>
<init-param></init-param>
</servlet>
Ma
<servlet-mapping>
sh
<servlet-name></servlet-name>
<url-pattern></url-pattern>
ate
</servlet-mapping>
<filter>
nk
<filter-name></filter-name>
<filter-class></filter-class>
Ve
<init-param></init-param>
</filter>
<filter-mapping>
<filter-name></filter-name>
<url-pattern></url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list>
</web-app>
ii
ip ath
Ma
sh
*imp
ate
define Annotation?
nk
annotation.
@ Override
@ SuppressWarnings("unchecked")
@ SuppressWarnings("rawtypes")
ii
ath
=>The following are some important annotations used in Servlet
programming:
ip
(a)@ WebServlet
(b)@ WebFilter
(c)@ WebInitParam
Ma
(d)@ WebListener
sh
(a)@ WebServlet:
ate
(b)@ WebFilter:
Ve
(c)@ WebInitParam:
(d)@ WebListener:
--------------------------------------
ii
Note:
ath
=>When we use annotations in Servlet programming,the Servlet programs
ip
=>All the annotations related to ServletProgramming are available
Dt : 15/6/2022
sh
faq:
Servlet Collaboration.
nk
(i)Using 'RequestDispatcher'
=>forward()
=>include()
=>In this process another Servlet program may be in same WebApp or diff WebAppl.
ii
Method Signature:
ath
public abstract void sendRedirect([Link]) throws [Link];
ip
Ex:
WebApp-1 : TestApp1
Ma
[Link]
sh
<!DOCTYPE html>
<html>
<head>
ate
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="first" method="post">
nk
</form>
</body>
</html>
[Link]
package test;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
@SuppressWarnings("serial")
@WebServlet("/first")
ii
throws ServletException,IOException{
ath
String uName = [Link]("uname");
ip
[Link]("[Link]
}
uName+"&mid="+mId);
Ma
}
sh
[Link]
<web-app>
<welcome-file-list>
<welcome-file>[Link]</welcome-file>
</welcome-file-list>
</web-app>
nk
WebApp-2 : TestApp2
Ve
[Link]
package test;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
@SuppressWarnings("serial")
@WebServlet("/second")
throws ServletException,IOException{
PrintWriter pw = [Link]();
ii
[Link]("text/html");
ath
[Link]("====SecondServlet====");
[Link]("<br>Name:"+[Link]("uname"));
ip
[Link]("<br>MailId:"+[Link]("mid"));
}
Ma
}
sh
[Link]
-----------------------------------------------------------------------
ate
faq:
(i)forward() method
(ii)sendRedirect() method
Ve
servlet program.
=>when we use sendRedirect() method then new requset is generated from the
faq:
[Link] process
ii
[Link] proccess
ath
[Link] process
ip
[Link] process
[Link] process:
Ma
=>The process of identifying the servlet program based on url-pattern and
sh
loading onto WebContatiner is known as Loading prrocess.
Note:
ate
(i)Annotation
nk
(ii)[Link]
Ve
[Link] proccess:
Genericservlet
(a)init()
(b)service()
(c)destroy()
HttpServlet
(a)init()
(b)doPost()/doGet()/service()
ii
(c)destroy()
ath
Filter
(a)init()
ip
(b)doFilter()
faq:
(c)destroy()
Ma
define Life-Cycle methods?
sh
=>The methods which are executed automatically in same order are known as
Life-Cycle methods.
ate
[Link] process:
nk
=>The process of making the programming components ready for execution is known as
Initialization process.
Ve
Note:
=>Through Initialization process we can make Bean objects and DAO objects ready
for execution.
=>The process of taking the request and providing the response is known as
Handling process.
Note:
ii
=>In Multi-User Applications,
ath
=>init() method is executed only once,but doPost()/doGet()/service() methods
ip
[Link] process:
Ma
=>The process of closing or destroying the resources after execution is known
as Destroying process.
sh
=>we use destroy() method to perform destroying process.
=============================================================================
ate
[Link] Object
nk
[Link] Object
[Link] Object
Ve
[Link] Object
[Link] object
[Link] object
[Link] object
[Link] Object
(a)JdbcRowSet
(b)CachedRowSet
=>WebRowSet
(i)FilteredRowSet
ii
(ii)JoinRowset
ath
*
ip
=>Vector<E> Object
Ma
Summary of Objects from Servlet Programming:
sh
[Link] object
[Link] object
ate
[Link]/HttpServletRequest object
[Link]/HttpServletResponse object
nk
[Link] object
[Link] object
Ve
[Link] object
[Link] object
==============================================================================
==
*imp
JSP Programming:(Unit-3)
=>JSP Stands for 'Java Server Page' and which is response from
WebApplication.
ii
=>JSP is tag based programming language and which is more easy when
ath
compared to Servlet programming.
ip
=>JSP programs are combination of both HTML code and Java Code.
[Link] tags
=>Scriptlet tag
sh
=>Expression tag
ate
=>Declarative tag
[Link] tags
nk
=>page
=>include
Ve
=>taglib
[Link] tags
=>jsp:include
=>jsp:forward
=>jsp:param
=>jsp:useBean
=>jsp:setProperty
=>jsp:getProperty
Dt : 16/6/2022
[Link] tags:
ii
=>Scripting tags are used to write JavaCode part of JSP programs.
ath
=>Scripting tags are categorized into the following:
(a)Scriptlet tag
ip
(b)Expression tag
(c)Declarative tag
Ma
(a)Scriptlet tag:
sh
=>Scriptlet tag is used to write normal JavaCode part of JSP programs
ate
syntax:
(b)Expression tag:
syntax:
<%= expression %>
(c)Declarative tag:
ii
syntax:
ath
<%! variables;methods %>
ip
=======================================================================
[Link] tags:
Ma
=>The tags which are used to specify the directions in translation
(a)page
(b)include
nk
(c)taglib
Ve
(a)page:
exp:
ii
List of attributes:
ath
[Link]
ip
[Link]
[Link]
[Link]
Ma
[Link]
sh
[Link]
[Link]
ate
[Link]
[Link]
nk
[Link]
[Link]
Ve
[Link]
[Link]
-----------------------------------------------------
(b)include:
syntax:
Exp:
ii
<%@ include file="[Link]" %>
ath
-----------------------------------------------------
ip
(c)taglib:
Ma
=>'taglib' directive tag specifies to add specified url to current
JSP page and which is used part of EL(Expression Lang) and JSTL
syntax:
ate
===============================================
nk
Exp program1:
Note:
[Link]
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="[Link]" method="post">
Enter the Value:<input type="text" name="v"><br>
<input type="submit" value="Factorial">
</form>
</body>
</html>
ii
[Link]
ath
<%@ page language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
errorPage="[Link]"%>
ip
<!DOCTYPE html>
<html> Ma
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%!
sh
int fact;
int factorial(int n)
{
ate
fact=1;
for(int i=n;i>=1;i--)
{
fact=fact*i;
nk
}
return fact;
}
%>
Ve
<%
int val = [Link]([Link]("v"));
int result = factorial(val);
[Link]("Factorial : "+result+"<br>");
%>
<%@include file="[Link]"%>
</body>
</html>
[Link]
<%@ page language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
isErrorPage="true"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
ii
<%
[Link]("Enter only Integer value...<br>");
ath
%>
<%= exception %>
<br>
<%@include file="[Link]"%>
</body>
ip
</html>
[Link]
[Link]
nk
Diagram:
Ve
ii
ath
=======================================================================
ip
=>The following are the implicit objects of JSP:
Ma
application - [Link]
config - [Link]
sh
request - [Link]
ate
response - [Link]
out - [Link]
session - [Link]
nk
exception - [Link]
Ve
page - [Link]
pageContext - [Link]
=============================================================
[Link] tags:
=>Action Tags are used to include some basic actions like inserting
some other page resources ,forwarding the request to another page,
Note:
ii
------------------------------------------------------
ath
=>The following are some Important action tags available in JSP:
ip
1.<jsp:include>
2.<jsp:forward>
3.<jsp:param>
Ma
4.<jsp:useBean>
sh
5.<jsp:setProperty>
6.<jsp:getProperty>
ate
nk
1.<jsp:include> :
Ve
=>If the resource is static then its content is included in the JSP
page.
=>If the resource is dynamic then its result is included in the JSP
page.
syntax:
<jsp:include attributes>
ii
</jsp:include>
ath
attributes of include tag:
ip
*imp
Ma
page : Takes a relative URL,which locates the resource
<jsp:include page="<%=mypath%>"/>
ate
2.<jsp:forward>:
=> This action tag forwards a JSP request to another resource and
=>If the resource is dynamic then we can use a jsp:param tag to pass
name and value of the parameter to the resource.
sntax:
<jsp:forward attributes>
</jsp:forward>
ii
Exp:
ath
<jsp:forward page="/[Link]"/>
<jsp:forward page="<%=mypath%>"/>
ip
3.<jsp:param>:
Ma
This action tag is used to hold the parameter with value and which
syntax:
ate
====================================================
nk
4.<jsp:useBean>:
Ve
syntax:
<jsp:useBean attributes>
</jsp:useBean>
(a)id
ii
(b)scope
ath
(c)class
(d)beanName
ip
(e)type
(a)id:
Ma
=>which represents the variable name assigned to id attribute of
sh
<jsp:useBean> tag and which holds the reference of JavaBean instance.
ate
(b)scope:
created or located.
Ve
(i)page scope : within the JSP page,until the page sends response.
(ii)request scope : JSP page processing the same request until a JSP sends response.
(c)class :
bean instance.
ii
(d)beanName :
ath
=>The beanName attribute takes a qualified class name.
ip
(e)type :
Ma
=>The "type" attribute takes a qualified className or interfaceName,
5.<jsp:setProperty>:
ate
Types of attributes:
Ve
(a)name
(b)property
(c)value
(d)param
(a)name:
(b)property:
ii
specifies the setter method that has to be invoked.
ath
(c)value:
ip
=>The value attribute takes the value that has to be set to the
6.<jsp:getProperty>:
nk
the bean's getter method and writes the value to the current JspWriter.
Ve
Types of attributes:
(a)name
(b)property
(a)name:
(b)property:
=>which gets the value of a bean property and invokes the getter
ii
method of the bean property.
ath
-------------------------------------
ip
The following are some rare used Actions tags:
Syntax:
nk
<jsp:plugin attributes>
</jsp:plugin>
be displayed if the required plug-in cannot run and this action tag
must be used as a child tag with the <jsp:plugin> action tag.
Syntax:
<jsp:fallback>
</jsp:fallback>
ii
ath
9. < jsp:params >
ip
pass to an applet.
Syntax:
Ma
<jsp:params>
sh
<!-one or more jsp:param tags---
</jsp:params>
ate
=======================================================================
nk
Exp application_2:
[Link]
package test;
import [Link].*;
public class DBConnection {
private static Connection con=null;//reference variable
private DBConnection() {}
static
{
try {
[Link]("[Link]");
con = [Link]
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
}catch(Exception e) {[Link]();}
}
public static Connection getCon()
ii
{
return con;
ath
}
}
[Link]
ip
package test; Ma
import [Link].*;
import [Link].*;
try {
nk
PreparedStatement ps = [Link]
Ve
[Link](1,[Link]("uname"));
[Link](2,[Link]("pword"));
ResultSet rs = [Link]();
if([Link]()) {
fName = [Link](3);
}catch(Exception e) {[Link]();}
return fName;
ii
[Link]
ath
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
ip
<title>Insert title here</title>
</head> Ma
<body>
<form action="[Link]" method="post">
UserName:<input type="text" name="uname"><br>
PassWord:<input type="password" name="pword"><br>
<input type="submit" value="Login">
<a href="[Link]">NewUser?</a>
sh
</form>
</body>
</html>
ate
[Link]
pageEncoding="ISO-8859-1"
import="test.*"%>
<!DOCTYPE html>
Ve
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String fName = new LoginDAO().login(request);
if(fName==null){
[Link]("Invalid Login process...<br>");
%>
<jsp:include page="[Link]"/>
<%
}else{
%>
<jsp:forward page="[Link]">
<jsp:param value="<%=fName %>" name="fname"/>
</jsp:forward>
<%
}
%>
ii
</body>
</html>
ath
[Link]
ip
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html> Ma
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
sh
<%
String fName = [Link]("fname");
[Link]("Wlcome User : "+fName+"<br>");
ate
%>
</body>
</html>
nk
[Link]
<welcome-file-list>
<welcome-file>[Link]</welcome-file>
</welcome-file-list>
</web-app>
diagram:
ii
ip ath
Ma
----------------------------------------------------------------------
Assignment:
Dt : 17/6/2022
Exp program_3:
ii
[Link](Bean class)
ath
package test;
import [Link].*;
@SuppressWarnings("serial")
public class ProductBean implements Serializable{
ip
private String code,name;
private float price; Ma
private int qty;
public ProductBean() {}
public String getCode() {
return code;
}
public void setCode(String code) {
sh
[Link] = code;
}
public String getName() {
ate
return name;
}
public void setName(String name) {
[Link] = name;
}
nk
[Link]
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
ii
<form action="[Link]" method="post">
ath
Enter the PCode:<input type="text" name="pcode"><br>
<input type="submit" value="Display">
</form>
</body>
</html>
ip
[Link] Ma
<%@ page language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
import="[Link].*,test.*"%>
<!DOCTYPE html>
sh
<html>
<head>
<meta charset="ISO-8859-1">
ate
ii
</html>
ath
[Link]
ip
import="test.*"%>
<!DOCTYPE html> Ma
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
sh
<jsp:useBean id="ob" type="[Link]" scope="session"/>
ProductCode:<jsp:getProperty property="code" name="ob"/><br>
ProductName:<jsp:getProperty property="name" name="ob"/><br>
ate
</body>
nk
</html>
[Link]
Ve
[Link]
package test;
import [Link].*;
public class DBConnection {
private static Connection con=null;//reference variable
private DBConnection() {}
static
{
try {
[Link]("[Link]");
con = [Link]
ii
("jdbc:oracle:thin:@localhost:1521:xe","system","manager");
}catch(Exception e) {[Link]();}
ath
}
public static Connection getCon()
{
return con;
}
ip
}
[Link] Ma
package test;
import [Link].*;
import [Link].*;
sh
public class RetrieveDAO {
ate
try {
Ve
PreparedStatement ps = [Link]
[Link](1,[Link]("pcode"));
rs = [Link]();
}catch(Exception e) {[Link]();}
return rs;
=====================================================================
ii
Dt : 18/6/2022
ath
*imp
ip
Ma
Two types of development models are used in Java,for Web applications
1. Model-1 Architecture
2. Model-2 Architecture(MVC)
nk
1. Model-1 Architecture:
Ve
develop Web applications and this model uses JSP to design applications
A single change in one page may cause changes in other pages, leading
to unpredictable results.
ii
ath
(ii).Involves the developer at both the page development and the
ip
Ma
(iii).Increases the complexity of a program with the increase in the
===========================================================
2. Model-2 Architecture:
ii
and this Model-2 architecture is based on the MVC design model.
ath
=>MVC Stands for Model View Controller.
ip
Ma
Model: Represents enterprise data and business rules that specify how
using JavaBeans.
sh
enterprise data through the Model component and specifies how that
and delegates the responsibility for producing the next phase of the
complete control over each view, implying that any change in the Model
ii
business logic of other applications.
ath
(ii)Offers great flexibility to the presentation logic, which can be
ip
modified without effecting the business logic.
Ma
sh
ate
nk
Ve
=====================================================================
Dt : 20/6/2022
ii
Note:
ath
It is newly added feature in JSP technology.
ip
syntax of EL:
$(expression)
Ma
sh
The following are the implicit objects of EL:
ate
pageScope : It maps the given attribute name with the value,set in the vxvc v
page scope
nk
requestScope : It maps the given attribute name with the value set
Ve
sessionScope : It maps the given attribute name with the value set
paramValues :
ii
It maps the request parameters to the array of values
ath
header : It maps the request header name to the single value
ip
Ma
headerValues : It maps the request header names to the array of values
===============================================================
CoreJava Objects:
[Link] objects
(i)Byte Object
(ii)Short Object
(iii)Integer object
(iv)Long Object
(v)Float Object
(vi)Double Object
(vii)Character object
(viii)Boolean Object
ii
[Link] Objects
ath
(i)String Object
(ii)StringBuffer object
ip
(iii)StringBuilder object
[Link] Objects
(iv)Object Array
ate
(v)Jagged Array
[Link]<E> Objects
nk
(a)Set<E>
(i)HashSet<E> object
Ve
(ii)LinkedHashSet<E> Object
(iii)TreeSet<E> Object
(b)List<E>
(i)ArrayList<E> Object
(ii)Vector<E> Object
|->Stack<E> Object
(iii)LinkedList<E> Object
(c)Queue<E>
(i)PriorityQueue<E> Object
|->Deque<E>
(ii)ArrayDeque<E> Object
ii
[Link]<K,V> Objects
ath
(i)HashMap<K,V> Object
(ii)LinkedHashMap<K,V> Object
ip
(iii)TreeMap<K,V> Object
(iv)Hashtable<K,V> Object
[Link]<E> objects
Ma
--------------------------
sh
JDBC Objects:
[Link] Object
ate
[Link] Object
[Link] Object
nk
[Link] object
[Link] object
[Link] object
[Link] object
[Link] Object
------------
Servlet Objects:
[Link] object
[Link] Object
ii
[Link] object/HttpServletRequest object
ath
[Link] object/HttpServletResponse object
[Link] object
ip
[Link] object
[Link] object
JSP objects:
[Link]
nk
[Link]
[Link]
Ve
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
----------
JSP EL objects:
[Link]
[Link]
ii
[Link]
ath
[Link]
[Link]
ip
[Link]
[Link]
[Link]
Ma
[Link]
sh
[Link]
[Link]
ate
--------------------------
Note:
nk
Advantages of JSTL:
(i)Fast Development
Ve
(ii)Code Reusability
(2)Function Tags
(3)Formatting Tags
(4)XML Tags
(5)SQL Tags
ii
ath
Note:
ip
=>To Execute JSTL Tags we use the following steps:
Ma
sh
(i)Download the following Jar files to execute JSTL tags
ate
[Link]
[Link]
nk
------------------------------------------------------------
(1)Core Tags:
syntax:
prefix="c" %>
ii
ath
The following are the List of JSTL Core Tags:
ip
c:out ->It displays the result of an expression, similar to
<%=...%> tag.
Ma
c:import->It Retrives relative or an absolute URL.
sh
in the body.
*imp
ii
c:forTokens-> It iterates over tokens which is separated by the
ath
supplied delimeters.
ip
c:param-> It adds a parameter in a containing 'import' tag's URL.
Ma
c:redirect-> It redirects the browser to a new URL and supports the
context-relative URLs.
sh
-----------------------------------------------------
(2)Function Tags:
nk
functions.
syntax:
ii
fn:containsIgnoreCase(): It is used to test if an input string
ath
contains the specified substring as a case insensitive way.
ip
fn:endsWith() : It is used to test if an input string ends with the
specified suffix.
Ma
fn:indexOf(): It returns an index within a string of first occurrence
sh
of a specified substring.
ate
fn:trim(): It removes the blank spaces from both the ends of a string.
nk
case.
fn:toUpperCase(): It converts all the characters of a string to
uppercase.
ii
ath
fn:length(): It returns the number of characters inside a string, or
ip
Ma
fn:replace(): It replaces all the occurrence of a string with
---------------------------------------------------------------
sh
(3)Formatting Tags:
syntax:
prefix="fmt" %>
List of some Formatting tags:
ii
specific format or precision.
ath
fmt:parseDate : It parses the string representation of a time and
ip
date.
fmt:setTimeZone
Ma
: It stores the time zone inside a time zone
configuration variable.
sh
*imp
ate
-------------------------------------------------------------
Ve
(4)XML Tags:
=>The JSTL XML tags are used for providing a JSP-centric way of
syntax:
<%@ taglib uri="[Link] prefix="x" %>
(5)SQL Tags:
=>The SQL tag library allows the tags to Interact with RDBMS
or Oracle.
ii
ath
syntax:
ip
Note:
Ma
=>In realtime we must not have JSP Centric XML and DB Connections,
because of this reason XML tags and SQL Tags are less used when
sh
compared to other tags.
================================================================
ate
nk
Ve