300+ TOP Apache Tomcat Interview Questions and Answers

Tomcat Interview Questions for Experienced & Freshers

1. How Servlet Life Cycles?

The life-cycle of a typical servlet running on Tomcat:

  • Tom-cat receives a request from a client through one of its connectors
  • For processing, this request Tomcat maps this request to appropriate
  • Once the request has been directed to the appropriate servlet, Tomcat verifies that servlet class has been loaded. If it is not than Tomcat wraps the servlet into Java Bytecode, that is executable by the JVM and forms an instance of the servlet
  • Tomcat initiates the servlet by calling its init The servlet contains code that is able to screen Tomcat configuration files and act accordingly, as well as declare any resources it might require
  • Once the servlet has been started, Tomcat can call the servlet’s service method to proceed the request
  • Tomcat and the servlet can co-ordinate or communicate through the use of listener classes during the servlet’s lifecycle, which tracks the servlet for a variety of state changes.
  • To remove the servlet, Tomcat calls the servlets destroy method.

2. Explain Directory Structure Of Tomcat?

Directory structure of Tomcat are:

bin – contain startup, shutdown, and other scripts (*.sh for UNIX and *.bat for Windows systems) and some jar files also there.

conf – Server configuration files (including server.xml) and related DTDs. The most important file in here is server.xml. It is the main configuration file for the container.

lib – contains JARs those are used by container and Servlet and JSP application programming interfaces (APIs).

logs – Log and output files.

webapps – deployed web applications reside in it .

work – Temporary working directories for web applications and mostly used during in JSP compilation where JSP is converted to a Java servlet.

temp – Directory used by the JVM for temporary files .

3. How Running Tomcat As A Windows Service Provides Benefits?

Running Tomcat as a windows service provides benefits like:

  • Automatic startup: It is crucial for environment where you may want to remotely re-start a system after maintenance
  • Server startup without active user login: Tomcat is run oftenly on blade servers that may not even have an active monitor attached to them. Windows services can be started without an active user
  • Security: Tomcat under window service enables you to run it under a special system account, which is protected from the rest of the user accounts

4. What Is Tomcat?

Tomcat is a Java Servlet container and web server from Jakarta project of Apache software foundation. A web server sends web pages as response to the requests sent by the browser client. In addition to the static web pages, dynamic web pages are also sent to the web browsers by the web server. Tomcat is sophisticated in this respect, as it provides both Servlet and JSP technologies. Tomcat provides a good choice as a web server for many web applications and also a free Servlet and JSP engine. Tomcat can be used standalone as well as behind other web servers such as Apache httpd.

5. How To We Can Change Tomcat Default Port?

8080 is the default HTTP port that Tomcat attempts to bind to at startup.  To change this, we need to change port in $ TOMCAT_HOME /conf/server.xml, in that we can search 8080 and after getting below statement

We can change 8080 to other port like 8081, we need to restart tomcat to take effect. We required changes in URL as http://localhost:8081/.

6. What Is Webservers? Why It Is Used?

Traction with HTTP request and HTTP response is called webserver.

Using the internet listening the HTTP request and providing the HTTP response is also called webserver.It gives only html output.It will not process business logic .They can provide Http server.They are static.

7. Mention What Is The Output Of Select * From Tab?

It displays the default tables in the database

8. What Is Default Session Time Out In Tomcat?

The default session timeout 30 minutes in tomcat and can change in $TOMCAT_HOME/conf/web.xml via modify below entry

9. What Is Different Between Webserver And Application Server?

The basic difference between a web server and an application server is Webserver can execute only web applications i,e servlets and JSPs and has only a single container known as Web container which is used to interpret/execute web applications. Application server can execute Enterprise application, i,e (servlets, jsps, and EJBs)

it is having two containers:

  1. Web Container(for interpreting/executing servlets and jsps)
  2. EJB container(for executing EJBs).

it can perform operations like load balancing , traction demarcation etc.

10. What Is Tomcat Coyote?

Tom coyote is an HTTP connector based on HTTP/ 1.1 specification which receives and trport web requests to the Tomcat engine by listening to a TCP/IP port and sent request back to the requesting client.

