Interview Questions
« Previous | 0 | 1 | 2 | 3 | 4 | Next »

1.What is Tomcat?

Tomcat is a Java Servlet container and web server from Jakartha 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.

2.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

3.How will you clear the cache of Tomcat server?

The tomcat server keeps a copy of compiled servlets and JSP’s present in all deployed web application at the following location.
To clear the cache, you just need to delete the folder corresponding to the web application for which you want to clear the cache.

4.What all services are provided by Tomcat?

Tomcat server provides a host of services which are not provided by normal web servers like Apache Web Server. The following is a list of services provided by Tomcat:

  • Life cycle Management
  • Handling Web Requests
  • Thread Management
  • Connection pooling
  • Clustering
Apart from the above service, you can also tell about the various tomcat components about which not everyone is aware in detail.

5.How will you create a database connection pool in Tomcat server?

The steps to configure connection pool:

  • Configure pool in context.xml inside conf folder of tomcat.
  • Perform a JNDI lookup of pool and get connection from data source.
The JDBC connection pooling page shows how one can create connection pool in tomcat server.

6.What are the steps to enable SSL in web application deployed on Tomcat?

Read this excellent tutorial on enabling SSL in web application deployed on tomcat

7.Suppose there is a clash between the version of library being shipped with your application and the library of Tomcat, How will you resolve it? (Take example of Log4J)

There should be only one jar file for a particular library and if there is a clash, you should be using the version of library provided by the server which can avoid problems arising when deploying the application on client machines.

8.What is the directory structure of a web application deployed on Tomcat?

The typical web application structure which is deployed on tomcat is:

- images
- js
- src
|- classes
|- lib
|- web.xml
- index.html

9.Will you classify Tomcat as web server or application server?

Ideally speaking, tomcat is neither a web server not application server because of the following points:

  • Tomcat has servlet and JSP engine present in it which is not provided by web servers
  • Tomcat can not run EJB based applications which can be run by application servers.

10.What are the steps to configure clustering in Tomcat server?

Apache Tomcat wiki lists down the steps for configuring clustering in the guide at Tomcat server clustering

11.How do you define welcome file list?

We can define welcome file list in web.xml deployment descriptor by using the welcome-file-list tag as shown in the following sample code:

The actual welcome file being presented to the user shall be decided from the above list. If index.html is present then it shall be shown. If no index.html file is present in the root folder of web application, then server tries to find a file with the name index.htm and that also fails then it finds index.jsp.

12.Why is Tomcat not an application server?

Application server is broader term where a host services apart from deploying a JSP/Servlet based application are provided. Tomcat is a web server and not application server. This is because of the fact that Tomcat doesn’t provide services to install/manage EJB and JMS based applications.

13.How do you create multiple virtual hosts?

If you want tomcat to accept requests for multiple hosts e.g. then you must.

  • Create ${catalina.home}/www/appBase , ${catalina.home}/www/deploy, and ${catalina.home}/conf/Catalina/
  • Add a host entry in the server.xml file.
  • Create the the following file under conf/Catalina/
  • 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.
To add more sites just repeat and rinse, all webapps can share the same war file location and appbase.

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.How would you set up tomcat for remote debugging?

In windows environment , open up your startup.bat and add to file somewhere in beginning

  • rem set remote debugger
  • set JPDA_ADDRESS=8001
  • set JPDA_TRANSPORT=dt_socket
  • echo Remote debugging started
Add this to end of your file
call “%EXECUTABLE%” jpda start %CMD_LINE_ARGS%
Make sure you comment out
When you are connecting with eclipse, set your debug port at 8001. Now when you start your server , you would see the message Remote debugging started

16.How do I configure Tomcat to work with IIS and NTLM?

Follow the standard instructions for when the isapi_redirector.dll Configure IIS to use “integrated windows security”
In server.xml, make sure you disable tomcat authentication:

1 <Connectorport="8009"enableLookups="false"redirectPort="8443"protocol="AJP/1.3"tomcatAuthentication="false"/>

17.How do I override the default home page loaded by Tomcat?

After successfully installing Tomcat, you usually test it by loading http://localhost:8080 . The contents of that page are compiled into the index_jsp servlet. The page even warns against modifying the index.jsp files for this reason. Luckily, it is quite easy to override that page. Inside $TOMCAT_HOME/conf/web.xml there is a section called and it looks like this:

  • <welcome-file-list>
  • <welcome-file>index.html</welcome-file>
  • <welcome-file>index.htm</welcome-file>
  • <welcome-file>index.jsp</welcome-file>
  • </welcome-file-list>
