Tuesday, August 6, 2013

GenericServlet

GenericServlet

Implementation of the ‘Servlet’ interface need to be provided by the all servlets.
To facilitate indirect implementation of ‘Servlet’ interface is helper class named javax.servlet.GenericServlet is provided by the ‘sun microsystem’. Details an abstract class which implements servlet interface and defines all it’s methods except service() method. It is used as a super class by the user define servlets.

public class UserServlet extends GenericServlet
{
                        //Service() method is defined
}

Servlet interface and its implementation class GenericServlet provides a generic model (protocol independent) of request processing.

Monday, August 5, 2013

Servlet


Servlet


Servlet is an API provided by 'sun microsystem' to facilitate development of dynamic web applications.
The term 'servlet ' is used in two different context; in the broader context it represent an API and in the narrow context it represents an interface define using the API.
Javax.servlet  package added some packages contents classes and interfaces of servlet API, at the core of the  servlet API is an interface named ‘Servlet’ (javax.servlet.Servlet) this interface provides lifecycle methods of a servlet.
Lifecycle methods of Servlet :-
1.       init():- This method is invoke only ones just after a servlet object is created. It is used by the application developers to perform initialization
public void init(ServletConfig config) throws ServletException;
It is used by the server to provide the reference of the ServletConfig object to the servlet.
ServletConfig is an interface of servlet API implementation of it is provided by vendors.

2.       Service():- This method is invoke each time a request for the servlet is receive. It is used by the servlet  to process request and generate the html contents.
public void service(ServletRequest request, ServletResponse response)throws ServletException, IOException;
In this method references of objects of type Servletrequest and ServletResponse are provided by the server these objects act as interface between the server and the servlet that is server provides request data to  the servlet through ServletRequest object and server receives response from the servlet object through ServletResponse object.

3.       destroy():- This method is invoke only onse just before the servlet is unloaded . It is used to perform cleanup operations
public void destroy();

Non Lifecycle methods of Servlet Interface:-
1.       getServletConfig():- This method is used to obtain the reference of ‘ServletConfig’ object of a servlet.
public ServletConfig getServletConfig();
2.       getServletInfo():- This method is used to obtain the description of the servlet.
public String getServletInfo();
Note: Total five methods are available in Servlet interface – three are lifecycle and two are non lifecycle methods.

                                                                                                                                                  

Sunday, August 4, 2013

Creating java program in netbeans

Creating java program in netbeans: step by step 
11.      Click on the file menu.
22.      Click on the new project sub menu.

33.      Select java from left menu.
44.      Then select java application from right menu.
55.      Click next button.


66.      Type the project name into the highlighted text box.
77.      Click on finish button.

88.      You will see the window like this.

99.      Type here this code.

110.  Run the program by clicking on run button.
111.  And see your result bellow.