11. How Do I Can Change The Default Home Page Loaded By Tomcat?

We can easily override home page via adding welcome-file-list in application $TOMCAT_HOME/webapps//WEB-INF /web.xml file or by editing in container $TOMCAT_HOME/conf/web.xml

In $TOMCAT_HOME/conf/web.xml, it may look like this: 




Request URI refers to a directory, the default servlet looks for a “welcome file” within that directory in following order: index.html, index.htm and index.jsp

If none of these files are found, server renders 404 error.

12. When You Can Use . And When You Can Use []?

If you are running a bean property, use the .operator, and if you are executing a map value or an array index, it is preferred to use the [] operator. Although you can use these operators interchangeably.

13. How Web Server Handles Multiple Requests For Same Action Class(struts) Concurrently?

Struts or any webserver makes new thread for each new request. so multiple request is served with new request object.

14. Suppose When We Are Starting Startup.bat File Of Tomcat Server It Is Not Started. Dos Window Appears For A Second Only. What We Need Do?

Your set up might have been not done well.

Make sure you have added tomcat root directory path in the CATALINA_HOME environment variable and added the bin path in the path variable.

15. Explain What Is Tomcat Valve?

A tomcat valve- a new technology is introduced with Tomcat 4 which enables you to link an instance of a Java class with a specific Catalina container.

16. Mention What Are The Connectors Used In Tomcat?

In Tomcat, two types of connectors are used:

  1. HTTP Connectors: It has many attributes that can be changed to determine exactly how it works and access functions such as redirects and proxy forwarding
  2. AJP Connectors: It works in the same manner as HTTP connectors, but they practice the AJP protocol in place of HTTP. AJP connectors are commonly implemented in Tomcat through the plug-in technology mod_jk.

17. How To Communicate Between Two Web Servers In Two Diff Systems?

By using plug module .

18. Explain What Is Jasper?

  • Jasper is a Tomcat JSP engine
  • It parses JSP files to compile them into JAVA code as servlets
  • At runtime, Jasper allows to automatically detect JSP file changes and recompile them

19. Explain What Does The Mac Stands For?

MAC me Medium Access Control

20. What Is Apache Tomcat?

Apache Tomcat is an open-source web server and Servlet/JSP container developed by the Apache Software Foundation. Tomcat implements several Java EE specifications including Java Servlet, Java Server Pages (JSP), Java EL, and WebSocket, and provides a “pure Java” HTTP web server environment for Java code to run in.

21. Mention With How Many Valves Does Tomcat Configured With?

Four types of valves Tomcat is configured with:

  • Access Log
  • Remote Address Filter
  • Remote Host Filter
  • Request Dumper

22. How Do You Create Multiple Virtual Hosts?

If you want tomcat to accept requests for different hosts e.g. www.myhostname.com then you must

  • Create ${catalina.home}/www/appBase , ${catalina.home}/www/deploy, and ${catalina.home}/conf/Catalina/www.myhostname.com
  • Add a host entry in the server.xml file
  • Create the the following file under conf/Catalina/www.myhostname.com/ROOT.xml
  • Add any parameters specific to this hosts webapp to this context file
  • Put your war file in ${catalina.home}/www/deploy
  • When tomcat starts, it finds the host entry, then looks for any context files and will start any apps with a context.

23. Can I Set Java System Properties Differently For Each Webapp?

No. If you can edit Tomcat’s startup scripts, you can add “-D” options to Java. But there is no way to add such properties in web.xml or the webapp’s context.

24. Explain When To Use Ssl With Tomcat?

You would use Tomcat to handle connection, when you are running Tomcat as a stand-alone web server.

25. Explain The Concepts Of Tomcat Servlet Container.?

  • Tomcat Servlet Container is a servlet container. The servlets runs in servlet container.
  • The implementation of Java Servlet and the Java Server Pages is performed by this container.
  • Provides HTTP web server environment in order to run Java code.
  • Reduces garbage collection
  • Native Windows and Unix wrappers for platform integration

Tomcat Questions with Answers Pdf Download