The default servlet attempts to load the index.* files in the order listed. You may easily override the index.jsp file by creating an index.html file at $TOMCAT_HOME/webapps/ROOT. It’s somewhat common for that file to contain a new static home page or a redirect to a servlet’s main page. A redirect would look
1 <html>
3 <head>
4 <metahttp-equiv="refresh"content="0;URL=">
5 </head>
7 <body>
8 </body>
10 </html>
This change takes effect immediately and does not require a restart of Tomcat.

Two things have to be done for tomcat to aknowledge SSI scripts:

18.How do I enable Server Side Includes (SSI)?

  • Rename $CATALINA_BASE/server/lib/servlets-ssi.renametojar to $CATALINA_BASE/server/lib/servlets-ssi.jar.
  • Uncomment the section of web.xml found in $CATALINA_BASE/conf/web.xml
that deals with SSI. it looks like this when it is uncommented:
1 <servlet>
2 <servlet-name>ssi</servlet-name>
3 <servlet-class>
4 org.apache.catalina.ssi.SSIServlet
5 </servlet-class>
6 <init-param>
7 <param-name>buffered</param-name>
8 <param-value>1</param-value>
9 </init-param>
10 <init-param>
11 <param-name>debug</param-name>
12 <param-value>0</param-value>
13 </init-param>
14 <init-param>
15 <param-name>expires</param-name>
16 <param-value>666</param-value>
17 </init-param>
18 <init-param>
19 <param-name>isVirtualWebappRelative</param-name>
20 <param-value>0</param-value>
21 </init-param>
22 <load-on-startup>4</load-on-startup>
23 </servlet>

19.How do I use DataSources with Tomcat?

When developing J2EE web applications, the task of database connection management can be daunting. Best practice involves using a J2EE DataSource to provide connection pooling, but configuring DataSources in web application servers and connecting your application to them is often a cumbersome process and poorly documented.
The usual procedure requires the application developer to set up a DataSource in the web application server, specifying the driver class, JDBC URL (connect string), username, password, and various pooling options. Then, the developer must reference the DataSource in his application’s web.xml configuration file, and then access it properly in his servlet or JSP. Particularly during
development, setting all of this up is tedious and error-prone. With Tomcat 5.5, the process is vastly simplified. Tomcat allows you to configure DataSources for your J2EE web application in a context.xml file that is stored in your web application project. You don’t have to mess with configuring the DataSource separately in the Tomcat server.xml, or referencing it in your application’s web.xml file. Here’s how:
Install the JDBC Driver
Install the .jar file(s) containing the JDBC driver in Tomcat’s common/lib folder. You do not need to put them in your application’s WEB-INF/lib folder. When working with J2EE DataSources, the web application server manages connections for your application.
Create META-INF/context.xml
In the root of your web app directory structure, create a folder named META-INF (all caps). Inside that folder, create a file named context.xml that contains a Resource like this:

1 <?xmlversion="1.0"encoding="UTF-8"?>
3 <Context>
5 <Resourcename="jdbc/WallyDB"auth="Container"
6 type="javax.sql.DataSource"username="wally"password="wally"
7 driverClassName=""
8 url="jdbc:sqlserver://localhost;DatabaseName=mytest;SelectMethod=cursor;"
9 maxActive="8"
10 />
12 </Context>
This example shows how to configure a DataSource for a SQL Server database named mytest located on the development machine. Simply edit the Resource name, driverClassName, username, password, and url to provide values appropriate for your JDBC driver.
Access the DataSource in Your Application
From a Servlet
Here’s how you might access the data in a servlet:
1 InitialContext ic =newInitialContext();
2 DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/WallyDB");
3 Connection c = ds.getConnection();
4 ...
5 c.close();
Notice that, when doing the DataSource lookup, you must prefix the JNDI name of the resource with java:comp/env/

20.What is Apache Tomcat Server ?

Apache Tomcat Server is very lightweight java application in itself an application server from the Apache Software Foundation (AES) that run Java servlets and renders Web pages that include Java Server Page coding.

« Previous | 0 | 1 | 2 | 3 | 4 | Next »

copyright © 2014 - all rights riserved by