Vous êtes sur la page 1sur 3

SERVLET:

servlet technology is used to create web applications. before servlet cgi is the
technology execute at server site.
WHAT IS SERVLET?
servlet is the part of JEEAPI.it contains many interfaces and classes.servlets can
be used to capture dat from html and process to the database.servlet is a web
component that is deployed on a sever to create a dynamic web page.
CGI(common gateway interface):
cgi is the oldest tech to capture the data from html.whenever client sends a
request the web server to call the external program and pass to the http request
and is not a thread safe.
DISADVANTAGES OF CGI:
if no.of clients increases it takes more time to respond.for each request it start
a processand the web server is limited to the start process.it uses platform
dependent languages ex:c,c++....
ADVANTAGES OF SERVLETS:
by using servlets we can provide thread safe.it takes less time to generate the
response when compared to the CGI.it is a secure bcoz it uses java language and
roboust .
SERVLET OR JEE API:
in servlet api consits of two packages 1.javax.servlet2.javax.servlet.http package.
1.javax.servlet:in this package contains so many interfaces and packages.
Interfaces:servlet is a interface
servlet request
servlet response
request dispatcher
servlet confing
servlet context
single thread model
filter
classes in javax.servlet package:
1.generic servlet
2.servlet input stream
3.servlet output stream
4.servlet request wrapper
5.servlet response wrapper
6.servlet request event.
javax.servlet.http package:this servlet package contains interfaces and packages.
interfaces:
http servlet request
http servlet response
http session
http session listner
hhtp context
hhtp session context.
classes:
1.http servlet
2.cookies
3.http session event
4.http servlet request wrapper
5.http servlet rquest wrapper
DEVELOPING A SERVLET CLASS:
to create a servlet class there are three ways:1.servlet interface2.generic
servlet3.http servlet.
1.SERVLET INTERFACE;
developing a servlet application means implementing the servlet interface either
directly or indirectly
in servlet interface consits of 5 methods:
1.public void init(servlet config)
2.public void services(servletRequest request,servletResonse response)
3.public void destroy()
4.public servlet config get servlet config()
5.public string getServletinfo()
INIT METHOD:
the init method is similar to the constructor only one time it will execute
whenever client sends the first req.
SERVICE METHOD:
it is similsr to the main method .
every time it will execute whwnwver client sends areq.
DESTROY METHOD:
whenever server stops or undeploy the application frm the server then the destry
function will execute.it is similar to destructor
the purpose o fdestroy method is to release memeory,cleaning activity and so on..
GETSERVLET CONFIG(getServlet config):
it is used to give additional information to servlet object
the purpose of service nmetghod is to execute business logic or main logic
GETSERVLET INFO(getServlet info):
it is similar to the getservlet config.
CREATING DYNAMIC WEB PROJECT INECLIPSE:
1.goto file->new->goto others
2.search for dynamic web project and click on next.
3.write the project name and change the dynamic web module version as 2.5 and click
on finish.
4.create a servlet inside the java resources inside src
5.right click on src and select servlets
6.write servlet name ->next
uncheck the do get&ddeposit &cick on finish.

installing tomcat server :


download server and install it.
configure the tomcat server into eclipse.
to configure click on server and select the appropriate server version and click on
next
give the path of tomcat server upto tomcat 7.1 folder but not bin.
clicvk on ok and finish
after configuring server change the port numbers.
for changing port numbers double click on server and move to the right hand side
change the port num.
to avoid errors servers in servlet we have to add jar files of the tomcat server.
ADDING EXTERNAL LIBRARIES:
right click on project select the build path and click on configure build path.
click on libraries and select the add ext jars
add the jar files and click on ok.
LIFECYCLE OF A SERVLET:
in life cycle there are five stages
servlet class is loaded.
servlet instance is created.Drawback of generic servlets:
init method is invoked.
service method is invoked.
destroy method is invoked.
the class loader is responsible to load servlet class whenever first request comes
before
this servlet class is loaded and pass to the second stage andinstance is created.
after class is loaded the web container creates the srevlet object only
once.whenever first request comes.
INIT METHOD:
after object is created the web contAINER CALLS INIT METHOD.after executing init
method the web container calls the service method each time whenever requestfor
servlet is recieved.
if servlet is not initialized then it will follows fiorst three steps.
if servlet is initialized it cals service method and the program wil execute.
DESTROY:
the web container calls destroy method whenever server stops or undeploy
application from server.
GENERIC SERVLETS:
it is the implementation class of servlet interface and this class is belongs to
javax.servlet package.
generic servlet class can handle any type of request.so ti is protocol independent.
in generic servlets consists of five methods +additional two
methods----------------------------
In generic servlet no need to implement the all five methods except srevice method.
Drawbacks of generic servlet:
Every time we have to implement service method-----------------------------------
HTTP SERVLET:
this http is available in javax.servlet.http package
it contains five methods i.e, doget,dopost,dohead,-----------------356dotrace.
String uname=request.getParameter("uname");
SERVLET CONFIG:
whenever client sends the frst request to the server the server will look into .xml
file and find out the servlet that has to be executed or not.
whenever servlet object is created then server takes memory and it will add the
information to obj.
whenever the servlet is destroyed the servlet config object is also removed from
the server.
server contain multiple applications and for every application they has multiple
contents.every servlet will have own servletconfig object.
the purpose of servlet config is to provide some intialization to the servlet.
the data available in servletConfig object is not useful for the another servlets
->To provide additional information to the servlet we have to use xmlinit paran
tag<init param>

Vous aimerez peut-être aussi