Top 50 Servlet Interview Questions
Top 50 Servlet Interview Questions
com/
Servlets are mostly used because they are platform-independent Java classes and are
compiled to platform-neutral byte code. Java byte code can be loaded dynamically into and run
by java enabled web server.
A servlet container is a part of Web server that provides network services depends on request
and response are sent, MIME based requests and responses. It contains and manages servlets
through their life cycle.
4. What is a filter?
A filter is nothing but a piece of code which can be reusable that will be transforming the content
of HTTP requests, response and header information.
5. How can we refresh automatically when new data has entered the database?
Refresh in Client side and Server Push can be performed to refresh automatically when new
data is entered into the database.
1/7
https://career.guru99.com/
A session is an object which is used by a servlet and it is used to track user interaction with a
web application across multiple HTTP requests.
Servlet Mapping is an association mapping between servlet and a URL pattern. This is used to
map servlets with the requests.
Servlet context contains servlet view of Web application in which servlet will be running. By
using the context,
Log events
Obtain URL references to resources
Set and Store attributes
Loaded
Initialized
Destroy
Unloaded
11. What is the difference between Servlet Request and Servlet Context when calling a
Request Dispatcher?
Relative URL can be called when Servlet Request is used and Relative URL is not used when
using Servlet Context.
2/7
https://career.guru99.com/
Session tracking is used to maintain a state on the series of requests from the same user for a
given period of time.
Every HTTP request needs to be captured by HTTP protocol and for that, state is captured.
Tracking of state is called session tracking.
URL rewriting
Hidden Form Fields
Cookies
Secure Socket Layer (SSL)
Cookies are used to store long term information that can be maintained without server
interaction. Small and Medium size data are kept in a queue.
3/7
https://career.guru99.com/
URL rewriting is one of the methods of session tracking in which additional data is appended at
the end of each URL. This additional data identifies the session.
A servlet container which does not initialize at the start up, this is known as servlet lazy loading.
Chaining is one of the methods where out of one servlet is given to the second servlet. This
chaining can happen for any number of servlets.
Security check
Modifying the request or response
Data compression
Logging and auditing
Response compression
Lifecycle management
Communication support
Multithreading support
Declarative security
JSP support
JSP supports HTTP protocol which mainly used for presentation. But a servlet can support any
protocol like HTTP, FTP, SMTP etc.
Cookies
URL rewriting
HttpSession
Hidden form fields
4/7
https://career.guru99.com/
A scriptlet contains any language statements, variables, expressions that can be valid in the
page scripting language. Scriptlet is a part of generated servlet service method.
A server can provide service to the client and it contains one or more containers such as EJBs,
Servlet, JSP containers. Containers hold set of objects.
On the client side, Meta http is used for refresh and server push is used for server side refresh.
ServletConfig provides information about configuration of a servlet which is defined inside the
web.xml file and it is a specific object for each servlet.
ServletContext is an application specific object and it is shared by all servlet. It belongs to one
application in one JVM.
Pure servlet is servlet which is used to create java objects that can be implemented from
javax.servlet.Servlet interface.
Servlets are used for server side config and it keeps on server. But, Applets are used for client
side coding and it runs on client browsers.
Generic servlet is the super class of all servlets. This class is extended by all other classes and
it is protocol independent.
Java servlet is used to provide secure access to the web based date. This can extend
functionality present in the web servers. As it is platform and server independent, it is used for
many purposes.
A String Tokenizer is used to break the string into tokens and the token value is passed as an
5/7
https://career.guru99.com/
This is one of the servlet initialization and it is initialized when it is called for the first time.
Servlet Invoker allows web application to dynamically register new servlet definitions with the
servlet tag in the /WEB-INF/web.xml.
Servlet mapping maps URL patterns with the servlets. If there is a request from the client,
servlet container decides on which application it needs to map.
6/7
https://career.guru99.com/
45. What are the different mode that servlets can be used?
Servlets are used to process and store data submitted by HTML form, dynamic content, handle
multiple request concurrently and manage state information on top of stateless HTTP.
Yes, it can be achieved by writing doGet method in doPost method and writing doPost method
in doGet method.
50. What exception should be thrown when servlet is not properly initialized?
7/7
Powered by TCPDF (www.tcpdf.org)