SlideShare a Scribd company logo
1 of 52
Servlets
By: Priyanka Pradhan
MJPRU
Priyanka Pradhan
 Servlet technology is used to create a web
application (resides at server side and
generates a dynamic web page).
 Servlet technology is robust and scalable
because of java language.
 Before Servlet, CGI (Common Gateway
Interface) scripting language was common as
a server-side programming language.
Priyanka Pradhan
 Servlet is an interface that must be
implemented for creating any Servlet.
 Servlet is a class that extends the
capabilities of the servers and responds to
the incoming requests. It can respond to any
requests.
 Servlet is a web component that is deployed
on the server to create a dynamic web page.
Priyanka Pradhan
Priyanka Pradhan
 A web application is an application accessible
from the web.
 A web application is composed of web
components like Servlet, JSP, Filter, etc. and
other elements such as HTML, CSS, and
JavaScript.
 The web components typically execute in
Web Server and respond to the HTTP
request.
Priyanka Pradhan
 CGI technology enables the web server to
call an external program and pass HTTP
request information to the external program
to process the request.
 For each request, it starts a new process.
Priyanka Pradhan
 If the number of clients increases, it takes
more time for sending the response.
 For each request, it starts a process, and the
web server is limited to start processes.
 It uses platform dependent language e.g. C,
C++, perl.
Priyanka Pradhan
 The web container creates threads for
handling the multiple requests to the
Servlet.
 Threads have many benefits over the
Processes such as they share a common
memory area, lightweight, cost of
communication between the threads are low.
Priyanka Pradhan
 Website: static vs dynamic
 HTTP
 HTTP Requests
 Get vs Post
 Container
Priyanka Pradhan
 The request sent by the computer to a web
server, contains all sorts of potentially
interesting information.
Priyanka Pradhan
GET
 only limited amount of data can be sent because data is sent in header.
 not secured because data is exposed in URL bar.
 can be bookmarked.
 idempotent . It means second request will be ignored until response of first request is delivered
 more efficient and used more than Post.
POST
 large amount of data can be sent because data is sent in body.
 secured because data is not exposed in URL bar.
 cannot be bookmarked.
 non-idempotent.
 less efficient and
 used less than get.
Priyanka Pradhan
 If the user wants to read the web pages as
per input then the servlet container is used
in java.
 The servlet container is the part of web
server which can be run in a separate
process.
Priyanka Pradhan
Priyanka Pradhan
 The javax.servlet and javax.servlet.http
packages represent interfaces and classes for
servlet api.
Priyanka Pradhan
 The javax.servlet package contains many
interfaces and classes that are used by the
servlet or web container.
 These are not specific to any protocol.
Priyanka Pradhan
 The javax.servlet.http package contains
interfaces and classes that are responsible
for http requests only.
Priyanka Pradhan
 Servlet
 ServletRequest
 ServletResponse
 RequestDispatcher
 ServletConfig
 ServletContext
 SingleThreadModel
 Filter
 FilterConfig
 FilterChain
 ServletRequestListener
 ServletRequestAttributeListener
 ServletContextListener
 ServletContextAttributeListener
Priyanka Pradhan
 GenericServlet
 ServletInputStream
 ServletOutputStream
 ServletRequestWrapper
 ServletResponseWrapper
 ServletRequestEvent
 ServletContextEvent
 ServletRequestAttributeEvent
 ServletContextAttributeEvent
 ServletException
 UnavailableException
Priyanka Pradhan
 HttpServletRequest
 HttpServletResponse
 HttpSession
 HttpSessionListener
 HttpSessionAttributeListener
 HttpSessionBindingListener
 HttpSessionActivationListener
 HttpSessionContext (deprecated now)
Priyanka Pradhan
 HttpServlet
 Cookie
 HttpServletRequestWrapper
 HttpServletResponseWrapper
 HttpSessionEvent
 HttpSessionBindingEvent
 HttpUtils (deprecated now)
