Sunday, September 15, 2013

Difference Between Get and Post


Difference between http Get and post request:-
Conventionaly get request is used for requesting static contents and post request is used for requesting dynamic contents.

Technical Dofference:-
11.     In case of get request, request data is sent as part of header. Size of http packet header is fixed hence only limited amount of data can be send as part of get request. In case of post request, request data is sent as part of body. Size of http packet body can be unlimited and unlimited amount of data can be send as part of post request.

22.      In case of get request, request data is displayed in the address bar of browser. Where as Incase of post request it is not displayed in the address bar.

33.      In case of get request, request data is transmited over the network has submited user. Where as In case of post request, request data is first incripted using the 32 bit data incription and then transmited the data on network.

44.      Get request is idempotent where as post is not.

javax.servlet.http package


Javax.servlet.http package provides http specific classes and Interfaces of servlet API. Commonaly used members of this package are:-
1.      HttpServletRequest:-  This Inetrface extends ServletRequest and adds http specific methods.
2.      HttpServletResponse:-  This Interface extends ServletResponse and adds http specific methods.
3.      HttpServlet:- It is a helper class with extends GenericServlet and provides methods for each http specific method is used super class.

doGet() and doPost() are two commonly used methods.
They are use to process http get and post process respectively.
public void doGet(HttpServletRequest request,HttpServletResponse response);
public void doPost(HttpServletRequest request,HttpServletResponse response);
public void doPut(HttpServletRequest request,HttpServletResponse response);
public void doDelete (HttpServletRequest request,HttpServletResponse response);
public void doHead (HttpServletRequest request,HttpServletResponse response);
public void doTrace(HttpServletRequest request,HttpServletResponse response);
public void doOptions(HttpServletRequest request,HttpServletResponse response);
public void doConnect(HttpServletRequest request,HttpServletResponse response);


Request passing by Http protocol


There are 8 types of request passing by the http protocol.

Http protocol is used to request content from the server. Http protocol support following types of request.

1.    Get
2.    Post
Note: Get and Post are used to request  contents from the server.

3.    Put
4.    Delete
5.    Haed
6.    Trace
7.    Options
8.    Connect
Note:  These are used for connection setup and management.

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.