SlideShare a Scribd company logo
1 of 48
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

What's hot (20)

Javascript 101
Javascript 101Javascript 101
Javascript 101
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architecture
 
Java script
Java scriptJava script
Java script
 
Javascript
JavascriptJavascript
Javascript
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Servlets
ServletsServlets
Servlets
 
Servlets
ServletsServlets
Servlets
 
Js ppt
Js pptJs ppt
Js ppt
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Event handling
Event handlingEvent handling
Event handling
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Servlets
ServletsServlets
Servlets
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Javascript conditional statements
Javascript conditional statementsJavascript conditional statements
Javascript conditional statements
 
Document Object Model (DOM)
Document Object Model (DOM)Document Object Model (DOM)
Document Object Model (DOM)
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
 
Html5 and-css3-overview
Html5 and-css3-overviewHtml5 and-css3-overview
Html5 and-css3-overview
 
JavaScript - Part-1
JavaScript - Part-1JavaScript - Part-1
JavaScript - Part-1
 

Similar to java Servlet technology

UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servletssbd6985
 
Server side programming
Server side programming Server side programming
Server side programming javed ahmed
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jspJafar Nesargi
 
Servlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, APIServlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, APIPRIYADARSINISK
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing Techglyphs
 
SERVER SIDE PROGRAMMING
SERVER SIDE PROGRAMMINGSERVER SIDE PROGRAMMING
SERVER SIDE PROGRAMMINGPrabu U
 
BITM3730Week12.pptx
BITM3730Week12.pptxBITM3730Week12.pptx
BITM3730Week12.pptxMattMarino13
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083Divyam Pateriya
 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and ServletsRaghu nath
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteTushar B Kute
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet backdoor
 

Similar to java Servlet technology (20)

Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
 
Server side programming
Server side programming Server side programming
Server side programming
 
TY.BSc.IT Java QB U3
TY.BSc.IT Java QB U3TY.BSc.IT Java QB U3
TY.BSc.IT Java QB U3
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
Servlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, APIServlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, API
 
Servlet
Servlet Servlet
Servlet
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
 
SERVER SIDE PROGRAMMING
SERVER SIDE PROGRAMMINGSERVER SIDE PROGRAMMING
SERVER SIDE PROGRAMMING
 
BITM3730Week12.pptx
BITM3730Week12.pptxBITM3730Week12.pptx
BITM3730Week12.pptx
 
J2ee servlet
J2ee servletJ2ee servlet
J2ee servlet
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083
 
Servlets
ServletsServlets
Servlets
 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and Servlets
 
Advanced java+JDBC+Servlet
Advanced java+JDBC+ServletAdvanced java+JDBC+Servlet
Advanced java+JDBC+Servlet
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet
 
Ecom 1
Ecom 1Ecom 1
Ecom 1
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Servlet.pptx
Servlet.pptxServlet.pptx
Servlet.pptx
 

More from Tanmoy Barman

JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivityTanmoy Barman
 
Web apps architecture
Web apps architectureWeb apps architecture
Web apps architectureTanmoy Barman
 
introduction to channel borrowing scheme in cellular networks
introduction to channel borrowing scheme in cellular networksintroduction to channel borrowing scheme in cellular networks
introduction to channel borrowing scheme in cellular networksTanmoy Barman
 
INTRODUCTION TO CLOUD COMPUTING
INTRODUCTION TO CLOUD COMPUTINGINTRODUCTION TO CLOUD COMPUTING
INTRODUCTION TO CLOUD COMPUTINGTanmoy Barman
 

More from Tanmoy Barman (7)

Java rmi
Java rmiJava rmi
Java rmi
 
Jini
JiniJini
Jini
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Java server pages
Java server pagesJava server pages
Java server pages
 
Web apps architecture
Web apps architectureWeb apps architecture
Web apps architecture
 
introduction to channel borrowing scheme in cellular networks
introduction to channel borrowing scheme in cellular networksintroduction to channel borrowing scheme in cellular networks
introduction to channel borrowing scheme in cellular networks
 
INTRODUCTION TO CLOUD COMPUTING
INTRODUCTION TO CLOUD COMPUTINGINTRODUCTION TO CLOUD COMPUTING
INTRODUCTION TO CLOUD COMPUTING
 

Recently uploaded

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 

Recently uploaded (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 

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.