The Jakarta Project
      Tomcat FAQ

Links

Contents

Tomcat FAQ

Miscellaneous Questions

Printer Friendly Version
print-friendly
version
Preface
This section contains various miscellaneous questions that are asked frequently enough to be listed here.
Questions

Answers
I'm having a problem with character encoding in tomcat 5.
In Tomcat 5 - there have been issues with respect to character encoding. ( Usually of the the form "request.setCharacterEncoding(String) doesn't work" ) Odds are, its not a bug. Before filing a bug report, see these bug reports as well as any bug reports linked to these bug reports: 23929, 25360, 25231, 25235, 22666, 24557, 24345, 25848

I have a problem with webapp reloading in tomcat 4.1.27.
Update to a later tomcat version, preferably the latest stable one. If you must stay with 4.1.27, get this hotfix: Bugzilla 22096.

I am unable to compile my JSP!
Are you seeing this?
      org.apache.jasper.JasperException: Unable to compile
      class for JSP

      An error occurred at line: -1 in the jsp file: null

      Generated servlet error:
          [javac] Since fork is true, ignoring compiler
      setting.
          [javac] Compiling 1 source file
         [javac] Since fork is true, ignoring compiler
      setting.

    
If so, here is some solutions: In the case of the Environment issues, it is typical that on Windows, the startup scripts work fine and the service does not. The service uses registry values to look for java and other "stuff". To save yourself some trouble, see if the NT Service Config Utility is helpful.

I can't get servlets to work under /servlet/*!
Using /servlet/ to map servlets is evil, absolutely evil. Even more evil than this . That being said, here are some threads that may answer this:

For another explanation of the invoker servlet, why it's evil, and what to do about it, see JavaRanch FAQ.

Why is the invoker evil?
This is opinions of the writer (YMMV)
Quickie about the invoker: The invoker is a dynamic servlet which allows run-time loading of other servlets based on class name. This servlet is the one that allows http://localhost/servlet/com.foo.MyClass?more=cowbell, where com.foo.MyClass is some class which can be loaded as a servlet but was never explicitly declared in a config file.

Evil because:
  • Security risk ... see links above
  • Configuration hiding - There is NO way to determine which servlets are used vs which are not used. In web.xml, every servlet is declared and mapped. In that one file you instantly have a road map to how the webapp works.
  • Back doors. Servlets which are mapped can be alternately called via the invoker by class name. Since the URL is different, all security constraints might be ignored since the URL pattern is VERY different.
  • Back doors. Bad programmers make it easier to do bad things.
  • Back doors. It may be common to use common 3rd party jars in a shared area. If that shared jar has servlets in them and that servlet has a hole in it, bad things happen.
  • Configuration hiding - it's important enough to say twice. Explicit declaration while a PITA, will be more helpful in the maintenance scheme of your webapp.


For another explanation of the invoker servlet, why it's evil, and what to do about it, see JavaRanch FAQ.

How to I get Tomcat's version number?
javax.servlet.ServletContext.getServerInfo();

Tomcat eats 100% of the CPU!
Odds are, it might be the garbage collector going wacky.

In 1.4.1 JVMs there is a memory leak which could hampering the garbage collector. More information Otherwise - get a memory profiler and/or tweak your memory settings.

How do I set system properties at startup?
Set JAVA_OPTS to be something BEFORE calling startup.bat or before calling catalina.bat. (or you can edit those files, but it isn't advised)

Example (windows): SET JAVA_OPTS='-DpropName=propValue'

Example (UNIX): export JAVA_OPTS='-DpropName=propValue'

Windows service users - use this

How do I get a customized error page?
In web.xml ...
        <error-page>
            <error-code>404</error-code>
            <location>/error/404.html</location>
        </error-page>
    
You may also catch error 500's as well as other specific exceptions or exceptions which extend Throwable.
For more information, see the Servlet Specification for all the gory details of how you can play with this.

Should I use the LE version?
No. It was an experiment, it failed. (YMMV) The original purpose of LE was because jdk1.4 provides a LOT of standard functionality that Tomcat uses that was not in jdk1.3. So to save some space two distributions were made to save some bandwidth. Since then, it has been an exercise in confusion. (Flame me if you disagree) More info

How do I configure Tomcat to NOT to store the sessions during shutdown?
How do I disable tag pooling?
To disable tag pooling: See $TOMCAT_HOME/conf/web.xml --> enablePooling=false for the jsp servlet declaration.

Is there a DTD for server.xml?
No! Nor can one accurately exist. Here's why

How do I change the welcome file? ( I want to show index.jsp instead of index.html)
This is done in web.xml by changing welcome-files-list. More detail.

How do I enable/disable directory listings?
This is done in TOMCAT_HOME/conf/web.xml by changing the listings property for the default servlet.

How do I make Tomcat listen on a specific IP address instead of all available addresses?
RTFM! [Add the property address='127.0.0.1' to your Connector config.] For more detail: JK, http (legacy), http (coyote).

How do I use symbolic links with jars?
You'll need to tweak with server.xml and do this. (Don't worry - its really easy!)

