SlideShare a Scribd company logo
Defination:
 servlet is a java class that extends the
functionality of web server.
Eg:
 mail server
servlet is a class that performs virus scan to attached files
Benefits
 only one copy of servlet is loaded into jvm.
 each request begins a new thread to servlet process.
◙ save time
◙ response time increases
◙ it is scalable
Servlet implementation:
 servlet use class and interface from 2 package
◘ javax.servlet
 It contains classes to support generic protocol
◘ javax.servlet.http
 It extends classes in servlet package to add HTTP sapecific
functionality.
Servlet API :
o Servlet interface
o Genericservlet class
o HTTPservletrequest interface
o HTTPservletrequest interface
o Cookie class
o HTTPsession interrface
o single threadmodel interface
o servletexception class
o unavailableexception class
o servlettcontext interfave
o serrvletconfig interrface
Servlet interface:
 Every servlet must implements the javax.servlet interface
 It can implement in 2 ways:
◙ Directly implementing interface
◙ Extending any of 2 classes:
◙ javax.serrvlet.genricservlet
◙ javax.servlet.http.HTTPservlet
Methods:
◘ Init()
◘ Service()
◘ Destroy()
◘ Getservletinfo()
◘ Getservletconfig()
Service()
syntax:
 public abstract voidservice(servletrequest req,
servletresponse res)throws
servletException,IOException
◙ it is called whenever the request is made
◙it must be overridden in servlet
◙ it receives request via servletrequest and sends
response via servlet response
HTTP servlet
 It is an abstract class that is used for developing
HTTpservlets.
 It dose not override the service() method.
 It override doget() to handle GET requests and dopost()to
handle POST requests
Methods:
o serrvice()
o doget()
o dopost()
o dodelete()
o dooption()
o do put()
o do trace()
do get() or do post()
o protected void doget(HTTPServletRequest req
HTTPServletResponse res)throws servletException,IOException
o protected void dopost(HTTP ServletRequest
req,HTTPservletresponse res) throws
servletException,IOException
public class SessionServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException
{
res.setContentType("text/html");
OutputStream out = res.getOutputStream();
PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
HttpSession session = req.getSession(false);
if (session == null) {
session=req.getSession(true);
session.putValue ("VisitCount", "1");
}
pw.println("<html><body><pre>");
pw.println("session.isNew()="+session.isNew());
pw.println("session.getCreationTime()="+ new java.util.Date(
session.getCreationTime()));
pw.println("session.getID()="+session.getId());
pw.println("session.getLastAccessedTime()=" + new
java.util.Date(session.getLastAccessedTime()));
String strCount = (String) session.getValue("VisitCount");
pw.println("No. of times visited = " + strCount);
int count = Integer.parseInt(strCount); count++;
session.putValue("VisitCount", Integer.toString(count));
pw.println ("</pre></body></html>");
pw.flush();
}
}
Java ppt

More Related Content

What's hot

Glusterfs session #7 client, server interactions
Glusterfs session #7   client, server interactionsGlusterfs session #7   client, server interactions
Glusterfs session #7 client, server interactions
Pranith Karampuri
 
톰캣 #04-환경설정
톰캣 #04-환경설정톰캣 #04-환경설정
톰캣 #04-환경설정
GyuSeok Lee
 
Upgrading Puppet Agents
Upgrading Puppet AgentsUpgrading Puppet Agents
Upgrading Puppet Agents
Michael Smith
 
Mule hppt java
Mule hppt javaMule hppt java
Mule hppt java
Germano Barba
 
Sge
SgeSge
Kotlin Coroutines and Rx
Kotlin Coroutines and RxKotlin Coroutines and Rx
Kotlin Coroutines and Rx
Shaul Rosenzwieg
 
Akmal Khaleeq Waheed - Challenge 3 p2
Akmal Khaleeq Waheed - Challenge 3 p2Akmal Khaleeq Waheed - Challenge 3 p2
Akmal Khaleeq Waheed - Challenge 3 p2
tovmug
 
Qunit testing slider
Qunit testing sliderQunit testing slider
Qunit testing slider
Yating Chatiron
 
Shibuya,trac セッション
Shibuya,trac セッションShibuya,trac セッション
Shibuya,trac セッション
Yasunobu Kawaguchi
 
