Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: converted to 1.6 markup

*Originally taken from: http://wiki.apache.org/jakarta-tomcat/Tomcat/Howto*

...

Contents TableOfContents

Table of Contents

...

How do I add a question to this page?

Anyone may edit this page to add their own content. That is why this page is part of a Wiki and not a hardcoded static file in the FAQ.

Wiki MarkupHowever, _do not_ add questions without answers to this page. If you have a question about how to do something in Tomcat which has not been addressed yet, ask the \[http://jakarta.apache.org/tomcat/faq/tomcatuser.html tomcat-user list\]. Once you've figured out how to fix your problem, come back and update the Wiki to allow the rest of us to benefit from what you've learned!

How do I set up and run Tomcat on Macintosh OS X?

...

See \["TomcatOnMacOS"\]

How do I set up multiple sites sharing the same war application/war file?

...

In particular, here are a number of locations for Tomcat Connectors:

The following excellent article was written by Mladen Turk. He is a Developer and Consultant for JBoss Inc in Europe, where he is responsible for native integration. He is a long time commiter for Jakarta Tomcat Connectors, Apache Httpd and Apache Portable Runtime projects.

...

...


John Turner has an excellent page about \[http://johnturner.com/howto/apache-tomcat-howto.html Using Apache HTTP with Apache Tomcat\]. Several different connectors have been built, and some connector projects have been abandoned (so beware of old documentation).

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

Wiki MarkupSee \["TomcatNTLM"\]

Tomcat crashed! What do I do now?

...

How do I share sessions across web apps?

Wiki MarkupYou cannot share sessions directly across web apps, as that would be a violation of the Servlet Specification. There are workarounds, including using a singleton class loaded from the common classloader repository to hold shared information, or putting some of this shared information in a database or another data store. Some of these approaches have been discussed on the \[http://jakarta.apache.org/tomcat/faq/tomcatuser.html tomcat-user mailing list\], whose archives you should search for more another data store. Some of these approaches have been discussed on the tomcat-user mailing list, whose archives you should search for more information.

Sharing sessions across containers for clustering or replication purposes is a different matter altogether.

...

Wiki Markup
You might want to try serializing the response of 'request.getUserPrincipal()' and deserialize it to an instance of \[webapp\]MyPrincipal.

Setting up SSL

...

Threads from the \[http://jakarta.apache.org/tomcat/faq/tomcatuser.html tomcat-user list\]

Using VeriSign:

...


Using \["OpenSSL"\]:

...

HowTo SSL Client Authentication with Fallback to FORM Authentication

Wiki MarkupSee \["SSLWithFORMFallback"\]

How do I set up another tomcat service on Windows, sharing the same Tomcat Home ?

Wiki MarkupThis script sets up a a tomcat base directory and calls tomcat5.exe to create a windows service which will use the tomcat home given for the binaries and tomcat base you create See \["TomcatCreateWindowsService"\]

How do I install Tomcat as a service under Unix?

...

How do I make Tomcat startup faster?

...

See \["HowTo / FasterStartUp"\]

How do I contribute to Tomcat's documentation?

...

How do I edit the default JSP home page loaded by Tomcat?

...

See \["EditDefaultJSPPage"\]

How do I redirect System.out and System.err to my web page?

...

  • Use your IDE to connect to Tomcat through port 1044

Wiki MarkupIf Eclipse happens to be your IDE of choice, you can get more information at \[http://www.jacoozi.com/index.php?option=com_content&task=view&id=119&Itemid=134 Remote Debugging with Eclipse (Jacoozi Article)\].

How do I debug a Tomcat application when Tomcat is run as a Windows service ?

...

  • Click on "Apply" and close the dialog by clicking on "OK"
  • Restart the Apache Tomcat service
  • Use your IDE to connect to Tomcat through port 1044

...


If Eclipse happens to be your IDE of choice, you can get more information at \[http://www.jacoozi.com/index.php?option=com_content&task=view&id=119&Itemid=134 Remote Debugging with Eclipse (Jacoozi Article)\]. For IntelliJ IDEA you choose a remote debug target and set transport to "socket" and mode to "attach" , then you specify the host (127.0.0.1) and port (1044)

How do I enable Server Side Includes (SSI)?

...

No Format
    <servlet>
        <servlet-name>ssi</servlet-name>
        <servlet-class>
          org.apache.catalina.ssi.SSIServlet
        </servlet-class>
        <init-param>
          <param-name>buffered</param-name>
          <param-value>1</param-value>
        </init-param>
        <init-param>
          <param-name>debug</param-name>
          <param-value>0</param-value>
        </init-param>
        <init-param>
          <param-name>expires</param-name>
          <param-value>666</param-value>
        </init-param>
        <init-param>
          <param-name>isVirtualWebappRelative</param-name>
          <param-value>0</param-value>
        </init-param>
        <load-on-startup>4</load-on-startup>
    </servlet>

Wiki Markupadditional information can be found at: \[
http://tomcat.apache.org/tomcat-5.5-doc/ssi-howto.html\]

How do I connect to a Websphere MQ (MQ Series) server using JMS and JNDI?

...

Basically, this works just as described in \[http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html\]: Within your application, you are using the standard JNDI and JMS API calls. In web.xml (the container independent application descriptor), you specify resource references (stub resources). And in context.xml (the container specific application descriptor), you are actually configuring the JMS connection.

More to the point. Here's some example code, which might be added to a Servlet. The example is sending a message to an MQ server:

...

Wiki Markup
The pages and code of your "mywebapp" application currently reside in (CATALINA_BASE)/webapps/mywebapp/. In a standard Tomcat installation, you will notice that under the same directory (CATALINA_BASE)/webapps/, there is a directory called ROOT (the capitals are important, even under Windows).  That is the residence of the _current_ Tomcat default application, the one that is called right now when a user calls up "http://myhost.company.com\[:port\]". The trick is to put your application in it's place.

First stop Tomcat.

BR Then before you replace the current default application, it may be a good idea to make a copy of it somewhere else.

BR Then delete everything under the ROOT directory, and move everything that was previously under the (CATALINA_BASE)/webapps/mywebapp/ directory, toward this (CATALINA_BASE)/webapps/ROOT directory. In other words, what was previously .../mywebapp/WEB-INF should now be .../ROOT/WEB-INF (and not .../ROOT/mywebapp/WEB-INF).

...

Restart Tomcat and you're done.

BR Call up "http://myhost.company.com/" and enjoy.

...

The above instructions relate to the situation where you are "manually" deploying your application as a directory-and-files structure under the /webapps directory. If instead you are using the "war" method to deploy your application, the principle is about the same :BR

  • delete the ROOT directoryBR
  • name your war file "ROOT.war" (capitals mandatory)BR
  • drop the ROOT.war file directly in the /webapps directory.BR Tomcat will automatically deploy it./webapps directory.

Tomcat will automatically deploy it.

For more information about this topic in general, consult this page :
The Context Container Wiki MarkupFor more information about this topic in general, consult this page : \[http://tomcat.apache.org/tomcat-6.0-doc/config/context.html The Context Container\]

Addendum 2 : If for some reason you want another method..unmigrated-wiki-markup

If, for some reason, you do not want to deploy your application under the CATALINA_BASE/webapps/ROOT subdirectory, or you do not want to name your war-file "ROOT.war", then read on. But you should first read this : \[http://tomcat.apache.org/tomcat-6.0-doc/config/context.html The Context Container\] and make sure you understand the :
The Context Container and make sure you understand the implications.

The method described above is the simple method. The two methods below are more complex, and the second one has definite implications on the way you manage and run your Tomcat.

...

  • Place your war file outside of CATALINA_BASE/webapps (it must be outside to prevent double deployment).BR
  • Place a context file named ROOT.xml in CATALINA_BASE/conf/<engine name>/<host name>. The single <Context> element in this context file MUST have a docBase attribute pointing to the location of your war file. The path element should not be set - it is derived from the name of the .xml file, in this case ROOT.xml. See the Context Container above for details.

...

  • leave your war file in CATALINA_BASE/webapps, under its original nameBR
  • turn off autoDeploy and deployOnStartup in your Host element in the server.xml file.BR
  • explicitly define all application Contexts in server.xml, specifying both path and docBase. You must do this, because you have disabled all the Tomcat auto-deploy mechanisms, and Tomcat will not deploy your applications anymore unless it finds their Context in the server.xml.

...