♠ Posted by Unknown in Adv Java at 07:05
Servlets
Client access from the Internet or
corporate intranets is a sure way to allow many users to access data and
resources easily. This type of access is based on clients using the World Wide
Web standards of Hypertext Markup Language (HTML) and Hyper Text Transfer
Protocol (HTTP). The Servlet API set abstracts a common solution framework for
responding to HTTP requests.
Servlet provide an excellent solution for
server-side programming support, they are one of the most popular reasons for
moving to Java. Not only do they provide a framework that replaces CGI
programming (and eliminates a number of thorny CGI problems), but all your code
has the platform portability gained from using Java, and you have access to all
the Java API (except, of course, the ones that produce GUIs, like swing).
The architecture of the servlet API is
that of a classic service provider with a service() method through which all
client requests will be sent by the servlet container software, and life cycle
methods init() and destroy() which are called only when the servlet is loaded
and unloaded (this happens rarely).
Servlet Life Cycle
The Servlet interface methods relevant to
the servlet lifecycle are init(), service(), and destroy(). The life cycle
starts with the container calling the init() method, and ends with the
container calling the destroy() method.
The lifecycle of a servlet consists of
the following fundamental stages:
- Instantiation :- the web container creates an instance of the servlet
- Initialization :- The container calls the instance’s init{} method.
- Service :- If the container has a request for the servlet, it calls the servlets instance’s service() method.
- Destroy :- Before destroying the instance, the container calls the servlet instance’s detroy() method.
- Unavailable :- The instance is destroyed and marked for garbage collection.
0 comments:
Post a Comment