Java 8 고급 (4/6)
Java 8 고급 (4/6)Java 8 고급 (4/6)
Java 8 고급 (4/6)
Kyung Koo Yoon
 
Magento 2 Seminar - Miguel Balparda - M2 with PHP 7 and Varnish
Magento 2 Seminar - Miguel Balparda - M2 with PHP 7 and VarnishMagento 2 Seminar - Miguel Balparda - M2 with PHP 7 and Varnish
Magento 2 Seminar - Miguel Balparda - M2 with PHP 7 and Varnish
Yireo
 
AMC Minor Technical Issues
AMC Minor Technical IssuesAMC Minor Technical Issues
AMC Minor Technical Issues
Apache Traffic Server
 
Sockets in nach0s
Sockets in nach0sSockets in nach0s
Sockets in nach0snaniix21_3
 
マイナーツールを使ってみる
マイナーツールを使ってみるマイナーツールを使ってみる
マイナーツールを使ってみる
N Masahiro
 
My mule esb first http flow
My mule esb first http flowMy mule esb first http flow
My mule esb first http flow
Davide Rapacciuolo
 
Ruby version manager
Ruby version managerRuby version manager
Ruby version manager
Rahul Chaudhari
 

What's hot (17)

Glusterfs session #7 client, server interactions
Glusterfs session #7   client, server interactionsGlusterfs session #7   client, server interactions
Glusterfs session #7 client, server interactions
 
톰캣 #04-환경설정
톰캣 #04-환경설정톰캣 #04-환경설정
톰캣 #04-환경설정
 
Upgrading Puppet Agents
Upgrading Puppet AgentsUpgrading Puppet Agents
Upgrading Puppet Agents
 
Mule hppt java
Mule hppt javaMule hppt java
Mule hppt java
 
Sge
SgeSge
Sge
 
Kotlin Coroutines and Rx
Kotlin Coroutines and RxKotlin Coroutines and Rx
Kotlin Coroutines and Rx
 
Akmal Khaleeq Waheed - Challenge 3 p2
Akmal Khaleeq Waheed - Challenge 3 p2Akmal Khaleeq Waheed - Challenge 3 p2
Akmal Khaleeq Waheed - Challenge 3 p2
 
Qunit testing slider
Qunit testing sliderQunit testing slider
Qunit testing slider
 
Shibuya,trac セッション
Shibuya,trac セッションShibuya,trac セッション
Shibuya,trac セッション
 
Java 8 고급 (4/6)
Java 8 고급 (4/6)Java 8 고급 (4/6)
Java 8 고급 (4/6)
 
Magento 2 Seminar - Miguel Balparda - M2 with PHP 7 and Varnish
Magento 2 Seminar - Miguel Balparda - M2 with PHP 7 and VarnishMagento 2 Seminar - Miguel Balparda - M2 with PHP 7 and Varnish
Magento 2 Seminar - Miguel Balparda - M2 with PHP 7 and Varnish
 
AMC Minor Technical Issues
AMC Minor Technical IssuesAMC Minor Technical Issues
AMC Minor Technical Issues
 
Sockets in nach0s
Sockets in nach0sSockets in nach0s
Sockets in nach0s
 
マイナーツールを使ってみる
マイナーツールを使ってみるマイナーツールを使ってみる
マイナーツールを使ってみる
 
Running workflows through galaxy bosc presentation
Running workflows through galaxy bosc presentationRunning workflows through galaxy bosc presentation
Running workflows through galaxy bosc presentation
 
My mule esb first http flow
My mule esb first http flowMy mule esb first http flow
My mule esb first http flow
 
Ruby version manager
Ruby version managerRuby version manager
Ruby version manager
 

Similar to Java ppt

Servlet
Servlet Servlet
Servlet
Dhara Joshi
 
Java servlets
Java servletsJava servlets
Java servlets
yuvarani p
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
team11vgnt
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
BG Java EE Course
 
Chap4 4 1
Chap4 4 1Chap4 4 1
Chap4 4 1
Hemo Chella
 
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
bharathiv53
 
WEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES ServletWEB TECHNOLOGIES Servlet
Servlet viva questions
Servlet viva questionsServlet viva questions
Servlet viva questions
Vipul Naik
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
Ankit Minocha
 
gayathri.pptx
gayathri.pptxgayathri.pptx
gayathri.pptx
GayathriP95
 
Session 26 - Servlets Part 2
Session 26 - Servlets Part 2Session 26 - Servlets Part 2
Session 26 - Servlets Part 2
PawanMM
 
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
PRIYADARSINISK
 
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java Servlet
Fahmi Jafar
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
Dhruvin Nakrani
 
Javax.servlet,http packages
Javax.servlet,http packagesJavax.servlet,http packages
Javax.servlet,http packagesvamsi krishna
 
S E R V L E T S
S E R V L E T SS E R V L E T S
S E R V L E T Spatinijava
 
Servlets
ServletsServlets
J2ee servlet
J2ee servletJ2ee servlet
J2ee servlet
vinoth ponnurangam
 
Introduction to Servlets
Introduction to ServletsIntroduction to Servlets
Introduction to Servlets
Fulvio Corno
 
ajava unit 1.pptx
ajava unit 1.pptxajava unit 1.pptx
ajava unit 1.pptx
PawanKumar617960
 

Similar to Java ppt (20)

Servlet
Servlet Servlet
Servlet
 
Java servlets
Java servletsJava servlets
Java servlets
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Chap4 4 1
Chap4 4 1Chap4 4 1
Chap4 4 1
 
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
 
WEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES ServletWEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES Servlet
 
Servlet viva questions
Servlet viva questionsServlet viva questions
Servlet viva questions
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
 
gayathri.pptx
gayathri.pptxgayathri.pptx
gayathri.pptx
 
Session 26 - Servlets Part 2
Session 26 - Servlets Part 2Session 26 - Servlets Part 2
Session 26 - Servlets Part 2
 
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
 
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java Servlet
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 
Javax.servlet,http packages
Javax.servlet,http packagesJavax.servlet,http packages
Javax.servlet,http packages
 
S E R V L E T S
S E R V L E T SS E R V L E T S
S E R V L E T S
 
Servlets
ServletsServlets
Servlets
 
J2ee servlet
J2ee servletJ2ee servlet
J2ee servlet
 
Introduction to Servlets
Introduction to ServletsIntroduction to Servlets
Introduction to Servlets
 
ajava unit 1.pptx
ajava unit 1.pptxajava unit 1.pptx
ajava unit 1.pptx
 

More from renukarenuka9

mobile computing
mobile computingmobile computing
mobile computing
renukarenuka9
 
Dip
DipDip
Compiler design
Compiler designCompiler design
Compiler design
renukarenuka9
 
Web programming
Web programmingWeb programming
Web programming
renukarenuka9
 
Software engineering
Software engineeringSoftware engineering
Software engineering
renukarenuka9
 
Software engineering
Software engineeringSoftware engineering
Software engineering
renukarenuka9
 
Software engineering
Software engineeringSoftware engineering
Software engineering
renukarenuka9
 
Bigdata
BigdataBigdata
Bigdata
renukarenuka9
 
Bigdata ppt
Bigdata pptBigdata ppt
Bigdata ppt
renukarenuka9
 
Rdbms
RdbmsRdbms
Rdbms
RdbmsRdbms
operating system
operating systemoperating system
operating system
renukarenuka9
 
Rdbms
RdbmsRdbms
OPERATING SYSTEM
OPERATING SYSTEMOPERATING SYSTEM
OPERATING SYSTEM
renukarenuka9
 
Computer network
Computer networkComputer network
Computer network
renukarenuka9
 
computer network
computer networkcomputer network
computer network
renukarenuka9
 
operating system
operating systemoperating system
operating system
renukarenuka9
 
data mining
data miningdata mining
data mining
renukarenuka9
 
COMPUTER NETWORK
COMPUTER NETWORKCOMPUTER NETWORK
COMPUTER NETWORK
renukarenuka9
 

More from renukarenuka9 (20)

mobile computing
mobile computingmobile computing
mobile computing
 
Dip
DipDip
Dip
 
Compiler design
Compiler designCompiler design
Compiler design
 