How do I get UTF-8?
This thread should answer that.

How do I change the name of the file in the download Save-As dialog from a servlet? (or jsp)
Use the Content-Disposition header.

Is tag pooling broken? It doesn't call release!
It is not broken, your tag probably is. Many bug reports have been filed about this. Here is the bug report with all the gory details.

Why do I get java.lang.IllegalStateException?
These are the most common reasons how you can get an java.lang.IllegalStateException:
  • Calling setBufferSize and content has been written.
  • The response has been committed and you do any of the following:
    • Calling ServletResponse.reset() or ServletResponse.resetBuffer()
    • Calling either HttpServletResponse.sendError() or HttpServletResponse.sendRedirect().
    • Calling RequestDispatcher.forward() which includes performing a jsp:forward
    • Calling RequestDispatcher.forward() which includes performing a jsp:forward
Remember that if you call forward() or sendRedirect(), any following lines of code will still execute. For example:
{
  ...
  response.sendRedirect("foo.jsp");
  // At this point, you should probably have a return statement otherwise
  // the following code will run
  System.out.println("After redirect! By the way ...");
  System.out.println("Use commons-logging or log4j, not System.out");
  System.out.println("System.out is a bad practice!");

  response.sendRedirect("bar.jsp"); /* This will throw an error! */

}
    

How do I make a scheduled event on Tomcat?
Tomcat does not support this directly. Its not part of the Servlet or JSP Specification.
If you do need this functionality see this thread or this link.

What is Element "web-app" does not allow "servlet" here?
Your web.xml is not well formed or it is not conforming to the DTD as defined by the servlet spec. Use an XML validator to ensure your web.xml file is ok.

Where does System.out go?
How do I rotate catalina.out?
System.out and System.err both print to catalina.out. But you can suppress this via the swallowOutput property and sent to different log files.
catalina.out does not rotate. But it should not be an issue because nothing should be printing to standard output since you are using a logging package, right? A log4j example and a thread about rotation of catalina.out

How do open a file for reading in my webapp?
Use ServletContext.getResourceAsStream().

Can I run tomcat with the JRE, or do I need the full JDK?
Tomcat officially requires the full JDK, because it needs javac in order to compile JSPs. If you pre-compile all your JSPs, you can get away with running tomcat on a JRE only, but you do so at your own risk.

Is tomcat an EJB server? Can I use EJBs with tomcat?
Tomcat is not an EJB server. Tomcat is not a full J2EE server. Tomcat is a Servlet container. Tomcat does support those parts of the J2EE specification that are required for Servlets, such as a subset of JNDI functionality. Furthermore, you can connect to remote J2EE servers, or run tomcat embedded inside a full J2EE server.

Can I access Tomcat's JNDI provider from outside tomcat?
Not at this time.

Who uses tomcat in production?
Numerous organizations across various industries all over the world. Examples includes: This list is limited mostly by our free time. There are numerous other examples and references available by searching online, and undoubtedly many cases where the organization does not want to reveal it's using tomcat for various (e.g. security) reasons. (This is true for many software products, not just tomcat). We'll keep adding to the list, but please let us know (by sending a message to tomat-user@jakarta.apache.org) if your site is using tomcat in production.

How do I configure commons-logging and log4j in tomcat 5?
See this mailing list message. For an example with log4j and tomcat running with JSVC (port 80), see this thread.


Copyright © 1999-2003, Apache Software Foundation