Académique Documents
Professionnel Documents
Culture Documents
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.