Web programming
Web programmingWeb programming
Web programming
 
Software engineering
Software engineeringSoftware engineering
Software engineering
 
Software engineering
Software engineeringSoftware engineering
Software engineering
 
Software engineering
Software engineeringSoftware engineering
Software engineering
 
Bigdata
BigdataBigdata
Bigdata
 
Bigdata ppt
Bigdata pptBigdata ppt
Bigdata ppt
 
Rdbms
RdbmsRdbms
Rdbms
 
Rdbms
RdbmsRdbms
Rdbms
 
operating system
operating systemoperating system
operating system
 
Rdbms
RdbmsRdbms
Rdbms
 
OPERATING SYSTEM
OPERATING SYSTEMOPERATING SYSTEM
OPERATING SYSTEM
 
Data mining
Data miningData mining
Data mining
 
Computer network
Computer networkComputer network
Computer network
 
computer network
computer networkcomputer network
computer network
 
operating system
operating systemoperating system
operating system
 
data mining
data miningdata mining
data mining
 
COMPUTER NETWORK
COMPUTER NETWORKCOMPUTER NETWORK
COMPUTER NETWORK
 

Recently uploaded

GBSN- Microbiology (Lab 3) Gram Staining
GBSN- Microbiology (Lab 3) Gram StainingGBSN- Microbiology (Lab 3) Gram Staining
GBSN- Microbiology (Lab 3) Gram Staining
Areesha Ahmad
 
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
Sérgio Sacani
 
SCHIZOPHRENIA Disorder/ Brain Disorder.pdf
SCHIZOPHRENIA Disorder/ Brain Disorder.pdfSCHIZOPHRENIA Disorder/ Brain Disorder.pdf
SCHIZOPHRENIA Disorder/ Brain Disorder.pdf
SELF-EXPLANATORY
 
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
NathanBaughman3
 
platelets- lifespan -Clot retraction-disorders.pptx
platelets- lifespan -Clot retraction-disorders.pptxplatelets- lifespan -Clot retraction-disorders.pptx
platelets- lifespan -Clot retraction-disorders.pptx
muralinath2
 
RNA INTERFERENCE: UNRAVELING GENETIC SILENCING
RNA INTERFERENCE: UNRAVELING GENETIC SILENCINGRNA INTERFERENCE: UNRAVELING GENETIC SILENCING
RNA INTERFERENCE: UNRAVELING GENETIC SILENCING
AADYARAJPANDEY1
 
Hemostasis_importance& clinical significance.pptx
Hemostasis_importance& clinical significance.pptxHemostasis_importance& clinical significance.pptx
Hemostasis_importance& clinical significance.pptx
muralinath2
 
erythropoiesis-I_mechanism& clinical significance.pptx
erythropoiesis-I_mechanism& clinical significance.pptxerythropoiesis-I_mechanism& clinical significance.pptx
erythropoiesis-I_mechanism& clinical significance.pptx
muralinath2
 
Orion Air Quality Monitoring Systems - CWS
Orion Air Quality Monitoring Systems - CWSOrion Air Quality Monitoring Systems - CWS
Orion Air Quality Monitoring Systems - CWS
Columbia Weather Systems
 
Citrus Greening Disease and its Management
Citrus Greening Disease and its ManagementCitrus Greening Disease and its Management
Citrus Greening Disease and its Management
subedisuryaofficial
 
platelets_clotting_biogenesis.clot retractionpptx
platelets_clotting_biogenesis.clot retractionpptxplatelets_clotting_biogenesis.clot retractionpptx
platelets_clotting_biogenesis.clot retractionpptx
muralinath2
 
Structural Classification Of Protein (SCOP)
Structural Classification Of Protein  (SCOP)Structural Classification Of Protein  (SCOP)
Structural Classification Of Protein (SCOP)
aishnasrivastava
 
Predicting property prices with machine learning algorithms.pdf
Predicting property prices with machine learning algorithms.pdfPredicting property prices with machine learning algorithms.pdf
Predicting property prices with machine learning algorithms.pdf
binhminhvu04
 
NuGOweek 2024 Ghent - programme - final version
NuGOweek 2024 Ghent - programme - final versionNuGOweek 2024 Ghent - programme - final version
NuGOweek 2024 Ghent - programme - final version
pablovgd
 
