Keeping in tune with the OCEJWCD 6 exam and its objectives, we will start a series of posts that will explain the concepts of the exam. This first post will discuss the basic concepts related to servlets and its life cycle.
What are the basic terminologies for the exam?
Client and Server:
A “client” is any user who makes certain requests to the server. The requests may be simple examples as fetching a document or modifying a shopping cart.
A “server” is a device or a program that returns the resources requested by the “client”. Most of the Internet runs on the client-server architecture.
Static pages and Dynamic pages:
“Static pages” are those that are returned “as is” to the client. An example may be fetching a document ‘xyz.html’ from the server.
“Dynamic pages” on the other hand are more interactive and user friendly. Pages that change according to user preferences, is one example of a dynamic page. The content on dynamic web sites, are not stale and are constantly updated.
Web components and Web applications:
Servlets and JSPs are considered to be web components. A web application is a combination of web components and static pages.
Servlets, CGI and Web container:
A “servlet” is a small program that runs inside a server. A servlet is responsible for doing most of the processing that has to be done by the application. A servlet is hence used to create dynamic and interactive pages. In the days prior to servlets, CGI was used to create dynamic pages. CGI scripts were slow and less secure than servlets. This was one of the reasons that they gave way to servlets in due course of time.
Web applications (servlets, JSPs and static pages) are managed by a web container. The primary function of a web container is to manage interactions between the different components in a web application and to manage the servlet life cycle.
Having seen the important definitions related to the Web component developer exam, let us move onto a discussion of servlets.
What are the important Servlets classes and interfaces?
In order to create servlets and work with them it is necessary to extend the ‘GenericServlet’ abstract class. If we have to work with Http Servlets specifically, it is necessary to extend the ‘HttpServlet’ abstract class. It should be noted that ‘Servlet’ itself is an interface.
It should also be borne in mind that the resource requested by a client is the “request” and the reply from the server is the “response”.
This brings us to two other important objects for the exam – the ‘HttpServletRequest’ interface and ‘HttpServletResponse’ interface. The ‘HttpServletRequest’ and ‘HttpServletResponse’ interfaces are related to the HTTP servlets.
This is the hierarchy of the ‘HttpServletRequest’ and ‘HttpServletResponse’ interface:
All servlets must override one of the following methods (which is defined in the HttpServlet class)
doGet()
doPost()
doPut()
doDelete()
There are three other doXXX() methods as well – they are doOptions(), doTrace() and doHead()
Servlet life cycle:
All servlets are characterized by the init(), service() and destroy() methods. Let us briefly see the servlet life cycle:
- The init() method is where the initialization of the servlet takes place. It takes place only once in a servlet life cycle. The init() method may be overridden.
- The servlet spends most of its time in the service() method. The service() method must not be overridden. The service() method in turn calls one of the doXXX() methods mentioned above.
- The destroy() method is called once the response is generated and sent back to the client. The destroy() method is again called only once and the final clean up of the servlet occurs here.
We have seen a brief introduction of the web component developer exam terminologies, the servlet interface and a crisp understanding of the servlet life cycle. We will understand more of servlets in the next post.
Preparing for OCEJWCD 6 Certification? Pass in 1st attempt through Whizlabs OCEJWCD 6 Course! Start with Free Trial!
- Top 45 Fresher Java Interview Questions - March 9, 2023
- 25 Free Practice Questions – GCP Certified Professional Cloud Architect - December 3, 2021
- 30 Free Questions – Google Cloud Certified Digital Leader Certification Exam - November 24, 2021
- 4 Types of Google Cloud Support Options for You - November 23, 2021
- APACHE STORM (2.2.0) – A Complete Guide - November 22, 2021
- Data Mining Vs Big Data – Find out the Best Differences - November 18, 2021
- Understanding MapReduce in Hadoop – Know how to get started - November 15, 2021
- What is Data Visualization? - October 22, 2021
Very useful and interesting. Thankyou for sharing this Great article
Thank you so much
very informative thanks so much