You are on page 1of 4

Tomcat Question&Answer

1) How will you clear the cache of Tomcat server?


Ans: The tomcat server keeps a copy of compiled servlets and JSPs present in all
deployed web application at the following location.
$Tomcat_ServerworkCatalinalocalhost
To clear the cache, you just need to delete the folder corresponding to the web
application for which you want to clear the cache.
2) What is Tomcat?
Ans: 1) Tomcat is a Java Servlet container and web server from the Jakarta project
of the Apache software foundation.
2) A web server responds with web pages to requests from client browsers.
3) Web servers can provide dynamic content based on the requests sent by the
user.
4) Tomcat is very good at this because it provides both Java servlet and
JavaServerPages (JSP) technologies.
5) Tomcat can also be used as a web server for many applications even if free
servlet and JSP engine is wanted.
6) It can be used standalone or used behind traditional web servers such as Apache
httpd, with the traditional server serving static pages and Tomcat serving dynamic
servlet and JSP requests.
3) What all services are provided by Tomcat?
Ans: 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:
1) Life cycle Management
2) Handling Web Requests
3) Thread Management
4) Connection pooling
5) Clustering
Apart from the above service, you can also tell about the various tomcat
components about which not everyone is aware in detail.
4) How will you create a database connection pool in Tomcat server?
Ans: The steps to configure connection pool:
1) Configure pool in context.xml inside conf folder of tomcat.
2) 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.
5) What are the steps to enable SSL in web application deployed on Tomcat?
Ans: Read this excellent tutorial on enabling SSL in web application deployed on
tomcat
6) Can we run multiple instances of Tomcat server on single machine? If yes how?
Ans: I had posted a blog entry about configuring multiple instances of tomcat on a
single machine.
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)
Ans: 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?
Ans: The typical web application structure which is deployed on tomcat is:

The contents of WEB-INF folder shall look like:

9) How can one enable Hot Deployment in Tomcat?
Ans: For enabling hot deployment, follow the official guide by Apache at configuring
tomcat hot deployment.
10) Will you classify Tomcat as web server or application server?
Ans: Ideally speaking, tomcat is neither a web server not application server because
of the following points:
a) Tomcat has servlet and JSP engine present in it which is not provided by web
servers
b) Tomcat can not run EJB based applications which can be run by application
servers.
11) What are the steps to configure clustering in Tomcat server?
Ans: Apache Tomcat wiki lists down the steps for configuring clustering in the guide
at Tomcat server clustering
12) How do you define welcome file list?
Ans: 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:
<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 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.
13) Why is Tomcat not an application server?
Ans: 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 doesnt provide services
to install/manage EJB and JMS based applications.
14) How do you create multiple virtual hosts?
Ans: If you want tomcat to accept requests for multiple 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.
To add more sites just repeat and rinse, all webapps can share the same war file
location and appbase.
15) What is Jasper?
Ans: Jasper is a program to read the .class files in binary format. This program can
generate ASCII files , which can be used along with Jasmin Assembler. Jasper is
intended for generating input into a class file browser which can produce the
hierarchy of inheritance and composition maps from the .class files.
16) 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?
Ans: 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.
17) How would you set up tomcat for remote debugging?
Ans: 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 startup.sh file
call %EXECUTABLE% jpda start %CMD_LINE_ARGS%
Make sure you comment out
call %EXECUTABLE% start %CMD_LINE_ARGS%
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


Read more: http://www.javaexperience.com/tomcat-server-interview-questions-and-
answers/#ixzz363hPBgCO

You might also like