Cancer cell metabolism: special Reference to Lactate Pathway
Cancer cell metabolism: special Reference to Lactate PathwayCancer cell metabolism: special Reference to Lactate Pathway
Cancer cell metabolism: special Reference to Lactate Pathway
AADYARAJPANDEY1
 
Penicillin...........................pptx
Penicillin...........................pptxPenicillin...........................pptx
Penicillin...........................pptx
Cherry
 
Multi-source connectivity as the driver of solar wind variability in the heli...
Multi-source connectivity as the driver of solar wind variability in the heli...Multi-source connectivity as the driver of solar wind variability in the heli...
Multi-source connectivity as the driver of solar wind variability in the heli...
Sérgio Sacani
 
insect taxonomy importance systematics and classification
insect taxonomy importance systematics and classificationinsect taxonomy importance systematics and classification
insect taxonomy importance systematics and classification
anitaento25
 
Richard's entangled aventures in wonderland
Richard's entangled aventures in wonderlandRichard's entangled aventures in wonderland
Richard's entangled aventures in wonderland
Richard Gill
 
Viksit bharat till 2047 India@2047.pptx
Viksit bharat till 2047  India@2047.pptxViksit bharat till 2047  India@2047.pptx
Viksit bharat till 2047 India@2047.pptx
rakeshsharma20142015
 

Recently uploaded (20)

GBSN- Microbiology (Lab 3) Gram Staining
GBSN- Microbiology (Lab 3) Gram StainingGBSN- Microbiology (Lab 3) Gram Staining
GBSN- Microbiology (Lab 3) Gram Staining
 
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
 
SCHIZOPHRENIA Disorder/ Brain Disorder.pdf
SCHIZOPHRENIA Disorder/ Brain Disorder.pdfSCHIZOPHRENIA Disorder/ Brain Disorder.pdf
SCHIZOPHRENIA Disorder/ Brain Disorder.pdf
 
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
 
platelets- lifespan -Clot retraction-disorders.pptx
platelets- lifespan -Clot retraction-disorders.pptxplatelets- lifespan -Clot retraction-disorders.pptx
platelets- lifespan -Clot retraction-disorders.pptx
 
RNA INTERFERENCE: UNRAVELING GENETIC SILENCING
RNA INTERFERENCE: UNRAVELING GENETIC SILENCINGRNA INTERFERENCE: UNRAVELING GENETIC SILENCING
RNA INTERFERENCE: UNRAVELING GENETIC SILENCING
 
Hemostasis_importance& clinical significance.pptx
Hemostasis_importance& clinical significance.pptxHemostasis_importance& clinical significance.pptx
Hemostasis_importance& clinical significance.pptx
 
erythropoiesis-I_mechanism& clinical significance.pptx
erythropoiesis-I_mechanism& clinical significance.pptxerythropoiesis-I_mechanism& clinical significance.pptx
erythropoiesis-I_mechanism& clinical significance.pptx
 
Orion Air Quality Monitoring Systems - CWS
Orion Air Quality Monitoring Systems - CWSOrion Air Quality Monitoring Systems - CWS
Orion Air Quality Monitoring Systems - CWS
 
Citrus Greening Disease and its Management
Citrus Greening Disease and its ManagementCitrus Greening Disease and its Management
Citrus Greening Disease and its Management
 
platelets_clotting_biogenesis.clot retractionpptx
platelets_clotting_biogenesis.clot retractionpptxplatelets_clotting_biogenesis.clot retractionpptx
platelets_clotting_biogenesis.clot retractionpptx
 
Structural Classification Of Protein (SCOP)
Structural Classification Of Protein  (SCOP)Structural Classification Of Protein  (SCOP)
Structural Classification Of Protein (SCOP)
 
Predicting property prices with machine learning algorithms.pdf
Predicting property prices with machine learning algorithms.pdfPredicting property prices with machine learning algorithms.pdf
Predicting property prices with machine learning algorithms.pdf
 
NuGOweek 2024 Ghent - programme - final version
NuGOweek 2024 Ghent - programme - final versionNuGOweek 2024 Ghent - programme - final version
NuGOweek 2024 Ghent - programme - final version
 
