♠ Posted by Unknown in Adv Java at 07:50
Useful Methods of Servlet
Servlets are simply Java classes that follow
three basic rules:
- An
HTTP Servlet must extend javax.servlet.http.HttpServlet (or extend an
abstract class that does).
- The
Servlet must implement at least one of the following metheods: doGet(),
doPost(), doPut(), doDelete(), init(), destroy(), or service().
- The Servlet can optionally implement init(), destroy(), or getServletInfo().
service() :-
All HTTP network requests have several
“methods” of invocation that indicate the intent of the request, such as GET,
POST, PUT and DELETE. In practice, only GET and POST methods are used. When a
Servlet container first routes to a Servlet, it invokes the service() method.
By default, the service() methods will dispatch to doGet(), doPost(), or
doDelete() based on the method information given in HTTP request header. You
can override this default service() implementation to respond to all HTTP
requests in an identical way, although you would usually just override doGet()
or doPost().
doGet() :-
The GET method is the most common form of
HTTP request. The doGet() method receives an HttpServletRequest and an
HttpServletResponse object. And must throws java.io.IOException and
ServletException.
doPost() :-
HTTP employs the POST method to transfer
large amounts of HTML form data. The doPost() method is called much like
doGet().The doPost() method receives an HttpServletRequest and an
HttpServletResponse object. And must throws java.io.IOException and
ServletException. If the Servlet’s service() method receives an HTTP POST
request, the Servlet’s doPost() method is called. The input parameters are
identical to doGet(). The doPost() method is sometimes chained to doGet().
init() and destroy() :-
The init() and destroy() methods identify
the beginning and end of the Servlet Life Cycle. The init() method is called
when a Servlet is being placed into service by the container, and the
destroy() method is called when the
container takes the Servlet out of service. These methods are most often used
to initialize and release resources, or to provide other life cycle-sensitive
support functions.
0 comments:
Post a Comment