1 / 9

Servlet Life Cycle

Greens Technologies is a leading provider of Java Training in Chennai. Excellent syllabus with Assured Job Placements and Sun Certified Developer for the Java 2 Platform certification. We provide Java Training in Chennai with Placement in leading companies.<br><br>

Apsara
Download Presentation

Servlet Life Cycle

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Servlet Life Cycle

  2. Java Servlet life cycle consists of a series of events that begins when the Servlet container loads Servlet, and ends when the container is closed down Servlet. A servlet container is the part of a web server or an application server that controls a Servlet by managing its life cycle. • A servlet life cycle can be defined as the entire process from its creation till the destruction. The following are the paths followed by a servlet. • The servlet is initialized by calling the init() method. • The servlet calls service() method to process a client's request. • The servlet is terminated by calling the destroy() method. • Finally, servlet is garbage collected by the garbage collector of the JVM. • Learn Professional Java Training in Chennai @ Greens Technologys.

  3. The init() Method • The init technique is called just once. It is called just when the servlet is made, and not required any client asks for thereafter. In this way, it is utilized for one-time instatements, similarly as with the init strategy for applets. • The servlet is typically made when a client initially conjures a URL comparing to the servlet, yet you can likewise indicate that the servlet be stacked when the server is first begun. • At the point when a user invokes a servlet, a solitary example of each servlet gets made, with every client ask for bringing about another string that is given off to doGet or doPost as proper. The init() technique just makes or loads a few information that will be utilized for the duration of the life of the servlet.

  4. The init method definition looks like this: public void init(ServletConfigconfig) throws ServletException {  // Initialization code...} The service() Method • The administration() strategy is the principle technique to play out the genuine errand. The servlet compartment (i.e. web server) calls the administration() strategy to deal with demands originating from the customer( programs) and to compose the arranged reaction back to the customer. • Each time the server gets a demand for a servlet, the server brings forth another string and calls benefit. The administration() technique checks the HTTP ask for type (GET, POST, PUT, DELETE, and so forth.) and calls doGet, doPost, doPut, doDelete, and so forth strategies as proper.

  5. The servicemethod definition looks like this: public void service(ServletRequest request,ServletResponse response)      throws ServletException, IOException{} The doGet() Method • A GET request results from a normal request for a URL or from an HTML form that has no METHOD specified and it should be handled by doGet() method. The dogetmethod definition looks like this: public voiddoGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{ // Servlet code }

  6. The doPost() Method • A POST request results from an HTML form that specifically lists POST as the METHOD and it should be handled by doPost() method. The dopost method definition looks like this: public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Servlet code } The destroy() Method • The destroy() method is called only once at the end of the life cycle of a servlet. This method gives your servlet a chance to close database connections, halt background threads, write cookie lists or hit counts to disk, and perform other such cleanup activities. The dostroy method definition looks like this: public void destroy() {    // Finalization code...  }

  7. Architecture Diagram The following figure depicts a typical servlet life-cycle scenario.

  8. Initially the HTTP asks for going to the server are designated to the servlet compartment. • The servlet holder stacks the servlet before summoning the administration() strategy. • At that point the servlet holder handles various demands by producing different strings, each string executing the administration() technique for a solitary occasion of the servlet. • Servletsare Java classes which service HTTP requests and implement the javax.servlet.Servlet interface. • Web application developers typically write servlets that extend javax.servlet.http.HttpServlet, an abstract class that implements the Servlet interface and is specially designed to handle HTTP requests.

  9. Who Offer Best Java Training in Chennai • Among several Software Training Institute in Chennai. Greens Technologysis the only software training institute that offers the best Java training in Chennaiwith concrete examples. • Our trainers work professionally from leading IT companies that are able to provide hands-on training that will help you understand the concepts in Java easily. • Our training will help you get a great experience in technology and turn your ideas into new applications. • We limit the size of our lots, which will make the training sessions more interactive and well structured. • We've developed our course based on current software trends, which will certainly help you clear certification and interviews easily without any difficulty, so join us and be quickly placed.

More Related