Tomcat Interview Questions And Answers Pdf

1. Explain how you can deploy a web application using WAR files?
Answer: JSPs, servlets, and their supporting files are placed in the proper subdirectories under the web apps directory in Tomcat. You can make all the files under the web apps directory into one compressed file, which ends with the .war file extension. You can execute a web application by placing a WAR file in the web apps directory. When a web server starts executing, it pulls out the WAR file’s contents into the appropriate web apps sub-directories.

2. How will you clear the cache of the Tomcat server?
Answer: The tomcat server keeps a copy of compiled servlets and JSP’s 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.

3. How Do I Can Change The Default Home Page Loaded By Tomcat?
Answer: 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:
index.html
index.htm
index.jsp
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.

4. Explain When You Can Use. And When You Can Use?
Answer: 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.

5. How do you create multiple virtual hosts?
Answer: 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/www.myhostname.com.
Add a host entry in the server.xml file.
Create the following file under conf/Catalina/www.myhostname.com/ROOT.xml.
Add any parameters specific to this hosts web app 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 web apps can share the same war file location and appease.

6. Explain what is Tomcat Valve?
Answer: 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.

7. Explain what is Jasper?
Answer: Jasper is a Tomcat’s 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

8. Mention what is the default port for Tomcat?
Answer: The default port for Tomcat is 8080. After initializing Tomcat on your local machine, you can verify if Tomcat is running the URL:
home-oss-logos-tomcat

9. Mention What Are The Connectors Used In Tomcat?
Answer:
In Tomcat, two types of connectors are used:
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
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.

10. stored a cookie on the browser; why can’t I see it?
Answer: First, check to make sure you spelled the cookie name correctly. Next, make sure the browser has cookies enabled. Also, if you specified a root path for the cookie, make sure that the JSP or servlet reading the cookie is in that path. Remember, too, that if you don’t give the cookie specific expiration time, the cookie will vanish when the user shuts the browser down.

11. How will you load properties file?
Answer: Use a ResourceBundle. See the Java docs for the specifics of how the ResourceBundle class works. Using this method, the properties file must go into the WEB-INF/classes directory or in a jar file contained in the WEB-INF/lib directory.
* Another way is to use the method getResourceAsStream() from the ServletContext class. This allows you to update the file without having to reload the web app as required by the first method. Here is an example code snippet, without any error trapping:
// Assuming you are in a Servlet extending HttpServlet
// This will look for a file called “/more/cowbell.properties” relative
// to your servlet Root Context
InputStream is = getServletContext().getResourceAsStream(“/more/cowbell.properties”);
Properties p = new Properties();
p.load(is);
is.close();

12. How can I access members of a custom Realm or Principal?
Answer: When you create a custom subclass of RealmBase or GenericPrincipal and attempt to use those classes in your web app code, you’ll probably have problems with ClassCastException. This is because the instance returned by request.getUserPrincipal() is of a class loaded by the server’s classloader, and you are trying to access it through you webapp’s classloader. While the classes may be otherwise exactly the same, different (sibling) classloaders make them different classes.
This assumes you created a My“Principal class, and put in Tomcat’s server/classes (or lib) directory, as well as in your webapp’s webinf/classes (or lib) directory. Normally, you would put custom realm and principal classes in the server directory because they depend on other classes there.
Here’s what you would like to do, but it throws ClassCastException:
principal p = request.getUserPrincipal(); String emailAddress = p.getEmailAddress(); Here are 4 ways you might get around the classloader boundary:
1) Reflection
Principal p = request.getUserPrincipal();
String emailAddress = p.getClass().getMethod(“getEmailAddress”, null).invoke(p, null);
2) Move classes to a common classloader
You could put your custom classes in a classloader that is common to both the server and your web app – e.g., either the “common” or bootstrap classloaders. To do this, however, you would also need to move the classes that your custom classes depend on up to the common classloader, and that seems like a bad idea because of there a many of them and they a core server classes.
3) Common Interfaces
Rather than move the implementing custom classes up, you could define interfaces for your customs classes and put the interfaces in the common directory. You’re code would look like this:
public interface MyPrincipalInterface extends java.security.Principal {
public String get email address();
public class MyPrincipal implements MyPrincipalInterface {
public String get email address() {
return emailAddress;
public class MyServlet implements Servlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
MyPrincipalInterface p = (MyPrincipalInterface)request.getUserPrincipal();
String emailAddress = p.getEmailAddress();
Notice that this method gives you pretty much the web app code you wanted in the first place
4) Serializing / Deserializing
You might want to try serializing the response of ‘request.getUserPrincipal()’ and deserialize it to an instance of [webapp]MyPrincipal.

13. Suppose when we are starting startup.bat file of Tomcat server it is not started. DOS window appears for a Second only. What do we need to do?
Answer: 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. ( tableau training online )

14. How do I use DataSources with Tomcat?
Answer: 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:

15. How do I configure Tomcat to work with IIS and NTLM?
Answer: 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:

16. What Is Webservers? Why It Is Used?
Answer: Transaction with HTTP request and the HTTP response is called webserver.
Using the internet listening to 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.

17. Explain Directory Structure Of Tomcat?
Answer: 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 here is server.xml. It is the main configuration file for the container.
lib – contains JARs that are used by container and Servlet and JSP application programming interfaces (APIs).
logs – Log and output files.
web-apps – 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. 

18. How To We Can Change Tomcat Default Port?
Answer: 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.

19. How to use tomcat server as an HTTP server?
Answer: Tomcat also contains an HTTP connector which can be used to serve static HTML pages. The standard directory which will be served is below the Tomcat web apps/ROOT installation directory. Place static content into this directory.
To allow directory browsing via Apache Tomcat change the listings parameter in the file conf/web.xml from false to true.
default
org.apache.catalina.servlets.DefaultServlet
debug 0
listings true
Tomcat training

20. Difference between the web server and application server?
Answer:
1. Application Server supports the distributed transaction and EJB.
While Web Server only supports Servlets and JSP.
2. Application Server can contain a web server in them. most of the App server e.g. JBoss or WAS has
Servlet and JSP container.
3. Though it’s not limited to Application Server they used to provide services like Connection
pooling, Transaction management, messaging, clustering, load balancing, and persistence. Now
Apache tomcat also provides connection pooling.
4. In terms of the logical difference between the web server and application server. webserver is supposed
to provide Http protocol level service
while application server provides support to web service and expose business-level service
e.g. EJB.
5. The application server is more heavy than the web server in terms of resource utilization.

21. How do I override the default home page loaded by Tomcat?
Answer: After successfully installing Tomcat, you usually test it by loading
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:
index.html
index.htm
index.jsp
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/web apps/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 like:
This change takes effect immediately and does not require a restart of Tomcat.

22. Explain how running Tomcat as a windows service provides benefits?
Answer: Running Tomcat as a windows service provides benefits like
Automatic startup: It is crucial for the 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. ( devops training online  )

23. Explain how you can configure Tomcat to work with IIS and NTLM?
Answer: You have to follow the standard instructions for when the isapi_redirector.dll
Configure IIS to use “integrated windows security”
Ensure that in the server.xml you have disabled tomcat authentication

24. Mention what is the output of select * from tab?
Answer:
It displays the default tables in the database.

25. Explain how servlet life cycles?
Answer:
The life-cycle of a typical servlet running on Tomcat
Tomcat 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 to destroy method.

26. How will you create a database connection pool in Tomcat server?
Answer: The steps to configure the connection pool:
1) Configure pool in context.xml inside the conf folder of tomcat.
2) Perform a JNDI lookup of the pool and get a connection from the data source.
The JDBC connection pooling page shows how one can create a connection pool in the tomcat server.

