Tuesday, May 30, 2006

SCWCD (Sun Certified Web Component Developer) notes

HTTP methods

GET, POST, PUT, and HEAD.

GET method
The GET method is used to retrieve a resource (like an image or an HTML page)
from the server, which is specified in the request URL. When the user types the
request URL into the browser's location field or clicks on a hyperlink, the GET
method is triggered.

Even if no method attribute is specified, the browser uses the GET method by default.


The other restrictions for the GET method are that it can pass only text
data and not more than 255 characters.

POST method

The purpose of the POST method is to "post" or send information to the server. It is possible to send an unlimited amount of data as part of a POST request, and the type of data can be binary or text.

The method attribute of the
tag can be specified as " POST " to cause the browser to send a POST request to the server.

PUT method
The PUT method adds a resource to the server and is mainly used for publishing
pages. It is similar to a POST request, because both are directed at server-side
resources.

HEAD method
The HEAD method is used to retrieve the headers of a particular resource on the
server. You would typically use HEAD for getting the last modified time or content
type of a resource. It can save bandwidth because the meta-information about the resource is obtained without transferring the resource itself.

Request handling methods in HttpServlet

When an HTTP request from a client is delegated to a servlet, the service()
method of the HttpServlet class is invoked.



Life cycle

Loading and instantiation

For each servlet defined in the deployment descriptor of the Web application, the
servlet container locates and loads a class of the type of the servlet. This can
happen when the servlet engine itself is started, or later when a client request is
actually delegated to the servlet.

Initialization

After instantiation, the container initializes a servlet before it is ready to handle client requests. The container initializes the servlet by invoking its init() method, passing an object implementing the ServletConfig interface. In the init() method, the servlet can read configuration parameters from the deployment descriptor or perform any other one-time activities, so the init() method is invoked once and only once by the servlet container.

Request handling

After the servlet is initialized, the container may keep it ready for handling client
requests. When client requests arrive, they are delegated to the servlet through the service() method, passing the request and response objects as parameters.

Removal from service

A servlet container may decide to remove a servlet from service for various reasons, such as to conserve memory resources. To do this, the servlet container calls the destroy() method on the servlet.




Retrieving request parameters and headers

public String getParameter(String name);
public java.lang.String[] getParameterValues(String name);
public java.util.Enumeration getParameterNames();


Retrieving request headers

public String getHeader(String name);
public java.util.Enumeration getHeaders(String name);
public java.util.Enumeration getHeaderNames();

Retrieving initialization parameters

public String getInitParameter(String name);
public java.util.Enumeration getInitParameterNames();

0 Comments:

Post a Comment

<< Home