SlideShare a Scribd company logo
UNDERSTANDING JAVA
SERVLET
by Tanmoy Barman
Discussions
 Client-Server Architecture.
 HTTP protocol.
 Introduction to Servlet.
 J2ee container and architecture.
 Servlet Life Cycle.
 Functions of servlet container.
 Servlet API.
 Example of servlet.
 Session Management Techniques.
 Servlet Collaboration.
 Comparing Servlet with CGI.
Client server architecture
Client server architecture
 Server: typically a application for large
computers which can handle multiple request
simultaneously, can process much faster. The
application of server is written in such a way
that it cannot be access by the user directly
but it waits for another program to connect and
then it process the request as need by the
user.
Client server architecture
 Client: an application that runs on simple
desktop computers. It has an attractive user
interface but itself does not have the data to
manipulate instead it takes input from the
user, connects the server and the server
responds to the request as need by the client
using this application.
HTTP protocol
 HTTP(Hyper Text Transfer Protocol ) is a
communication protocol for displaying HTML
pages inside web browser.
 HTTP are stateless protocol because it treats
each request independently and have no
knowledge of where the request have came
from.
 A stateless protocol treats each request and
response pair as an independent transaction.
 Default port no of HTTP is 80.
HTTP protocol
 The communication between the web browser
and the server are usually done using two
methods:-
1. GET.
2. POST.
 GET method is used to request data from a
specified resource.
 POST method is used to submit data from a
specified resource.
HTTP protocol
 GET methods are cached but POST method
cannot be cached.
 GET methods can be bookmarked but POST
methods cannot be bookmarked.
 GET methods have length restrictions where as
POST methods have no length restrictions.
 GET methods remains in history of the web
browser whereas the POST methods are not
present in the history of the web browser.
 GET methods are idempotent but POST methods
are non-idempotent.
HTTP protocol
 The other HTTP methods are:-
1. Trace
2. Put
3. Options
4. Head
5. Delete
Introduction to Servlet
 Servlet are Java class files which resides on
the web server which produces dynamic
output web pages when a client request for the
particular Servlet.
 So to execute a Servlet we need a compiler
and a JVM machine inside a web server same
as when we need to compile and run a simple
java program inside our desktop.
Introduction to Servlet
 To deploy our servlet inside the web server we
need a servlet container.
 Servlet container is a java virtual machine
inside web server which provides compilation
and run time execution of servlet.
 “Apache tomcat” is an example of popular
servlet container.
J2ee container and architecture
J2ee container and architecture
 Containers are used for deploying and
execution service provided by the component.
 The various types of container in J2EE:-
A. Applet container
B. Application client container
C. EJB container
D. Servlet container
Servlet Life Cycle
 When the client request for the servlet through
the web browser the Servlet container loads
the servlet for the first time, it calls the init()
method. Before the servlet can respond to any
request the init() method need to be finished or
the servlet need to be initialize. After the init()
method the servlet container marked the
servlet as available.
Servlet Life Cycle
 For each request form the client the servlet
container calls the service method on the
servlet which is going to process the request.
The service method can use all the resources
which are marked as available in the init()
method.
 The destroy() method is called to clean up the
resources when the server shuts down or
there is a lack of resources. It also calls the
save the current state information of the
servlet which will be used when the servlet
again called for the next time.
Functions of servlet container
 Manage servlet life cycles.
 Register a servlet for one or more URLS.
 Encode MIME base response.
 Decode MIME base request.
 Handles HTTP protocols along with other
protocols(ftp,pop,smtp,telnet,etc).
 Provide network services with request and
responses cycles.
Servlet API
 The java servlet API consist of two Packages
which helps in implementation of the servlet:-
1. javax.servlet
2. javax.servlet.http
Servlet API
 javax.servlet:- It provides the core functionality
of the servlet, this API consist of classes and
interfaces which is generic and protocol
independent.
 javax.servlet.http:- This API consist of classes
and interfaces which are HTTP protocol
specific.
SERVLET API
SERVLET API
 There are two types of servlet available by default
which has been defined in servlet API
1. GenericServlet
2. HttpServlet
 GenericServlet : it defines the classes and
interfaces which are protocol independent and
generic which is define on the javax.servlet
package. It defines simple life cycle methods
such as init, service, destroy. To write generic
servlet we simply have to override the abstract
service() method.
SERVLET API
 Signature of GenericServlet:-
 public abstract class GenericServlet extends
