Posts

Commonly used method of ServletResponse interface

Image
1- setContentType():                               Is used to specify MIME type of response. Content type is also known as MIME (Multipurpose internet mail extension) type. It is a HTTP header that provides the description about what are you sending to the browser. public void setContentType(String MIMEType); MIME type has 2 part: Major part represent type of content and miner part specify the format of content. Commonly used MIME types (content types) are: text/html      image/gif audio/mp3 application/pdf text/xml image/jpg audio/wav application/msword text/plain image/bmp application/vnd.ms-excel application/jar                 ...

Difference between Parameter and Attribute

Image
1- Parameter represents data which is received as part of request and store in ServletRequest object by the Server . Attributes represent information which is stored in the ServletRequest object by Servlet to share it with another servlet participate in the processing of same request . 2- Parameters are read only that is Servlet can not modify them . Attribute are stored, read, remove and replaced by the Servlet. 3- Parameters represent data in String form whereas Attributes represents data in object form. Note: Attributes are required only if multiple Servlet participate in the processing of request. Real life example: Waking for interview- Let there be two Servlet s1 and s2. Both of the Servlets participates in the processing of a request. Servlet s1 does initial processing and shares its result with s2 which sends final response. 1.1- ServletRequest object is created and request data is stored as a parameter. 1.2- ServletRespons...

Commonly used method of ServletRequest interface

1- getParameter():                               Is used to obtain the value of request parameter.     public String getParameter(String pName); 2- getParameterNames():                                                           Is used to find out names of request parameters.     public Enumeration getParameterNames(); 3- setAttribute():                                 Is us...

Implementation of HttpServlet class

Image
public abstract class HttpServlet extends GenericServlet {    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException;    {                         HttpServletRequest req=(HttpServletRequest)request;                    HttpServletResponse res=(HttpServletResponse)response;                 service(req,res);    } protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException;  {             // Request type is checked and doGet() and doPost() method are invoked.      ...

Difference between HTTP get and post request

1- Conventionally,  get request is used for static contents and post request is used for dynamic contents. 2- Technically , In case of get request, requested data send as part of packet header whereas in case of post request, request data is send as a part of packet body. The size of HTTP packet header is fixed hence only limited amount of data can be send as a part of get request. Size of HTTP packet body can be unlimited hence, unlimited amount of data can be send as a part of post request. post request use in case of : 1- audio/ video uploading 2- Large amount of data sending 3- In case of get request, request data is appended to the URL as parameter. URL is visible in the address bar hence request data is displayed in the address bar. In case of post request, request data is not appended to the URL, hence it is not visible in the address bar. 4- In case of get request, request data transmitted over the network as submitted by the user wher...

How to create servlet?

Image
In order to define a Servlet, implementation of Servlet interface is need to be provided. This Implementation can be provided in 2 ways: 1- Direct 2- Indirect 1- Direct 2- Indirect In order to facilitate indirect implementation of Servlet interface, SUN Microsystems provide a helper class named javax.servlet.GenericServlet . It is an abstract class which implements Servlet interface and defines all its method except service (). Both approaches are not usually used because it has following limitations: Servlet interface and its implementation in GenericServlet class are protocol independent in web application. Some protocol (HTTP, HTTPS) used by the client to interact with the web server. Each of these protocols supports different types of request. Most commonly used protocol is HTTP which supports following 8 types of request. Types of HTTP request: 1-   get 2-   post 3-   put 4-   delete 5-   head 6-   ...

What is Servlet?

Image
Servlet term is used in 2 different contexts with 2 different meaning. In the broader context, it represents technology provided by SUN Microsystems for developing web application in java. It is web component that is deployed on the server to create dynamic web pages. In the narrow context, it represent a class for web application component that is created using the technology and that is responsible for processing request on a web server. Before Servlet web application were developed using CGI (Common Getaway Interface). CGI was a protocol that specifies how an application program communicates with the web server in standard manner. In CGI based web application program were written C, C++, Perl. These program uses to follow CGI protocol for interaction with web server. CGI based application had following problems: 1-    CGI scripts were platform dependent. Execution of CGI script was process based. Process based execution limits scalability due to limited h...