27. Suppose there is a clash between the version of the library being shipped with your application and the library of Tomcat, How will you resolve it?
Answer: There should be only one jar file for a particular library and if there is a clash, you should be using the version of the library provided by the server which can avoid problems arising when deploying the application on client machines. Company

28. Will you classify Tomcat as a web server or application server?
Answer: 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. 

29. Why is Tomcat not an application server?
Answer: Application server is a 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.

30. How would you set up tomcat for remote debugging?
Answer: In windows environment, open up your startup.bat and add to file somewhere in the beginning
rem Set the remote debugger
set JPDA_ADDRESS=8001
set JPDA_TRANSPORT=dt_socket
echo Remote debugging started’

31. What is different between the web server and application server?
Answer: The basic difference between a web server and an
the application server is Web server 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.
The 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, transaction demarcation, etc.

32. How the webserver handles multiple requests for the same action class(Struts) concurrently?
Answer: Struts or any web server makes a new thread for each new request. so multiple requests are served with the new request object.

33. How can one enable Hot Deployment in Tomcat?
Answer: For enabling the hot deployment, follow the official guide by Apache at configuring tomcat hot deployment. ( data science online training )

34. What are the steps to enable SSL in a web application deployed on Tomcat?
Answer: Read this excellent tutorial on enabling SSL in a web application deployed on tomcat. ( hadoop training videos )

35. What all services are provided by Tomcat?
Answer: 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.

36. Mention with how many valves does Tomcat configured with?
Answer: Four types of valves Tomcat is configured with
Access Log
Remote Address Filter
Remote Host Filter
Request Dumper

37. Explain what is the purpose of NAT protocol?
Answer: The purpose of NAT protocol is to hide private IP address from public IP address and give a certain level of security to the organization.

38. What are the steps to configure clustering in Tomcat server?
Answer: Apache Tomcat wiki lists down the steps for configuring clustering in the guide at Tomcat server clustering. ( python online training  )

39. What Is Apache Tomcat?
Answer: 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.

40. Explain What Is Tomcat Coyote?
Answer: Tom coyote is an HTTP connector based on HTTP/ 1.1 specification which receives and transport web requests to the Tomcat engine by listening to a TCP/IP port and sent a request back to the requesting client.

41. Why is a new object created whenever I call JSP: use Bean?
Answer: You probably forgot to specify a scope for the bean. Remember, the default scope for a bean is page, and all beans with page scope disappear when the page finishes executing.

42. Can I set Java system properties differently for each web app?
Answer: 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 web app’s context.

43. Why do I get a Class Not Found Exception when I try to use the Shopping Cart class?
Answer: The JSP engine probably can’t see the class in its classpath. Tomcat uses the system classpath, so if ShoppingCart.class is visible somewhere in the system classpath, they should see it.

44. When do I use? and when do I use?
Answer: Although you can use these operators interchangeably, it is a good idea to use an operator that indicates the kind of data being accessed. For example, if you are accessing a bean property, use the. operator. If you are accessing a map value or an array index, use the operator. There are plenty of times when you break this rule, especially in cases where you want a map to look like it is a bean, you want things to make sense to the next person who reads your code. You may know the types of all the variables, but the next person may not. ( data science training )

Note: Browse latest Apache Tomcat Interview Questions and Tomcat Tutorial Videos. Here you can check Tomcat Training details and Tomcat Training Videos for self learning. Contact +91 988 502 2027 for more information.

Leave a Comment

Scroll to Top