java.io.lang implements
Servlet, ServletConfig, java.io.seriliziable
SERVLET API
 HttpServlet :- it defines classes and interfaces
which are http protocol specific. It extends the
GenericServlet class therfore it inherits the
GenericServlet methods.
 Signature of HttpServlet:-
 Public abstract class HttpServlet extends
GenericServlet implements java.io.sereliziable
Example of servlet
 To write our own servlet we have to extend the
HttpServlet class.
 Public class our_servlet extends HttpServlet {
Public void doGet(HttpServletRequest req,HttpServletResponse
resp)throws IOException,ServletException{
//code for servlet
//the logic of the application
}
}
Example of servlet
 teddy_test.java
Public void display extends HttpServlet{
Public void doGet(HttpServlet response, HttpSrvlet request)throws
IOException,ServletException{
out.println(“<HTML>”);
out.println(“< BODY>”);
response.setContentType(“text/html”);
PrintWriter out=resp.getWriter();
out.println(“<p>Hello World</p>”);
out.println(“</ BODY>”);
out.println(“< /HTML>”);
}
}
Example of servlet
 Reading Form Data using Servlet:-
 Servlets handles form data parsing automatically using the following
methods depending on the situation:
 getParameter(): -You call request.getParameter() method to get the
value of a form parameter.
 getParameterValues(): -Call this method if the parameter appears
more than once and returns multiple values, for example checkbox.
 getParameterNames(): -Call this method if you want a complete
list of all parameters in the current request.
Example of servlet
 To get information from an html page
 Let assume there are two text box present in
html page name “teddy_test.html”
<form ACTION=“teddy_servlet.java”>
Name:<input type=“text” name=“nme”>
Age:<input type=“text” name=“age”>
<input type=“submit”>
Example of servlet
 teddy_servlet.java
Public void display extends HttpServlet{
Public void doGet(HttpServlet response, HttpSrvlet request)throws
IOException,ServletException{
out.println(“<HTML>”);
out.println(“< BODY>”);
response.setContentType(“text/html”);
Printwriter out=resp.getWriter();
String name=req.getParameter(“name”);
String age=req.getParameter(“age”);
out.println(“<p>name:-”+name+”age:-”+age+”</p>”);
out.println(“</ BODY>”);
out.println(“< /HTML>”);
}
}
Session Management
Techniques
 As HTTP is a stateless protocol it cannot
remember the same user over multiple page
request and treats the same user as different
user.
 So, if a user request for a page the server
responds when the same user request for the
another page the server thinks as another
user.
 The value or the state of the page need to be
retained when we purchasing goods from
merchant sites or keep us out of daily login to
a particular sites.
Session Management
Techniques
 The are methods to retain this value over
many pages:-
1. Cookies.
2. Hidden from fields
3. Url rewriting
4. Http Session
Session Management
Techniques
 Cookies are textual information which are
stored on the client file system.
 Cookies are send by the web server to the
web browser.
 Cookies contain cookie name and cookie
value.
 Advantages:-
1. They are simple to maintain
2. They are maintained by the client no over
head of the server.
Session Management
Techniques
 Disadvantage:-
1. It will not work if it is disabled by the web
browser.
2. Easy to tamper and one person can
impersonate as another user.
 Syntax:-
Cookie ck_object=new
Cookie(“cookie_name”,cookie_value);
Session Management
Techniques
 Hidden from fields, in HTML we have to type
an extra field called “hidden” which will not be
shown to the user by the web browser but it
will pass information to the web server. It
contains value from the previous request
which will going to process the future request.
Session Management
Techniques
 Advantage:-
1. To process it we do not require any special
type of server.
2. It will work where cookies will be disable by
the web browser.
 Disadvantage:-
1. If an error occurred before the values are
saved then the values are lost.
Session Management
Techniques
 Syntax:-
<input type=“hidden” name=“” values=“”>
This field will not be shown to the user but it will
pass information to the app server.
Session Management
Techniques
 Url rewriting, it a technique of appending
values to the end of the url, so that when the
user clicks on the link the values of the current
page will be passed through the url.
 Advantage:-
1. No extra form submission is required as in
hidden from fields.
Session Management
Techniques
 Disadvantage:-
1. It can only pass textual information.
2. Work with link only.
 Syntax:-
http://url? name1=value1&name2=value2
 Appends value on the end of the url where
parameters are separated by „&‟ and
name, value pairs are separated by „=„.
Session Management
Techniques
 HttpSession object is completely maintained