Priyanka Pradhan
import java.io.*; import javax.servlet.*;
public class First implements Servlet{
ServletConfig config=null;
public void init(ServletConfig config){
this.config=config;
System.out.println("servlet is initialized"); }
public void service(ServletRequest req,ServletResponse res)
throws IOException,ServletException{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.print("<html><body>"); out.print("<b>hello simple servlet</b>"); out.print("</body>
</html>"); }
public void destroy(){System.out.println("servlet is destroyed");}
public ServletConfig getServletConfig(){return config;}
public String getServletInfo(){return "copyright 2007-1010";} }
 GenericServlet class
implements Servlet, ServletConfig and Serializa
ble interfaces.
 It provides the implementation of all the
methods of these interfaces except the service
method.
 GenericServlet class can handle any type of
request so it is protocol-independent.
 You may create a generic servlet by inheriting
the GenericServlet class and providing the
implementation of the service method.
Priyanka Pradhan
 public void init(ServletConfig config)
 public abstract void service(ServletRequest request, ServletResponse
response)
 public void destroy()
 public ServletConfig getServletConfig()
 public String getServletInfo()
 public void init()
 public ServletContext getServletContext()
 public String getInitParameter(String name)
 public Enumeration getInitParameterNames()
 public String getServletName()
 public void log(String msg)
 public void log(String msg,Throwable t)
Priyanka Pradhan
import java.io.*;
import javax.servlet.*;
public class First extends GenericServlet{
public void service(ServletRequest req,ServletResponse res)
throws IOException,ServletException{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.print("<html><body>");
out.print("<b>hello generic servlet</b>");
out.print("</body></html>"); } }
Priyanka Pradhan
 The HttpServlet class extends the
GenericServlet class and implements
Serializable interface.
 It provides http specific methods such as
doGet, doPost, doHead, doTrace etc.
Priyanka Pradhan
 public void service(ServletRequest req,ServletResponse res)
 protected void service(HttpServletRequest req,
HttpServletResponse res)
 protected void doGet(HttpServletRequest req,
HttpServletResponse res)
 protected void doPost(HttpServletRequest req,
HttpServletResponse res)
 protected void doHead(HttpServletRequest req,
HttpServletResponse res)
 protected void doOptions(HttpServletRequest req,
HttpServletResponse res)
 protected void doPut(HttpServletRequest req,
HttpServletResponse res)
Priyanka Pradhan
The web container maintains the life cycle of a
servlet instance.
 Servlet class is loaded.
 Servlet instance is created.
 init method is invoked.
 service method is invoked.
 destroy method is invoked.
Priyanka Pradhan
 The classloader is responsible to load the
servlet class.
 The servlet class is loaded when the first
request for the servlet is received by the
web container.
Priyanka Pradhan
 The web container creates the instance of a
servlet after loading the servlet class.
 The servlet instance is created only once in
the servlet life cycle.
Priyanka Pradhan
 The web container calls the init method only
once after creating the servlet instance.
public void init(ServletConfig config) throws
ServletException
Priyanka Pradhan
 The web container calls the service method
each time when request for the servlet is
received.
public void service(ServletRequest request, S
ervletResponse response)throws ServletExce
ption, IOException
Priyanka Pradhan
 The web container calls the destroy method
before removing the servlet instance from
the service.
public void destroy()
Priyanka Pradhan
The servlet example can be created by
three ways:
 By implementing Servlet interface,
 By inheriting GenericServlet class, (or)
 By inheriting HttpServlet class
Priyanka Pradhan
The steps are as follows:
 Create a directory structure
 Create a Servlet
 Compile the Servlet
 Create a deployment descriptor
 Start the server and deploy the project
 Access the servlet
Priyanka Pradhan
 The directory structure defines that where
to put the different types of files so that web
container may get the information and
respond to the client.
Priyanka Pradhan
Priyanka Pradhan
There are three ways to create the servlet.
 By implementing the Servlet interface
 By inheriting the GenericServlet class
 By inheriting the HttpServlet class
Priyanka Pradhan
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class DemoServlet extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException {
res.setContentType("text/html");//setting the content type
PrintWriter pw=res.getWriter();//get the stream to write the data
//writing html in the stream
pw.println("<html><body>");
pw.println("Welcome to servlet");
pw.println("</body></html>");
pw.close();//closing the stream }}
 For compiling the Servlet, jar file is required
to be loaded. Different Servers provide
different jar files:
 servlet-api.jar Apache Tomcat
Priyanka Pradhan
Two ways to load the jar file
 set classpath
 paste the jar file in JRE/lib/ext folder
Priyanka Pradhan
 The deployment descriptor is an xml file,
from which Web Container gets the
information about the servet to be invoked.
 The web container uses the Parser to get the
information from the web.xml file. There are
many xml parsers such as SAX, DOM.
Priyanka Pradhan
<web-app>
<servlet>
<servlet-name>jaiswal</servlet-name>
<servlet-class>Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>jaiswal</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
</web-app>
Priyanka Pradhan
 <web-app> represents the whole application.
 <servlet> is sub element of <web-app> and represents the
servlet.
 <servlet-name> is sub element of <servlet> represents the
name of the servlet.
 <servlet-class> is sub element of <servlet> represents the
class of the servlet.
 <servlet-mapping> is sub element of <web-app>. It is used
to map the servlet.
 <url-pattern> is sub element of <servlet-mapping>. This
pattern is used at client side to invoke the servlet.
Priyanka Pradhan
To start Apache Tomcat server, double click
on the startup.bat file under apache-
tomcat/bin directory.
Priyanka Pradhan
 Go to My Computer properties ->
 Click on advanced tab then environment
variables ->
 Click on the new tab of user variable ->
 Write JAVA_HOME in variable name and paste
the path of jdk folder in variable value ->
 ok -> ok -> ok.
Priyanka Pradhan
 After setting the JAVA_HOME double click on
the startup.bat file in apache tomcat/bin.
Priyanka Pradhan
There are two types of tomcat available:
 Apache tomcat that needs to extract only (no
need to install)
 Apache tomcat that needs to install
Priyanka Pradhan
 Changing the port number is required if there
is another server running on the same system
with same port number.
 Open server.xml file in notepad. It is located
inside the apache-tomcat/conf directory .
Change the Connector port = 8080 and
replace 8080 by any four digit number
instead of 8080. Let us replace it by 9999
and save this file.
Priyanka Pradhan
 Copy the project and paste it in the webapps
folder under apache tomcat.
Priyanka Pradhan
Priyanka Pradhan
 Open broser and write
http://hostname:portno/contextroot/urlpatt
ernofservlet.
Priyanka Pradhan
The server checks if the servlet is requested for the first
time.
 If yes, web container does the following tasks:
 loads the servlet class.
 instantiates the servlet class.
 calls the init method passing the ServletConfig object
else
 calls the service method passing request and response
objects
 The web container calls the destroy method when it needs
to remove the servlet such as at time of stopping server or
undeploying the project.
Priyanka Pradhan

More Related Content

What's hot

An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technologyvikram singh
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1vikram singh
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsi krishna
 
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletFahmi Jafar
 
Servlet api &amp; servlet http package
Servlet api &amp; servlet http packageServlet api &amp; servlet http package
Servlet api &amp; servlet http packagerenukarenuka9
 
Java servlets
Java servletsJava servlets
Java servletslopjuan
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programmingKumar
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.pptVMahesh5
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods pptkamal kotecha
 
Javax.servlet,http packages
Javax.servlet,http packagesJavax.servlet,http packages
Javax.servlet,http packagesvamsi krishna
 
Request dispatching in servlet
Request dispatching in servletRequest dispatching in servlet
Request dispatching in servletvikram singh
 
Java EE 01-Servlets and Containers
Java EE 01-Servlets and ContainersJava EE 01-Servlets and Containers
Java EE 01-Servlets and ContainersFernando Gil
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycleDhruvin Nakrani
 
Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtapVikas Jagtap
 
Java Servlets
Java ServletsJava Servlets
Java ServletsNitin Pai
 

What's hot (20)

An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technology
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
 
Listeners and filters in servlet
Listeners and filters in servletListeners and filters in servlet
Listeners and filters in servlet
 
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java Servlet
 
Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Jsp in Servlet by Rj
 
Servlet api &amp; servlet http package
Servlet api &amp; servlet http packageServlet api &amp; servlet http package
Servlet api &amp; servlet http package
 
Servlets
ServletsServlets
Servlets
 
Java servlets
Java servletsJava servlets
Java servlets
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
 
Servlets
ServletsServlets
Servlets
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
Javax.servlet,http packages
Javax.servlet,http packagesJavax.servlet,http packages
Javax.servlet,http packages
 
Request dispatching in servlet
Request dispatching in servletRequest dispatching in servlet
Request dispatching in servlet
 
Java EE 01-Servlets and Containers
Java EE 01-Servlets and ContainersJava EE 01-Servlets and Containers
Java EE 01-Servlets and Containers
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 
Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtap
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 

Similar to Servlet

Http Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesHttp Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesbharathiv53
 
ADP - Chapter 2 Exploring the java Servlet Technology
ADP - Chapter 2 Exploring the java Servlet TechnologyADP - Chapter 2 Exploring the java Servlet Technology
ADP - Chapter 2 Exploring the java Servlet TechnologyRiza Nurman
 
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
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface pptTaha Malampatti
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servletssbd6985
 
Advance Java Programming (CM5I) 6.Servlet
Advance Java Programming (CM5I) 6.ServletAdvance Java Programming (CM5I) 6.Servlet
Advance Java Programming (CM5I) 6.ServletPayal Dungarwal
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technologyMinal Maniar
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESYoga Raja
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache TomcatAuwal Amshi
 
Session 26 - Servlets Part 2
Session 26 - Servlets Part 2Session 26 - Servlets Part 2
Session 26 - Servlets Part 2PawanMM
 
Java Servlet
Java ServletJava Servlet
Java ServletYoga Raja
 

Similar to Servlet (20)

Http Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesHttp Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responses
 
gayathri.pptx
gayathri.pptxgayathri.pptx
gayathri.pptx
 
Java servlets
Java servletsJava servlets
Java servlets
 
Chap4 4 1
Chap4 4 1Chap4 4 1
Chap4 4 1
 
ADP - Chapter 2 Exploring the java Servlet Technology
ADP - Chapter 2 Exploring the java Servlet TechnologyADP - Chapter 2 Exploring the java Servlet Technology
ADP - Chapter 2 Exploring the java Servlet Technology
 
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
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface ppt
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Servlet 01
Servlet 01Servlet 01
Servlet 01
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
 
Lecture5
Lecture5Lecture5
Lecture5
 
Advance Java Programming (CM5I) 6.Servlet
Advance Java Programming (CM5I) 6.ServletAdvance Java Programming (CM5I) 6.Servlet
Advance Java Programming (CM5I) 6.Servlet
 
J2ee servlet
J2ee servletJ2ee servlet
J2ee servlet
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technology
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
 
Spatial approximate string search Doc
Spatial approximate string search DocSpatial approximate string search Doc
Spatial approximate string search Doc
 
Weblogic
WeblogicWeblogic
Weblogic
 
Session 26 - Servlets Part 2
Session 26 - Servlets Part 2Session 26 - Servlets Part 2
Session 26 - Servlets Part 2
 
Java Servlet
Java ServletJava Servlet
Java Servlet
 

More from Priyanka Pradhan

Tomato disease detection using deep learning convolutional neural network
Tomato disease detection using deep learning convolutional neural networkTomato disease detection using deep learning convolutional neural network
Tomato disease detection using deep learning convolutional neural networkPriyanka Pradhan
 
programming with python ppt
programming with python pptprogramming with python ppt
programming with python pptPriyanka Pradhan
 
Image Processing Based Signature Recognition and Verification Technique Using...
Image Processing Based Signature Recognition and Verification Technique Using...Image Processing Based Signature Recognition and Verification Technique Using...
Image Processing Based Signature Recognition and Verification Technique Using...Priyanka Pradhan
 
GrayBox Testing and Crud Testing By: Er. Priyanka Pradhan
GrayBox Testing and Crud Testing By: Er. Priyanka PradhanGrayBox Testing and Crud Testing By: Er. Priyanka Pradhan
GrayBox Testing and Crud Testing By: Er. Priyanka PradhanPriyanka Pradhan
 
The agile requirements refinery(SRUM) by: Priyanka Pradhan
The agile requirements refinery(SRUM) by: Priyanka PradhanThe agile requirements refinery(SRUM) by: Priyanka Pradhan
The agile requirements refinery(SRUM) by: Priyanka PradhanPriyanka Pradhan
 
Social tagging and its trend
Social tagging and its trendSocial tagging and its trend
Social tagging and its trendPriyanka Pradhan
 
Behavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka PradhanBehavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka PradhanPriyanka Pradhan
 
software product and its characteristics
software product and its characteristicssoftware product and its characteristics
software product and its characteristicsPriyanka Pradhan
 
EDI(ELECTRONIC DATA INTERCHANGE)
EDI(ELECTRONIC DATA INTERCHANGE)EDI(ELECTRONIC DATA INTERCHANGE)
EDI(ELECTRONIC DATA INTERCHANGE)Priyanka Pradhan
 
collaborative tagging :-by Er. Priyanka Pradhan
collaborative tagging :-by Er. Priyanka Pradhancollaborative tagging :-by Er. Priyanka Pradhan
collaborative tagging :-by Er. Priyanka PradhanPriyanka Pradhan
 
Deploying java beans in jsp
Deploying java beans in jspDeploying java beans in jsp
Deploying java beans in jspPriyanka Pradhan
 
SOFTWARE PROCESS MONITORING AND AUDIT
SOFTWARE PROCESS MONITORING AND AUDITSOFTWARE PROCESS MONITORING AND AUDIT
SOFTWARE PROCESS MONITORING AND AUDITPriyanka Pradhan
 
s/w metrics monitoring and control
s/w metrics monitoring and controls/w metrics monitoring and control
s/w metrics monitoring and controlPriyanka Pradhan
 

More from Priyanka Pradhan (19)

Tomato disease detection using deep learning convolutional neural network
Tomato disease detection using deep learning convolutional neural networkTomato disease detection using deep learning convolutional neural network
Tomato disease detection using deep learning convolutional neural network
 
Applet
AppletApplet
Applet
 
Css
CssCss
Css
 
Javascript
JavascriptJavascript
Javascript
 
XML
XMLXML
XML
 
programming with python ppt
programming with python pptprogramming with python ppt
programming with python ppt
 
Core Java
Core JavaCore Java
Core Java
 
Image Processing Based Signature Recognition and Verification Technique Using...
Image Processing Based Signature Recognition and Verification Technique Using...Image Processing Based Signature Recognition and Verification Technique Using...
Image Processing Based Signature Recognition and Verification Technique Using...
 
GrayBox Testing and Crud Testing By: Er. Priyanka Pradhan
GrayBox Testing and Crud Testing By: Er. Priyanka PradhanGrayBox Testing and Crud Testing By: Er. Priyanka Pradhan
GrayBox Testing and Crud Testing By: Er. Priyanka Pradhan
 
The agile requirements refinery(SRUM) by: Priyanka Pradhan
The agile requirements refinery(SRUM) by: Priyanka PradhanThe agile requirements refinery(SRUM) by: Priyanka Pradhan
The agile requirements refinery(SRUM) by: Priyanka Pradhan
 
Social tagging and its trend
Social tagging and its trendSocial tagging and its trend
Social tagging and its trend
 
Behavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka PradhanBehavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka Pradhan
 
software product and its characteristics
software product and its characteristicssoftware product and its characteristics
software product and its characteristics
 
EDI(ELECTRONIC DATA INTERCHANGE)
EDI(ELECTRONIC DATA INTERCHANGE)EDI(ELECTRONIC DATA INTERCHANGE)
EDI(ELECTRONIC DATA INTERCHANGE)
 
collaborative tagging :-by Er. Priyanka Pradhan
collaborative tagging :-by Er. Priyanka Pradhancollaborative tagging :-by Er. Priyanka Pradhan
collaborative tagging :-by Er. Priyanka Pradhan
 
Deploying java beans in jsp
Deploying java beans in jspDeploying java beans in jsp
Deploying java beans in jsp
 
SOFTWARE PROCESS MONITORING AND AUDIT
SOFTWARE PROCESS MONITORING AND AUDITSOFTWARE PROCESS MONITORING AND AUDIT
SOFTWARE PROCESS MONITORING AND AUDIT
 
Pcmm
PcmmPcmm
Pcmm
 
s/w metrics monitoring and control
s/w metrics monitoring and controls/w metrics monitoring and control
s/w metrics monitoring and control
 

Recently uploaded

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...ranjana rawat
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 

Recently uploaded (20)

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 

Servlet

  • 2.  Servlet technology is used to create a web application (resides at server side and generates a dynamic web page).  Servlet technology is robust and scalable because of java language.  Before Servlet, CGI (Common Gateway Interface) scripting language was common as a server-side programming language. Priyanka Pradhan
  • 3.  Servlet is an interface that must be implemented for creating any Servlet.  Servlet is a class that extends the capabilities of the servers and responds to the incoming requests. It can respond to any requests.  Servlet is a web component that is deployed on the server to create a dynamic web page. Priyanka Pradhan
  • 5.  A web application is an application accessible from the web.  A web application is composed of web components like Servlet, JSP, Filter, etc. and other elements such as HTML, CSS, and JavaScript.  The web components typically execute in Web Server and respond to the HTTP request. Priyanka Pradhan
  • 6.  CGI technology enables the web server to call an external program and pass HTTP request information to the external program to process the request.  For each request, it starts a new process. Priyanka Pradhan
  • 7.  If the number of clients increases, it takes more time for sending the response.  For each request, it starts a process, and the web server is limited to start processes.  It uses platform dependent language e.g. C, C++, perl. Priyanka Pradhan
  • 8.  The web container creates threads for handling the multiple requests to the Servlet.  Threads have many benefits over the Processes such as they share a common memory area, lightweight, cost of communication between the threads are low. Priyanka Pradhan
  • 9.  Website: static vs dynamic  HTTP  HTTP Requests  Get vs Post  Container Priyanka Pradhan
  • 10.  The request sent by the computer to a web server, contains all sorts of potentially interesting information. Priyanka Pradhan
  • 11. GET  only limited amount of data can be sent because data is sent in header.  not secured because data is exposed in URL bar.  can be bookmarked.  idempotent . It means second request will be ignored until response of first request is delivered  more efficient and used more than Post. POST  large amount of data can be sent because data is sent in body.  secured because data is not exposed in URL bar.  cannot be bookmarked.  non-idempotent.  less efficient and  used less than get. Priyanka Pradhan
  • 12.  If the user wants to read the web pages as per input then the servlet container is used in java.  The servlet container is the part of web server which can be run in a separate process. Priyanka Pradhan
  • 14.  The javax.servlet and javax.servlet.http packages represent interfaces and classes for servlet api. Priyanka Pradhan
  • 15.  The javax.servlet package contains many interfaces and classes that are used by the servlet or web container.  These are not specific to any protocol. Priyanka Pradhan
  • 16.  The javax.servlet.http package contains interfaces and classes that are responsible for http requests only. Priyanka Pradhan
  • 17.  Servlet  ServletRequest  ServletResponse  RequestDispatcher  ServletConfig  ServletContext  SingleThreadModel  Filter  FilterConfig  FilterChain  ServletRequestListener  ServletRequestAttributeListener  ServletContextListener  ServletContextAttributeListener Priyanka Pradhan
  • 18.  GenericServlet  ServletInputStream  ServletOutputStream  ServletRequestWrapper  ServletResponseWrapper  ServletRequestEvent  ServletContextEvent  ServletRequestAttributeEvent  ServletContextAttributeEvent  ServletException  UnavailableException Priyanka Pradhan
  • 19.  HttpServletRequest  HttpServletResponse  HttpSession  HttpSessionListener  HttpSessionAttributeListener  HttpSessionBindingListener  HttpSessionActivationListener  HttpSessionContext (deprecated now) Priyanka Pradhan
  • 20.  HttpServlet  Cookie  HttpServletRequestWrapper  HttpServletResponseWrapper  HttpSessionEvent  HttpSessionBindingEvent  HttpUtils (deprecated now) Priyanka Pradhan
  • 21. import java.io.*; import javax.servlet.*; public class First implements Servlet{ ServletConfig config=null; public void init(ServletConfig config){ this.config=config; System.out.println("servlet is initialized"); } public void service(ServletRequest req,ServletResponse res) throws IOException,ServletException{ res.setContentType("text/html"); PrintWriter out=res.getWriter(); out.print("<html><body>"); out.print("<b>hello simple servlet</b>"); out.print("</body> </html>"); } public void destroy(){System.out.println("servlet is destroyed");} public ServletConfig getServletConfig(){return config;} public String getServletInfo(){return "copyright 2007-1010";} }
  • 22.  GenericServlet class implements Servlet, ServletConfig and Serializa ble interfaces.  It provides the implementation of all the methods of these interfaces except the service method.  GenericServlet class can handle any type of request so it is protocol-independent.  You may create a generic servlet by inheriting the GenericServlet class and providing the implementation of the service method. Priyanka Pradhan
  • 23.  public void init(ServletConfig config)  public abstract void service(ServletRequest request, ServletResponse response)  public void destroy()  public ServletConfig getServletConfig()  public String getServletInfo()  public void init()  public ServletContext getServletContext()  public String getInitParameter(String name)  public Enumeration getInitParameterNames()  public String getServletName()  public void log(String msg)  public void log(String msg,Throwable t) Priyanka Pradhan
  • 24. import java.io.*; import javax.servlet.*; public class First extends GenericServlet{ public void service(ServletRequest req,ServletResponse res) throws IOException,ServletException{ res.setContentType("text/html"); PrintWriter out=res.getWriter(); out.print("<html><body>"); out.print("<b>hello generic servlet</b>"); out.print("</body></html>"); } } Priyanka Pradhan
  • 25.  The HttpServlet class extends the GenericServlet class and implements Serializable interface.  It provides http specific methods such as doGet, doPost, doHead, doTrace etc. Priyanka Pradhan
  • 26.  public void service(ServletRequest req,ServletResponse res)  protected void service(HttpServletRequest req, HttpServletResponse res)  protected void doGet(HttpServletRequest req, HttpServletResponse res)  protected void doPost(HttpServletRequest req, HttpServletResponse res)  protected void doHead(HttpServletRequest req, HttpServletResponse res)  protected void doOptions(HttpServletRequest req, HttpServletResponse res)  protected void doPut(HttpServletRequest req, HttpServletResponse res) Priyanka Pradhan
  • 27. The web container maintains the life cycle of a servlet instance.  Servlet class is loaded.  Servlet instance is created.  init method is invoked.  service method is invoked.  destroy method is invoked. Priyanka Pradhan
  • 28.  The classloader is responsible to load the servlet class.  The servlet class is loaded when the first request for the servlet is received by the web container. Priyanka Pradhan
  • 29.  The web container creates the instance of a servlet after loading the servlet class.  The servlet instance is created only once in the servlet life cycle. Priyanka Pradhan
  • 30.  The web container calls the init method only once after creating the servlet instance. public void init(ServletConfig config) throws ServletException Priyanka Pradhan
  • 31.  The web container calls the service method each time when request for the servlet is received. public void service(ServletRequest request, S ervletResponse response)throws ServletExce ption, IOException Priyanka Pradhan
  • 32.  The web container calls the destroy method before removing the servlet instance from the service. public void destroy() Priyanka Pradhan
  • 33. The servlet example can be created by three ways:  By implementing Servlet interface,  By inheriting GenericServlet class, (or)  By inheriting HttpServlet class Priyanka Pradhan
  • 34. The steps are as follows:  Create a directory structure  Create a Servlet  Compile the Servlet  Create a deployment descriptor  Start the server and deploy the project  Access the servlet Priyanka Pradhan
  • 35.  The directory structure defines that where to put the different types of files so that web container may get the information and respond to the client. Priyanka Pradhan
  • 37. There are three ways to create the servlet.  By implementing the Servlet interface  By inheriting the GenericServlet class  By inheriting the HttpServlet class Priyanka Pradhan
  • 38. import javax.servlet.http.*; import javax.servlet.*; import java.io.*; public class DemoServlet extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { res.setContentType("text/html");//setting the content type PrintWriter pw=res.getWriter();//get the stream to write the data //writing html in the stream pw.println("<html><body>"); pw.println("Welcome to servlet"); pw.println("</body></html>"); pw.close();//closing the stream }}
  • 39.  For compiling the Servlet, jar file is required to be loaded. Different Servers provide different jar files:  servlet-api.jar Apache Tomcat Priyanka Pradhan
  • 40. Two ways to load the jar file  set classpath  paste the jar file in JRE/lib/ext folder Priyanka Pradhan
  • 41.  The deployment descriptor is an xml file, from which Web Container gets the information about the servet to be invoked.  The web container uses the Parser to get the information from the web.xml file. There are many xml parsers such as SAX, DOM. Priyanka Pradhan
  • 43.  <web-app> represents the whole application.  <servlet> is sub element of <web-app> and represents the servlet.  <servlet-name> is sub element of <servlet> represents the name of the servlet.  <servlet-class> is sub element of <servlet> represents the class of the servlet.  <servlet-mapping> is sub element of <web-app>. It is used to map the servlet.  <url-pattern> is sub element of <servlet-mapping>. This pattern is used at client side to invoke the servlet. Priyanka Pradhan
  • 44. To start Apache Tomcat server, double click on the startup.bat file under apache- tomcat/bin directory. Priyanka Pradhan
  • 45.  Go to My Computer properties ->  Click on advanced tab then environment variables ->  Click on the new tab of user variable ->  Write JAVA_HOME in variable name and paste the path of jdk folder in variable value ->  ok -> ok -> ok. Priyanka Pradhan
  • 46.  After setting the JAVA_HOME double click on the startup.bat file in apache tomcat/bin. Priyanka Pradhan
  • 47. There are two types of tomcat available:  Apache tomcat that needs to extract only (no need to install)  Apache tomcat that needs to install Priyanka Pradhan
  • 48.  Changing the port number is required if there is another server running on the same system with same port number.  Open server.xml file in notepad. It is located inside the apache-tomcat/conf directory . Change the Connector port = 8080 and replace 8080 by any four digit number instead of 8080. Let us replace it by 9999 and save this file. Priyanka Pradhan
  • 49.  Copy the project and paste it in the webapps folder under apache tomcat. Priyanka Pradhan
  • 51.  Open broser and write http://hostname:portno/contextroot/urlpatt ernofservlet. Priyanka Pradhan
  • 52. The server checks if the servlet is requested for the first time.  If yes, web container does the following tasks:  loads the servlet class.  instantiates the servlet class.  calls the init method passing the ServletConfig object else  calls the service method passing request and response objects  The web container calls the destroy method when it needs to remove the servlet such as at time of stopping server or undeploying the project. Priyanka Pradhan