تفاوت های بین متدهای doGet و doPost در Java Servlet

different between doGet and doPost() are as follows:
  1. doGet() method is a default method whereas doPost() explicitly
    should be mentioned
  2. doGet execute in 3 situation: 1-when end user clicks submit button 2-when
    end user provides URL 3-when end user clicks on the hyperlink
  3. but doPost used only when we click on submit method.
  4. doGet is not secure but doPost is most secure.
  5. doGet method is used to get the data from the server whereas doPost is used
    to post the data to the server.
  6. User name and password and secure data should not be sent by doGet().
    under doPost() we can send it.
  7. with doGet method we can send  255 - 260 KB data whereas doPost is unlimited
  8. doGet() is more faster than doPost().

در مورد Servlet Context در جاوا

  1. ServletContext is an interface present in java API. the job is to communicate with servlet container.
  2. the servlet context interface contents some methods that can be used to communicate with servlet container.
  3. as it is an interface we can not create the object directly using new keyboard but the servlet engine already crated the object and we can get this object using the getServletContextMethod()  as sample: ServletContext sc = getServletContext(); although we can call getServeletContext method directly but this method will be called on servlet config object. only one servlet context object will be available per web application.
  4. methods present in servlet context: 1-getAttribute(String name) and return type of this method is object and input argument is string and the job is to retrieve data from servlet container with described name. 2-setAttribute() it takes 2 argument one is String and another is the object. the job is to store the Object in Servlet  Container by providing a name. 3-getRequestDispature(String path): it will return the object of request dispature interface on that path.

Life Cycle of Protocol Independent Servlet

    1. The life cycle protocol independent servelet follows 4 different steps: 1-instanciation 2-intialization 3-service 4-destroy
    2. Instanciation: servelet engine first loads the servlet class. then creates the instance. this happens only once per servlet when a new user communicate with the servlet.
    3. Initialization: although servlet object has been created, but it is not capable of handling the request. to make able to handle, servlet engine creates the object of servlet config. the init method takes this argument and initialises the servlet. These steps happen only once, where client communicates with the servlet for the first time. it is once for each client.
    4. services: in this ways the servlet engine creates the objects of "HttpServeletRequest" and "HttpRequestResponse" by passing this 2 objects servlet engine calls public service method. the job of public service method is to call protected service method by passing the same argument.(httpservlet request and httpRequestresponse) the protected servlet method calls doget  and doPost method with request and response object. doGet and doPost method eligible to provide the service by executing the content. after executing these steps servlet will wait for the new request. if end user gives a new request the service step will repeated again. if not sending a new request the servlet engine will be wait for a new request.
    5. Destroy:when end user tries to close the communication then Destroy method will execute and deletes the instance.

تفاوت بینProtocol Independent ServletوProtocol Dependent Servlet

what is difference between protocol dependent and independent servlet?
  1. protocol dependent  is eligible to execute on http protocol but protocol independent can execute on any protocol but sun suggest only for http.
  2. protocol independent extends GenericServlet.
  3. protocol dependent extends HttpSevlet.
  4. if it is dependent it will override doGet() and doPost()  method.
  5. if it is independe it should override Init(), service() and  destroy()
  6. protocol dependent  imports java.servlet.http


Protocole Independent Servlet

  1. Protocol independent servlet: protocol independent servlet can execute on any protocol.
  2. we find servlet as protocol independent servlet if extends GenericServletClass and overrides 3 different methods as 1-public void init()  2-public void service(ServletRequest req , ServeletResponse Res) 3-public void destroy
  3. the GenericServletClass belongs to javax.Servlet package and that implements the servlet and servlet config Interface.
  4. public void init() :this method overrides this public void init(ServeletConfig config); this method executes only once per servlet and says to container that servlet is ready to get any request.
  5. public void service(): the service method executes whenever end user sends a request. and it returns the response to the end user after execution. this method executes n number of time on a particular servlet.
  6. destroy method: when ever no more service is required from the end user, destroy method executes.