and created by the Web server. To achieve this
there is HttpRequest.getSession() method.
This method returns true if there the session is
created or creates a session before returning.
It is used to identify the user across multiple
pages and they can live up to specific time
bound by the server.
Session Management
Techniques
 Syntax:-
HttpSession ses_object=request.getSession();
ses_object.setAttribute(“ses_name”,ses_value);
//to set the session on the web server.
ses_object.getAttribute(“ses_name”);
// to get the value of the session from the web server.
Servlet Collaboration
 Servlet collaboration is a technique of sharing
information between the servlets.
 In servlet collaboration on servlet pass the
information directly to the another servlet.
 To pass the information directly one servlet
need to know about the other.
Servlet Collaboration
 The servlet collaboration can be achieved by
following methods :-
1. forward
2. include
3. sendRedirect
Servlet Collaboration
 Forward and include is the method of
RequestDispatcher interface.
 Syntax:-
RequestDispatcher
rd=response.getRequestDispatcher(“url”);
rd.forward(request,reponse);
 sendRedirect is the method of
HttpServletResponse interface
 Syntax:-
response.sendRedirect(“url of the redirect
servlet”);
Servlet Collaboration
 Difference between sendRedirect and forward:-
 The sendRedirect method is used to send the
forwarded address to resources in a new domain
or server where as the forward method is used to
send the forwarded address to resources inside
the server.
 In case of forward method the servlet container
takes cares of everything, the client and browser
is not involved, whereas in case of sendRedirect
method the forwarded address is sent to the
browser of the client.
Servlet Collaboration
 In forward, the old request and response is
send along with the forwarded address, the old
request is going to process the new request. In
case of sendRedirect the old request and
response is lost and a new response is
created by the web server and treated as a
new request by the browser.
Servlet Collaboration
 In forward the forwarded address in not seen
by the client; its is transparent whereas in
sendRedirect the url is present in the url bar of
the web browser.
 The forward method is fast than the
sendRedirect as it does not require an extra
round trip.
CGI(Common Gateway Interface) allows the application server to
call an external program which is going to process the client http
request and respond to it. It creates a new process for each
request made by the client.
What is CGI?
Servlet Vs. CGI
 CGI(Common Gateway Interface) scripts
creates a separate process for each request
made by the client where as servlet is initialize
only once and creates threads for each
request, so CGI scripts are lead to overhead
when there is rise in user.
 CGI are more prone to attacks than servlet.
 CGI scripts are executed to native to operating
system where as servlet are compiled to java
byte code which can run anywhere.
Servlet Vs. CGI
 CGI are platform dependent whereas servlet
are platform independent.
 Servlet handling of request us much faster
than CGI.
Thank you

More Related Content

PDF
Java exception handling ppt
PPTX
servlet in java
PDF
jQuery for beginners
PPT
JQuery introduction
PPTX
jQuery
PPTX
Servlets
PPTX
Java Server Pages(jsp)
PPT
Introduction to Javascript
Java exception handling ppt
servlet in java
jQuery for beginners
JQuery introduction
jQuery
Servlets
Java Server Pages(jsp)
Introduction to Javascript

What's hot (20)

PDF
Introduction to HTML5
PPTX
PPTX
Spring data jpa
PPT
Java multi threading
PPTX
Session tracking in servlets
PPTX
PPTX
Javascript operators
PPTX
Hibernate ppt
PPTX
Servlet.ppt
PPTX
PPTX
Introduction to java
PDF
Spring boot jpa
PDF
Spring MVC Framework
PPT
Struts
PPS
Java Exception handling
PPT
Java Servlets
PPT
Java tutorial PPT
PPTX
Enterprise java unit-1_chapter-3
PDF
Enterprise java unit-1_chapter-1
Introduction to HTML5
Spring data jpa
Java multi threading
Session tracking in servlets
Javascript operators
Hibernate ppt
Servlet.ppt
Introduction to java
Spring boot jpa
Spring MVC Framework
Struts
Java Exception handling
Java Servlets
Java tutorial PPT
Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-1
Ad

Similar to java Servlet technology (20)

