• phone icon +44 7459 302492 email message icon info@uplatz.com
  • Register
0- - 0
Job Meter = High

Java EE: Programming Servlets

30 Hours
Online Instructor-led Training
USD 1399 (USD 2800)
Save 50% Offer ends on 31-Dec-2023
Java EE: Programming Servlets course and certification
71 Learners

About this Course
Java Servlets are the first step to understanding web programming using Java, and this course will show you the basics of servlet architecture and applying filters to more complex issues like debugging and deployment. Web application development can be made easier by using Java servlets.

In this Java EE Programming Servlets course by Uplatz, you will begin with a complete overview of servlet architecture and lifecycle. First, you'll see the configuration of a Tomcat webserver in Eclipse and you'll learn how to read the request and response headers. Next, you'll learn how filters are applied to servlets and see many details about tracking session data, web annotations, and globalizing servlets. Finally, you'll go over asynchronous programming in servlets, debugging, packing, and deployment of servlets. By the end of this course, you will have a much more complete understanding of how web development using Java servlets works. Software required: Tomcat and Eclipse.


Java Servlets Course Objectives

·   Build a Basic Todo Management Application piece by piece in 25 Steps
·       Understand Basic Web Application Architecture
·       Understand and use Basics of Java EE - Servlets, JSP, Scriptlets, JSTL, web.xml and EL
·       Understand Servlet LifeCycle       Use HttpRequest - GET/POST, Request Parameters
·       Understand HTTP Response - Response Status - 404,200,500 etc.
·       Understand HTML Forms - Method, Action & Form Data
·       Understand Basics of using Maven, Tomcat and Eclipse
·       Understand Difference between Session and Request Scopes
·       Use Maven for Basic Dependency Management
·       Run Web Application in Tomcat
·       Style web applications with Bootstrap (Basics)
·       Use Filters to intercept Request


Java EE: Programming Servlets

Course Details & Curriculum

Developing your first Java Web Application using JSP and Servlets is fun.

In this course, you will learn the basics developing a Basic Todo Management Application using Java Servlets and JSP with Login and Logout functionalities.

You will build a Dynamic Website using the Core technologies of Java Web Programming. You will understand the basic concepts of Java Web Application Development - HTTP protocol, Request-Response cycle, Java Servlets, JSPs.

You will build the website step by step - in more than 25 steps. This course would be a perfect first step as an introduction to Java Web Application Development.

We will be using Tomcat Web Server and Eclipse IDE. We will help you set these up.

You will learn

  • Basic Web Application Architecture - Model 1 and Model 2 MVC
  • Basics of Java EE - Servlets, JSP, Scriptlets, JSTL, web dot xml and EL
  • Basic Flow of a Web Application, Forms, Request and Response
  • Basics of creating a Web Page using CSS and HTML
  • Basics of using Maven, Tomcat and Eclipse
  • Difference between Session and Request Scopes


  • Step 01 : Up and running with a Web Application in Tomcat
  • Step 02 : First JSP
  • Step 03 : Adding a Get Parameter name
  • Step 04 : Adding another Get Parameter Password
  • Step 05 : Let's add a form
  • Step 06 : New Form and doPost
  • Step 07 : Adding Password and Validation of User Id / Password combination
  • Step 08 : Adding a TodoService and Todos to welcome page
  • Step 09 : Bit of Refactoring - Packages
  • Step 10 : Redirect from One Servlet to another - New TodoServlet.
  • Step 11 : First JSTL Tag : Using a Loop around todos
  • Step 12 : Difference between Session and Request Scopes
  • Step 13 : Add a New Todo
  • Step 14 : Delete Todo with equals and hashcode methods
  • Step 15 : Adding webjars for jquery and bootstrap
  • Step 16 : Missing Step :) We want you to take a break. Nothing in here..
  • Step 17 : Updating Bootstrap to 3.3.6
  • Step 18 : More Refactoring
  • Step 19 : Adding a Filter for More Security.
  • Step 20 : Logout
  • Step 21 : Theory : Understand Maven and Tomcat
  • Step 22 : Theory : Servlet LifeCycle
  • Step 23 : Theory : Model 1 and Model 2 MVC Architectures
  • Step 24 : Moving Add Functionality to a New Page.
  • Step 25 : Add Category Field
  • Step 26 : Format the JSPs better.
  • Step 27 : JSP Fragments