Cancer cell metabolism: special Reference to Lactate Pathway
Cancer cell metabolism: special Reference to Lactate PathwayCancer cell metabolism: special Reference to Lactate Pathway
Cancer cell metabolism: special Reference to Lactate Pathway
 
Penicillin...........................pptx
Penicillin...........................pptxPenicillin...........................pptx
Penicillin...........................pptx
 
Multi-source connectivity as the driver of solar wind variability in the heli...
Multi-source connectivity as the driver of solar wind variability in the heli...Multi-source connectivity as the driver of solar wind variability in the heli...
Multi-source connectivity as the driver of solar wind variability in the heli...
 
insect taxonomy importance systematics and classification
insect taxonomy importance systematics and classificationinsect taxonomy importance systematics and classification
insect taxonomy importance systematics and classification
 
Richard's entangled aventures in wonderland
Richard's entangled aventures in wonderlandRichard's entangled aventures in wonderland
Richard's entangled aventures in wonderland
 
Viksit bharat till 2047 India@2047.pptx
Viksit bharat till 2047  India@2047.pptxViksit bharat till 2047  India@2047.pptx
Viksit bharat till 2047 India@2047.pptx
 

Java ppt

  • 1.
  • 2. Defination:  servlet is a java class that extends the functionality of web server. Eg:  mail server servlet is a class that performs virus scan to attached files
  • 3. Benefits  only one copy of servlet is loaded into jvm.  each request begins a new thread to servlet process. ◙ save time ◙ response time increases ◙ it is scalable
  • 4.
  • 5.
  • 6. Servlet implementation:  servlet use class and interface from 2 package ◘ javax.servlet  It contains classes to support generic protocol ◘ javax.servlet.http  It extends classes in servlet package to add HTTP sapecific functionality.
  • 7.
  • 8.
  • 9. Servlet API : o Servlet interface o Genericservlet class o HTTPservletrequest interface o HTTPservletrequest interface o Cookie class o HTTPsession interrface o single threadmodel interface o servletexception class o unavailableexception class o servlettcontext interfave o serrvletconfig interrface
  • 10. Servlet interface:  Every servlet must implements the javax.servlet interface  It can implement in 2 ways: ◙ Directly implementing interface ◙ Extending any of 2 classes: ◙ javax.serrvlet.genricservlet ◙ javax.servlet.http.HTTPservlet
  • 11. Methods: ◘ Init() ◘ Service() ◘ Destroy() ◘ Getservletinfo() ◘ Getservletconfig()
  • 12. Service() syntax:  public abstract voidservice(servletrequest req, servletresponse res)throws servletException,IOException ◙ it is called whenever the request is made ◙it must be overridden in servlet ◙ it receives request via servletrequest and sends response via servlet response
  • 13. HTTP servlet  It is an abstract class that is used for developing HTTpservlets.  It dose not override the service() method.  It override doget() to handle GET requests and dopost()to handle POST requests
  • 14.
  • 15. Methods: o serrvice() o doget() o dopost() o dodelete() o dooption() o do put() o do trace()
  • 16. do get() or do post() o protected void doget(HTTPServletRequest req HTTPServletResponse res)throws servletException,IOException o protected void dopost(HTTP ServletRequest req,HTTPservletresponse res) throws servletException,IOException
  • 17. public class SessionServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { res.setContentType("text/html"); OutputStream out = res.getOutputStream(); PrintWriter pw = new PrintWriter(new OutputStreamWriter(out)); HttpSession session = req.getSession(false); if (session == null) { session=req.getSession(true); session.putValue ("VisitCount", "1"); } pw.println("<html><body><pre>"); pw.println("session.isNew()="+session.isNew()); pw.println("session.getCreationTime()="+ new java.util.Date( session.getCreationTime())); pw.println("session.getID()="+session.getId()); pw.println("session.getLastAccessedTime()=" + new java.util.Date(session.getLastAccessedTime())); String strCount = (String) session.getValue("VisitCount"); pw.println("No. of times visited = " + strCount); int count = Integer.parseInt(strCount); count++; session.putValue("VisitCount", Integer.toString(count)); pw.println ("</pre></body></html>"); pw.flush(); } }