Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Tomcat Interview Questions and Answers

Related differences

Jboss vs Tomcat

Ques 1. What is Tomcat?

  • Tomcat is a Java Servlet container and web server from the Jakarta project of the Apache software foundation.
  • A web server responds with web pages to requests from client browsers.
  • Web servers can provide dynamic content based on the requests sent by the user.
  • Tomcat is very good to provide dynamic content because it provides both Java servlet and JavaServerPages (JSP) technologies.
  • Tomcat can also be used as a web server for many applications even if free servlet and JSP engine is wanted.
  • 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.

Is it helpful? Add Comment View Comments

Ques 2. What is Jasper?

  • Jasper is Tomcat's JSP Engine. Tomcat 5.x uses Jasper 2, which is an implementation of the Sun Microsystems's JavaServer Pages 2.0 specification.
  • Jasper parses JSP files to compile them into Java code as servlets (that can be handled by Catalina).
  • At runtime, Jasper is able to automatically detect JSP file changes and recompile them.

Is it helpful? Add Comment View Comments

Ques 3. Explain the concepts of Tomcat Servlet Container.

  • A servlet container is a specialized web server that supports servlet execution.
  • It combines the basic functionality of a web server with certain Java/servlet specific optimizations and extensions (such as an integrated Java runtime environment, and the ability to automatically translate specific URLs into servlet requests).
  • Individual servlets are registered with a servlet container, providing the container with information such as the functionality, the URL used for identification.
  • The servlet container then initializes the servlet as necessary and delivers requests to the servlet as they arrive.
  • Many containers can dynamically add and remove servlets from the system, allowing new servlets to quickly be deployed or removed without affecting other servlets running from the same container.
  • Servlet containers are also referred to as web containers or web engines.

Is it helpful? Add Comment View Comments

Ques 4. What is WebServers? Why it is used?

Transaction with HTTP request and HTTP response is called webserver.
rnUsing 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.

Is it helpful? Add Comment View Comments

Ques 5. 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: 

<?xml version="1.0" encoding="UTF-8"?> 
<Resource name="jdbc/WallyDB" auth="Container" 
type="javax.sql.DataSource" username="wally" password="wally" 
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: 

InitialContext ic = new InitialContext(); 
DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/WallyDB"); 
Connection c = ds.getConnection(); 
Notice that, when doing the DataSource lookup, you must prefix the JNDI name of the resource with java:comp/env/

Is it helpful? Add Comment View Comments

Most helpful rated by users:

©2024 WithoutBook