Job Prospects

Java EE Servlets Interview Questions


1) What are Servlets? 

Java Servlets are programs that run on a Web or Application server and act as a middle layer between a request coming from a Web browser or other HTTP client and databases or applications on the HTTP server.

2) What are the advantages of servlets over CGI? 

Servlets offer several advantages in comparison with the CGI.

  • Performance is significantly better.
  • Servlets execute within the address space of a Web server. It is not necessary to create a separate process to handle each client request.
  • Servlets are platform-independent because they are written in Java.
  • Java security manager on the server enforces a set of restrictions to protect the resources on a server machine. So servlets are trusted.
  • The full functionality of the Java class libraries is available to a servlet. It can communicate with applets, databases, or other software via the sockets and RMI mechanisms that you have seen already.

3) What are the major tasks of servlets? 

Servlets perform the following major tasks:

  • Read the explicit data sent by the clients (browsers). This includes an HTML form on a Web page or it could also come from an applet or a custom HTTP client program.
  • Read the implicit HTTP request data sent by the clients (browsers). This includes cookies, media types and compression schemes the browser understands, and so forth.
  • Process the data and generate the results. This process may require talking to a database, executing an RMI or CORBA call, invoking a Web service, or computing the response directly.
  • Send the explicit data (i.e., the document) to the clients (browsers). This document can be sent in a variety of formats, including text (HTML or XML), binary (GIF images), Excel, etc.
  • Send the implicit HTTP response to the clients (browsers). This includes telling the browsers or other clients what type of document is being returned (e.g., HTML), setting cookies and caching parameters, and other such tasks.

4) Explain servlet 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.

5) When init() method of servlet gets called? 

The init method is designed to be called only once. It is called when the servlet is first created, and not called again for each user request. So, it is used for one-time initializations, just as with the init method of applets.

6) What is Servlet Context? 

The Servlet context is an object that contains a information about the Web application and container. Using the context, a Servlet can log events, obtain URL references to resources, and set and store attributes that other Servlet in the context can use.

7) What is a Servlet Filter? 

Servlet filters are pluggable Web components that allow us to implement pre-processing and post-processing logic in our Web applications.

8) What is a WAR File? 

WAR stands for Web Archive. It is a compressed version of your web application. You can use this WAR file to deploy your web application.

9) Can we use the Constructor, instead of Init(), to initialize Servlet? 

Yes. But you will not get the Servlet specific things from constructor. The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructor a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext.

10) How would you create Deadlock on your Servlet? 

Calling a doPost() method inside doGet() and doGet()method inside doPost() wouleate a deadlock for a servlet.

11) Why is Httpservlet declared abstract?

a) The default implementations of the main service methods can not do anything and need to be overridden. This calls of the HttpServlet class to be declared as abstract.
b) With its use the developers do not need to implement all the service methods.

12) Why Is a Constructor needed in a Servlet even if we use the Init Method? 

a) Although the init method of the servlet initializes it, a constructor instantiates it.
b) A developer might never explicitly call the servlet's constructor but a container uses it to create an instance of the servlet.

13) What is Genericservlet Class? 

a) GenericServlet is an abstract class which implements the Servlet interface and the ServletConfig interface.
b) Other than the methods included in above two interfaces, it also provides simple versions of the lifecycle methods init and destroy, and implements the log method declared in the ServletContext interface.
c) Since this class is not specific to any protocol, it is known as generic servlet.

14) How can the Session in Servlet be destroyed? 

There are two ways to destroy a session:
1. Programatically : By using session.invalidate() method. It makes the container abandon the session on which the method is called.
2. When the server shuts down.

15) What is Lazy Loading? 

The servlets are not initialized by the container from the start. It happens when the servlet is requested for the first time. This is called lazy loading.

16) What are the mechanisms used by a Servlet Container for maintaining Session information? 

For maintaining session information Servlet Container uses:
. Cookies
. URL rewriting
. HTTPS protocol information

17) When service() method of servlet gets called? 

Each time the server receives a request for a servlet, the server spawns a new thread and calls service. The service() method checks the HTTP request type (GET, POST, PUT, DELETE, etc.) and calls doGet, doPost, doPut, doDelete, etc. methods as appropriate.

18) When doGet() method of servlet to be called? 

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.

19) When doPost() method of servlet to be called? 

