Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

J2EE Architecture and Servlets:

Tags: servlet
Servlet:

Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet may be responsible for taking data in an HTML order-entry form and applying the business logic used to update a company's order database

Servlets are to servers; applets are to browsers

Servlets provide a way to generate dynamic documents that is both easier to write and faster to run. It is efficient, convenient, powerful, portable, secure and inexpensive. Servlets also address the problem of doing server-side programming with platform-specific APIs: they are developed with Java Servlet API, a standard Java extension.

Servlet Interface

The central abstraction in the Servlet API is the Servlet interface. All servlets implement this interface, either directly or, more commonly, by extending a class that implements it such as HttpServlet.

Servlets-->Generic Servlet-->HttpServlet-->MyServlet. 

The Servlet interface declares, but does not implement, methods that manage the servlet and its communications with clients.

When a servlet accepts a call from a client, it receives two objects. They are:

ServeltRequest: this encapsulates the communication from the client to the server

ServletResponse: This encapsulates the communication from the servlet back to the client.

ServletRequest and ServletResponse are interfaces defined by the javax.servlet package.

The javax.servlet.Servlet interface defines the three methods known as life-cycle method.


public void init(ServletConfig config) throws ServletException


public void service( ServletRequest req, ServletResponse res) throws ServletException, IOException


public void destroy()


First the servlet is constructed, then initialized with the
init() method.
Any request from client are handled initially by the
service() method before delegating to the doXxx() methods in the case of HttpServlet.

An HTTP Servlet handles client requests through its service method. The service method supports standard HTTP client requests by dispatching each request to a method designed to handle that request.

The servlet is removed from service, destroyed with the
destroy() method then garbage collected and finalized.



This post first appeared on Web Applications Development | Custom Web Applicat, please read the originial post: here

Share the post

J2EE Architecture and Servlets:

×

Subscribe to Web Applications Development | Custom Web Applicat

Get updates delivered right to your inbox!

Thank you for your subscription

×