Tomcat Interview Questions and Answers

How do you create multiple virtual hosts?

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

0. create ${catalina.home}/www/appBase , ${catalina.home}/www/deploy, and ${catalina.home}/conf/Catalina/

1. add a host entry in the server.xml file
  <Host appBase="www/appBase" name=""/>

2. Create the the following file under conf/Catalina/
<?xml version="1.0" encoding="UTF-8"?>
    reloadable="true" antiJARLocking="true">
Add any parameters specific to this hosts webapp to this context file

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

How will you load properties file?

    * 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 update the file without having to reload the webapp 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/" relative
                    // to your servlet Root Context
                   InputStream is = getServletContext().getResourceAsStream("/more/");
                   Properties  p  = new Properties();

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.

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:

<Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" tomcatAuthentication="false" />

Tomcat -2