Escolar Documentos
Profissional Documentos
Cultura Documentos
13.1 Servlets
“SERVLETS ARE JAVA PROGRAMS THAT CAN BE DEPLOYED ON JAVA
ENABLED WEB SERVER TO ENHANCE AND EXTEND THE FUNCTIONALITY
OF THE WEB SERVER.”
Java Servlets are server side components that provides a powerful mechanism
for developing server side of web application. Earlier CGI was developed to
provide server side capabilities to the web application. Although CGI played a
major role in the explosion of the Internet, its performance, scalability and
reusability issues make it less than optimal solutions. Java Servlets changes all
that. These provide excellent framework for server side processing.
Servlets are not designed for a specific protocols. It is different thing that they
are most commonly used with the HTTP protocols.
Provide dynamic content like getting the results of a database query and
returning to the client.
Process and/or store the data submitted by the HTML.
Manage information about the state of a stateless HTTP. For example, an
online shopping car manages request for multiple concurrent customers.
Servlets are Efficient. The initialization code for servlet is executed only
when the servlet is executed for the first time. Subsequently, the requests
that are received by the servlets are processed by its service() method.
This helps to increase the efficiency of the server by avoiding creation of
unnecessary processes.
Servlets are Robust. As servlets are based on Java, they provide all the
powerful features of Java, such as exception handling, and garbage
collection, which makes them robust.
Servlets are Portable. Servlets are portable because they are developed
in Java. This enables easy portability across web servers.
Servlets are Persistent. Servlets helps to increase the performance of
the system by preventing frequent disk access.
Applets Servlets
Applets are Java programs that As Servlets executed on the web
are embedded in Web pages. server, they help overcome
When a web page containing problems with download time
an applet is opened the byte faced while using applets.
code of the applet is Servlets do not require the
downloaded to the client browser to be Java enabled
computer. This process unlike applets because they
becomes time consuming if execute on web server and
the size of applet is too large. the results are sent back to
the client or browser.
Servlets
After the servlet is initialized it starts accepting requests from the client and
processes them through the service() method till it shutdown by the destroy()
method.
Init( )
Request
Service(
Client )
(Browser)
Response
Destroy(
)
Lifecycle of Servlet
The Java 2 Servlet Development Kit (J2SDK), Enterprise Edition (J2EE) server is
a product from Sun Microsystems that is based on the J2EE.
Servlets
The J2EE server is used to deploy servlets and JSP files and enables users to
access the same by implementing appropriate security.
JWS is a web server from Sun Microsystems that is developed based on the
servlet technology and can be used to deploy servlets.
JRun and apache can also be used to deploy servlets. JRun is a Java application
server which is a product of live software. JRun provides a high performance,
scalable solution for creating and delivering enterprise applications. The other
website technologies that can be deployed in JRun are Java Server Pages and
Enterprise Java Beans.
Apache is a web server from an organization called Apache that can be used to
deploy servlets. Few features of Apache that have made it popular are its freely
distributed code, robustness and security that is offered.
javax.servlet
javax.servlet.http
While the javax.servlet.http package contains the classes that are used when
developing HTTP-specific servlets. The HttpServlet is extended from
GenericServlet base class and it implements the Servlet interface. HttpServlet
class provides a framework for handling the HTTP requests.
The class that is used to create HTTP servlets is called HTTPServlet and is
derived from the GenericServlet class.
Servlet
Generic Servlet
MyServlet
GET/intro.html HTTP/1.0
This request uses the GET method to ask for the document named intro.html,
using HTTP version 1.0.
When a client connects to a server and makes an HTTP request, the request
can be of several different types called methods. The most frequently used
methods are GET and POST. The GET method is designed for getting
information (document, a chart or the results from a database query). While
the POST method is designed for posting information.
Servlets
Digital certificate allow web server, and clients to use advanced cryptographic
techniques to handle identification and encryption in a secure manner.