Servlets-1.doc - Introduction Servlets-1 Definition...

Info icon This preview shows pages 1–4. Sign up to view the full content.

Servlets-1 Introduction Definition: Servlets are java programs that run on a Web server and build Web pages. Working of a servlet : A client program, which could be a Web browser or some other program that can make connections across the Internet, accesses a Web server and makes a request. This request is processed by the servlet engine that runs within the Web server, which returns a response to a servlet. The servlet in turn sends a response in HTTP form to the client. Java Web Application Structure Java Servlet Architecture Two packages make up the servlet architecture: javax.servlet , contains the generic interfaces and classes that are implemented and extended by all servlets. javax.servlet.http packages. contains the classes that are extended when creating HTTP-specific servlets.
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

At the heart of this architecture is the interface javax.servlet.Servlet . It provides the framework for all servlets. Servlet Interface It provides the framework for all servlets. The Servlet interface defines five methods. The three most important are as follows: init ( ) method – initializes a servlet service () method – Receives and responds to client requests. destroy ( ) method – performs cleanup. Other two are: getServletConfig() method getServletInfo() method All servlets must implement this interface, either directly or through inheritance. It is a very clean object- oriented approach that makes the interface very easy to extend. Servlet Lifecycle A Java servlet has a lifecycle that defines how the servlet is loaded and initialized, how it receives and responds to requests, and how it is taken out of service. In code, the servlet lifecycle is defined by the javax.servlet.Servlet interface. All Java servlets must, either directly or indirectly, implement the Javax.servlet.Servlet interfaces so that they can run in a servlet engine. The servlet engine is a customized extension to a Web server for processing servlets, built in conformance with the Java Servlet API by the Web server vendor. The servlet engine provides network services and runs servlet containers. The javax.servlet.Servlet interface defines methods that are called at specific times and in a specific order during the servlet lifecycle. The entire servlet lifecycle is
Image of page 2
How a Servlet is Loaded and Instantiated? The servlet engine instantiates and loads a servlet. The instantiation and loading can occur when the engine starts, when it needs the servlet in order to respond to a request, or any time in between. The servlet engine loads a servlet using the Java class loading facility. The servlet engine can load the servlet from the local file system, a remote file system, or a network source. How a Servlet is Initialized?
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Image of page 4
This is the end of the preview. Sign up to access the rest of the document.
  • Fall '17
  • Rabia Khurshid
  • Java Servlet

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern