• +91 9723535972
  • info@interviewmaterial.com

Servlet Interview Questions and Answers

Servlet Interview Questions and Answers

Question - 101 : - What are the reasons we use inter-servlet communication?

Answer - 101 : -

There are three major reasons to use the inter servlet communication:

  • Direct servlet manipulation
  • Servlet reuse
  • Servlet collaboration

Question - 102 : - What do you mean by Servlet Manipulation?

Answer - 102 : -

When one servlet accesses the loaded servlets on its server, it is called Servlet Manipulation. It also optionally performs some task on one or more of them. A servlet gets information about other servlets through the ServletContext object. We use getServlet() to get a particular servlet:

public Servlet ServletContext.getServlet(String name) throws ServletException

Question - 103 : - Explain Request Dispatcher and its methods.

Answer - 103 : -

Request Dispatcher creates an object that is responsible to receive requests from the browser or client and then navigates them to any resources like Servlets, JSP, or HTML which resides at the server-side.

There are basically two methods of Request Dispatcher:

a) Forward () method:

  • In the Forward() method the client sends the request to the Servlet1.
  • The Servlet1 processes the request and then forwards the request to Servlet2.
  • The servlet2 processes the request and generates a response which in turn is sent back to the client as the final response.
b) Include () method:

  • In Include () method the client sends the request to the Servlet1.
  • The Servlet1 processes the request and then includes the request and sends the request to Servlet2.
  • The servlet2 processes the request and again sends it back to Servlet1 and
  • The Servlet1 generates a response which in turn is sent back to the client as the final response.

Question - 104 : - Explain the WAR file?

Answer - 104 : - A WAR file is basically referred to as a Web Archived file, which has all the files of your application like XML, servlets, JSP, HTML, configuration files combined into a single file so that deploying the application would be simple and easy.

Question - 105 : - What do you mean by Servlet Context?

Answer - 105 : -

Servlet Context is basically referred to as an object which has information regarding application and the Web Container. With Servlet context we can log events, get the URL of the specific resource, and can easily store the attributes for other servlets to use.

The core advantage of Servlet is that it is easy to maintain and acts as a mediator between the container and servlet.

There are some important methods of servlet context which are given below:

  • getInitParameter () – return the value of parameter.
  • getInitParameterNames () – returns the name of parameter.
  • void setAttribute () – used to set the values of attributes.
  • void getAttribute () – used to get the values of attributes.
  • void removeAttribute () – used to remove the attribute.

Question - 106 : - What do you mean by deployment descriptor?

Answer - 106 : -

WEB.XML is said to be the deployment descriptor in a servlet.

It is the entry point for any application and possesses the welcome file list. It defines resources, information about which servlet will be used and maps the servlet to URL.

Question - 107 : - Is servlet synchronized?

Answer - 107 : - No, the servlets are not synchronized. If we want to make the servlet synchronized, we must implement SingleThreadInterface.

Question - 108 : - What do you mean by Scope Object and what are its types?

Answer - 108 : -

Scope objects help to share information among web components via setattribute() and getattribute().

Types of Scope Objects are:

  • Web Context
  • Session
  • Request
  • Page

Question - 109 : - What does the term Localization refer to?

Answer - 109 : -

Localization basically refers to the local tradition or language followed by the user. So, we add resources or elements to the particular website like adding the Hindi language so every user can understand.

Question - 110 : -
If servlet receives multiple requests, how many objects will it create?

Answer - 110 : -

Servlet will create only one instance, no matter how many incoming requests it receives.


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners