Beruflich Dokumente
Kultur Dokumente
JOSHI
SERVLET
SERVLET
Servlets are Java platform technology of choice for
extending and enhancing Web servers .
•component-based
•server- independent
•platform-independent
•protocol-independent
•fast and efficient
•most secured
SERVLET
• Servlets are used for building Web-based
applications, without the performance
limitations of CGI programs.
• Servlets have access to the entire family
of Java APIs, including the JDBC API to
access enterprise databases.
• Servlets can also access a library of
HTTP-specific calls and receive all the
benefits of the mature Java language,
including portability, performance,
reusability, etc.
SERVLET
Request WEB
SERVER
CLEINT Servlet Name
+ parameters
JVM
Response DATA
SERVLET BASE
SERVLET
•JVM loads the servlet on the request from
client if servlet is not loaded.
•Heavily used servlets has to be loaded on
starting of web server to avoid loading and
creating instance on every client request.
•On every client request a service method is
called by creating it as separate thread in JVM,
i.e. every client request has a thread created.
•Unloading of servlet depends on vender
specification i.e., unloads after response or if
no response for a specific amount of time etc.
Life Cycle of SERVLET
CLASS INSTANCE
INIT
DESTROY
SERVLET API
Servlet is an API which is provided as servlet.jar
Servlet is an interface of package javax.servlet
javax.servlet.Servlet
javax.servlet.GenericServlet
ServletOutputStream sos=res.getOutputStream();
To create OutputStream to send response
image/gif
image/jpg
image/bmp
Parameters
Enumeration e = req.getParameterNames()
To get the parameter names sent with the request
String[] s = req.getPrameterValues(String)
To get the parameter values of given parameter name
Servlet to Servlet Communication
res.sendRedirect( req.encodeDirectURL(
“URL?QueryString”));
Example:
res.sendRedirect( req.encodeDirectURL(
“http://server:8080/servlet/color”));
res.sendRedirect( req.encodeDirectURL(
“http://server:8080/color.html”));