A POST request results from an HTML form that specifically lists POST as the METHOD and it should be handled by doPost() method.

20) When destroy() method of servlet gets called? 

The destroy() method is called only once at the end of the life cycle of a servlet.

21) For what purpose init() method of a servlet is used? 

The init() method simply creates or loads some data that will be used throughout the life of the servlet.

22) For what purpose destroy() method of a servlet is used? 

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.

23) For what purpose doGet() method of a servlet is used? 

This method should be used to get data from server.

24) For what purpose doPost() method of a servlet is used? 

This method should be used to process data on the server.

25) Explain working of service() method of a servlet. 

The service() method is the main method to perform the actual task. The servlet container (i.e. web server) calls the service() method to handle requests coming from the client( browsers) and to write the formatted response back to the client.

Each time the server receives a request for a servlet, the server spawns a new thread and calls service. The service() method checks the HTTP request type (GET, POST, PUT, DELETE, etc.) and calls doGet, doPost, doPut, doDelete, etc. methods as appropriate.

26) How to read form data in servlet? 

Servlets handles form data parsing automatically using the following methods depending on the situation:

  • getParameter(): You call request.getParameter() method to get the value of a form parameter.
  • getParameterValues(): Call this method if the parameter appears more than once and returns multiple values, for example checkbox.
  • getParameterNames(): Call this method if you want a complete list of all parameters in the current request. 

27) How to read name of all parameters in servlet?

getParameterNames() method of HttpServletRequest returns complete list of all parameters in the current request. This method returns an Enumeration that contains the parameter names in an unspecified order.

Once we have an Enumeration, we can loop down the Enumeration in the standard manner, using hasMoreElements() method to determine when to stop and using nextElement() method to get each parameter name.

28) How to read http header information in servlet? 

We can use getHeaderNames() method of HttpServletRequest to read the HTTP header infromation. This method returns an Enumeration that contains the header information associated with the current HTTP request.

Once we have an Enumeration, we can loop down the Enumeration in the standard manner, using hasMoreElements() method to determine when to stop and using nextElement() method to get each parameter name.

29) What is HTTPServletRequest class? 

When a browser requests for a web page, it sends lot of information to the web server which can not be read directly because this information travel as a part of header of HTTP request. HTTPServletRequest represents this HTTP Request.

30) What is HTTPServletResponse class?

when a Web server responds to a HTTP request to the browser, the response typically consists of a status line, some response headers, a blank line, and the document. HTTPServletResponse represents this HTTP Response.

31) How to write html contents using servlets? 

Get the object of PrintWriter using request.

PrintWriter out = response.getWriter();

Now print html.

out.println("Hello World");

32) How to send an authentication error from a servlet? 

We can use setStatus(statuscode) method of HttpServletResponse to send an authentication error.

// Set error code and reason.

response.sendError(407, "Need authentication!!!" );

33) How to redirect a request from a servlet to another servlet? 

Page redirection is generally used when a document moves to a new location and we need to send the client to this new location or may be because of load balancing, or for simple randomization. The simplest way of redirecting a request to another page is using method sendRedirect() of response object.

34) How sendRedirect method works? 

This method generates a 302 response along with a Location header giving the URL of the new document.

35) How sendError method works? 

This method sends a status code (usually 404) along with a short message that is automatically formatted inside an HTML document and sent to the client.

36) What are servlets filters? 

Servlet Filters are Java classes that can be used in Servlet Programming for the following purposes:

  • To intercept requests from a client before they access a resource at back end.
  • To manipulate responses from server before they are sent back to the client. 

37) Name some of the servlets filters?

There are various types of filters suggested by the specifications:

  • Authentication Filters.
  • Data compression Filters.
  • Encryption Filters.
  • Filters that trigger resource access events.
  • Image Conversion Filters.
  • Logging and Auditing Filters.
  • MIME-TYPE Chain Filters.

38) How to do servlet filter mapping? 

Filters are deployed in the deployment descriptor file web.xml and then map to either servlet names or URL patterns in your application's deployment descriptor.

39) Can multiple filters be configured? 


40) Can filtering be done in an ordered way? If so then how to achieve it? 

Yes. The order of filter-mapping elements in web.xml determines the order in which the web container applies the filter to the servlet. To reverse the order of the filter, you just need to reverse the filter-mapping elements in the web.xml file. 


Didn't find what you are looking for?  Contact Us