PPTX
UNIT-3 Servlet
PPTX
JAVA SERVLETS acts as a middle layer between a request coming from a web brow...
ODP
servlet 2.5 & JSP 2.0
ODP
Servlets
PPTX
Servlets-UNIT3and introduction to servlet
PPT
Servlets
PPT
PPT
Module 4.pptModule 4.pptModule 4.pptModule 4.ppt
PPT
Servlet1.ppt
PPT
Servlet.ppt
PPT
Servlet.ppt
PPTX
servlets sessions and cookies, jdbc connectivity
PPTX
21CS642 Module 4_1 Servlets PPT.pptx VI SEM CSE Students
PPT
Servlet123jkhuiyhkjkljioyudfrtsdrestfhgb
PPT
Servlet (1) also contains code to create it.ppt
PDF
Java Servlets.pdf
PPTX
CS8651 IP Unit 3.pptx
PDF
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
PPT
JAVA Servlets
PPTX
J2ee servlet
UNIT-3 Servlet
JAVA SERVLETS acts as a middle layer between a request coming from a web brow...
servlet 2.5 & JSP 2.0
Servlets
Servlets-UNIT3and introduction to servlet
Servlets
Module 4.pptModule 4.pptModule 4.pptModule 4.ppt
Servlet1.ppt
Servlet.ppt
Servlet.ppt
servlets sessions and cookies, jdbc connectivity
21CS642 Module 4_1 Servlets PPT.pptx VI SEM CSE Students
Servlet123jkhuiyhkjkljioyudfrtsdrestfhgb
Servlet (1) also contains code to create it.ppt
Java Servlets.pdf
CS8651 IP Unit 3.pptx
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
JAVA Servlets
J2ee servlet
Ad

More from Tanmoy Barman (7)

PPSX
Java rmi
PPSX
PPSX
JDBC: java DataBase connectivity
PPSX
Java server pages
PPTX
Web apps architecture
DOCX
introduction to channel borrowing scheme in cellular networks
PPT
INTRODUCTION TO CLOUD COMPUTING
Java rmi
JDBC: java DataBase connectivity
Java server pages
Web apps architecture
introduction to channel borrowing scheme in cellular networks
INTRODUCTION TO CLOUD COMPUTING

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
KodekX | Application Modernization Development
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Encapsulation theory and applications.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Big Data Technologies - Introduction.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
NewMind AI Weekly Chronicles - August'25 Week I
KodekX | Application Modernization Development
Unlocking AI with Model Context Protocol (MCP)
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Network Security Unit 5.pdf for BCA BBA.
MYSQL Presentation for SQL database connectivity
Encapsulation theory and applications.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Spectral efficient network and resource selection model in 5G networks
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Building Integrated photovoltaic BIPV_UPV.pdf

java Servlet technology

  • 2. Discussions  Client-Server Architecture.  HTTP protocol.  Introduction to Servlet.  J2ee container and architecture.  Servlet Life Cycle.  Functions of servlet container.  Servlet API.  Example of servlet.  Session Management Techniques.  Servlet Collaboration.  Comparing Servlet with CGI.
  • 4. Client server architecture  Server: typically a application for large computers which can handle multiple request simultaneously, can process much faster. The application of server is written in such a way that it cannot be access by the user directly but it waits for another program to connect and then it process the request as need by the user.
  • 5. Client server architecture  Client: an application that runs on simple desktop computers. It has an attractive user interface but itself does not have the data to manipulate instead it takes input from the user, connects the server and the server responds to the request as need by the client using this application.
  • 6. HTTP protocol  HTTP(Hyper Text Transfer Protocol ) is a communication protocol for displaying HTML pages inside web browser.  HTTP are stateless protocol because it treats each request independently and have no knowledge of where the request have came from.  A stateless protocol treats each request and response pair as an independent transaction.  Default port no of HTTP is 80.
  • 7. HTTP protocol  The communication between the web browser and the server are usually done using two methods:- 1. GET. 2. POST.  GET method is used to request data from a specified resource.  POST method is used to submit data from a specified resource.
  • 8. HTTP protocol  GET methods are cached but POST method cannot be cached.  GET methods can be bookmarked but POST methods cannot be bookmarked.  GET methods have length restrictions where as POST methods have no length restrictions.  GET methods remains in history of the web browser whereas the POST methods are not present in the history of the web browser.  GET methods are idempotent but POST methods are non-idempotent.
  • 9. HTTP protocol  The other HTTP methods are:- 1. Trace 2. Put 3. Options 4. Head 5. Delete
  • 10. Introduction to Servlet  Servlet are Java class files which resides on the web server which produces dynamic output web pages when a client request for the particular Servlet.  So to execute a Servlet we need a compiler and a JVM machine inside a web server same as when we need to compile and run a simple java program inside our desktop.
  • 11. Introduction to Servlet  To deploy our servlet inside the web server we need a servlet container.  Servlet container is a java virtual machine inside web server which provides compilation and run time execution of servlet.  “Apache tomcat” is an example of popular servlet container.
  • 12. J2ee container and architecture
  • 13. J2ee container and architecture  Containers are used for deploying and execution service provided by the component.  The various types of container in J2EE:- A. Applet container B. Application client container C. EJB container D. Servlet container
  • 14. Servlet Life Cycle  When the client request for the servlet through the web browser the Servlet container loads the servlet for the first time, it calls the init() method. Before the servlet can respond to any request the init() method need to be finished or the servlet need to be initialize. After the init() method the servlet container marked the servlet as available.
  • 15. Servlet Life Cycle  For each request form the client the servlet container calls the service method on the servlet which is going to process the request. The service method can use all the resources which are marked as available in the init() method.  The destroy() method is called to clean up the resources when the server shuts down or there is a lack of resources. It also calls the save the current state information of the servlet which will be used when the servlet again called for the next time.
  • 16. Functions of servlet container  Manage servlet life cycles.  Register a servlet for one or more URLS.  Encode MIME base response.  Decode MIME base request.  Handles HTTP protocols along with other protocols(ftp,pop,smtp,telnet,etc).  Provide network services with request and responses cycles.
  • 17. Servlet API  The java servlet API consist of two Packages which helps in implementation of the servlet:- 1. javax.servlet 2. javax.servlet.http
  • 18. Servlet API  javax.servlet:- It provides the core functionality of the servlet, this API consist of classes and interfaces which is generic and protocol independent.  javax.servlet.http:- This API consist of classes and interfaces which are HTTP protocol specific.
  • 20. SERVLET API  There are two types of servlet available by default which has been defined in servlet API 1. GenericServlet 2. HttpServlet  GenericServlet : it defines the classes and interfaces which are protocol independent and generic which is define on the javax.servlet package. It defines simple life cycle methods such as init, service, destroy. To write generic servlet we simply have to override the abstract service() method.
  • 21. SERVLET API  Signature of GenericServlet:-  public abstract class GenericServlet extends java.io.lang implements Servlet, ServletConfig, java.io.seriliziable
  • 22. SERVLET API  HttpServlet :- it defines classes and interfaces which are http protocol specific. It extends the GenericServlet class therfore it inherits the GenericServlet methods.  Signature of HttpServlet:-  Public abstract class HttpServlet extends GenericServlet implements java.io.sereliziable
  • 23. Example of servlet  To write our own servlet we have to extend the HttpServlet class.  Public class our_servlet extends HttpServlet { Public void doGet(HttpServletRequest req,HttpServletResponse resp)throws IOException,ServletException{ //code for servlet //the logic of the application } }
  • 24. Example of servlet  teddy_test.java Public void display extends HttpServlet{ Public void doGet(HttpServlet response, HttpSrvlet request)throws IOException,ServletException{ out.println(“<HTML>”); out.println(“< BODY>”); response.setContentType(“text/html”); PrintWriter out=resp.getWriter(); out.println(“<p>Hello World</p>”); out.println(“</ BODY>”); out.println(“< /HTML>”); } }
  • 25. Example of servlet  Reading Form Data using Servlet:-  Servlets handles form data parsing automatically using the following methods depending on the situation:  getParameter(): -You call request.getParameter() method to get the value of a form parameter.  getParameterValues(): -Call this method if the parameter appears more than once and returns multiple values, for example checkbox.  getParameterNames(): -Call this method if you want a complete list of all parameters in the current request.
  • 26. Example of servlet  To get information from an html page  Let assume there are two text box present in html page name “teddy_test.html” <form ACTION=“teddy_servlet.java”> Name:<input type=“text” name=“nme”> Age:<input type=“text” name=“age”> <input type=“submit”>
  • 27. Example of servlet  teddy_servlet.java Public void display extends HttpServlet{ Public void doGet(HttpServlet response, HttpSrvlet request)throws IOException,ServletException{ out.println(“<HTML>”); out.println(“< BODY>”); response.setContentType(“text/html”); Printwriter out=resp.getWriter(); String name=req.getParameter(“name”); String age=req.getParameter(“age”); out.println(“<p>name:-”+name+”age:-”+age+”</p>”); out.println(“</ BODY>”); out.println(“< /HTML>”); } }
  • 28. Session Management Techniques  As HTTP is a stateless protocol it cannot remember the same user over multiple page request and treats the same user as different user.  So, if a user request for a page the server responds when the same user request for the another page the server thinks as another user.  The value or the state of the page need to be retained when we purchasing goods from merchant sites or keep us out of daily login to a particular sites.
  • 29. Session Management Techniques  The are methods to retain this value over many pages:- 1. Cookies. 2. Hidden from fields 3. Url rewriting 4. Http Session
  • 30. Session Management Techniques  Cookies are textual information which are stored on the client file system.  Cookies are send by the web server to the web browser.  Cookies contain cookie name and cookie value.  Advantages:- 1. They are simple to maintain 2. They are maintained by the client no over head of the server.
  • 31. Session Management Techniques  Disadvantage:- 1. It will not work if it is disabled by the web browser. 2. Easy to tamper and one person can impersonate as another user.  Syntax:- Cookie ck_object=new Cookie(“cookie_name”,cookie_value);
  • 32. Session Management Techniques  Hidden from fields, in HTML we have to type an extra field called “hidden” which will not be shown to the user by the web browser but it will pass information to the web server. It contains value from the previous request which will going to process the future request.
  • 33. Session Management Techniques  Advantage:- 1. To process it we do not require any special type of server. 2. It will work where cookies will be disable by the web browser.  Disadvantage:- 1. If an error occurred before the values are saved then the values are lost.
  • 34. Session Management Techniques  Syntax:- <input type=“hidden” name=“” values=“”> This field will not be shown to the user but it will pass information to the app server.
  • 35. Session Management Techniques  Url rewriting, it a technique of appending values to the end of the url, so that when the user clicks on the link the values of the current page will be passed through the url.  Advantage:- 1. No extra form submission is required as in hidden from fields.
  • 36. Session Management Techniques  Disadvantage:- 1. It can only pass textual information. 2. Work with link only.  Syntax:- http://url? name1=value1&name2=value2  Appends value on the end of the url where parameters are separated by „&‟ and name, value pairs are separated by „=„.
  • 37. Session Management Techniques  HttpSession object is completely maintained and created by the Web server. To achieve this there is HttpRequest.getSession() method. This method returns true if there the session is created or creates a session before returning. It is used to identify the user across multiple pages and they can live up to specific time bound by the server.
  • 38. Session Management Techniques  Syntax:- HttpSession ses_object=request.getSession(); ses_object.setAttribute(“ses_name”,ses_value); //to set the session on the web server. ses_object.getAttribute(“ses_name”); // to get the value of the session from the web server.
  • 39. Servlet Collaboration  Servlet collaboration is a technique of sharing information between the servlets.  In servlet collaboration on servlet pass the information directly to the another servlet.  To pass the information directly one servlet need to know about the other.
  • 40. Servlet Collaboration  The servlet collaboration can be achieved by following methods :- 1. forward 2. include 3. sendRedirect
  • 41. Servlet Collaboration  Forward and include is the method of RequestDispatcher interface.  Syntax:- RequestDispatcher rd=response.getRequestDispatcher(“url”); rd.forward(request,reponse);  sendRedirect is the method of HttpServletResponse interface  Syntax:- response.sendRedirect(“url of the redirect servlet”);
  • 42. Servlet Collaboration  Difference between sendRedirect and forward:-  The sendRedirect method is used to send the forwarded address to resources in a new domain or server where as the forward method is used to send the forwarded address to resources inside the server.  In case of forward method the servlet container takes cares of everything, the client and browser is not involved, whereas in case of sendRedirect method the forwarded address is sent to the browser of the client.
  • 43. Servlet Collaboration  In forward, the old request and response is send along with the forwarded address, the old request is going to process the new request. In case of sendRedirect the old request and response is lost and a new response is created by the web server and treated as a new request by the browser.
  • 44. Servlet Collaboration  In forward the forwarded address in not seen by the client; its is transparent whereas in sendRedirect the url is present in the url bar of the web browser.  The forward method is fast than the sendRedirect as it does not require an extra round trip.
  • 45. CGI(Common Gateway Interface) allows the application server to call an external program which is going to process the client http request and respond to it. It creates a new process for each request made by the client. What is CGI?
  • 46. Servlet Vs. CGI  CGI(Common Gateway Interface) scripts creates a separate process for each request made by the client where as servlet is initialize only once and creates threads for each request, so CGI scripts are lead to overhead when there is rise in user.  CGI are more prone to attacks than servlet.  CGI scripts are executed to native to operating system where as servlet are compiled to java byte code which can run anywhere.
  • 47. Servlet Vs. CGI  CGI are platform dependent whereas servlet are platform independent.  Servlet handling of request us much faster than CGI.