Versions Compared

Key

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

...

This section contains various miscellaneous questions that are asked frequently enough to be listed here.

Questions

  1. Wiki Markup\[#Q1 I am unable to compile my JSP!\]unmigrated-wiki-markup
  2. \[#Q2 I can't get servlets to work under /servlet/\*!\]
  3. Wiki Markup\[#Q3 Why is the invoker evil?\]unmigrated-wiki-markup
  4. \[#Q4 How to I get Tomcat's version number?\]
  5. Wiki Markup\[#Q5 Tomcat eats 100% of the CPU!\]unmigrated-wiki-markup
  6. \[#Q6 How do I get a customized error page?\]
  7. Wiki Markup\[#Q7 Should I use the LE version?\]
  8. Wiki Markup
    \[#Q8 How do I configure Tomcat to NOT to store the sessions during shutdown?\]
  9. Wiki Markup
    \[#Q9 How do I disable tag pooling?\]
  10. Wiki Markup
    \[#Q10 Is there a DTD for server.xml?\]
  11. Wiki Markup
    \[#Q11 How do I change the welcome file? ( I want to show index.jsp instead of index.html)\]
  12. Wiki Markup
    \[#Q12 How do I enable/disable directory listings?\]
  13. Wiki Markup
    \[#Q13 How do I use symbolic links with jars?\]
  14. Wiki Markup
    \[#Q14 How do I change the name of the file in the download Save-As dialog from a servlet? (or jsp)\]
  15. Wiki Markup
    \[#Q15 Is tag pooling broken? It doesn't call release!\]
  16. Wiki Markup
    \[#Q16 Why do I get java.lang.IllegalStateException ?\]
  17. Wiki Markup
    \[#Q17 How do I make a scheduled event on Tomcat?\]
  18. Wiki Markup
    \[#Q18 What is Element "web-app" does not allow "servlet" here?\]
  19. Wiki Markup
    \[#Q19 How do I open a file for reading in my webapp?\]
  20. Wiki Markup
    \[#Q20 Can I run tomcat with the JRE, or do I need the full JDK?\]
  21. Wiki Markup
    \[#Q21 Is tomcat an EJB server? Can I use EJBs with tomcat?\]
  22. Wiki Markup
    \[#Q22 Can I access Tomcat's JNDI provider from outside tomcat?\]
  23. Wiki Markup
    \[#Q23 Who uses tomcat in production?\]
  24. Wiki Markup
    \[#Q24 I'm getting java.lang.ThreadDeath exceptions when reloading my webapp.\]
  25. Wiki Markup
    \[#Q25 Help! Even though I run shutdown.sh (or shutdown.bat), Tomcat does not stop!\]
  26. Wiki Markup
    \[#Q26 How do I debug JSP errors in the Admin web application?\]
  27. Wiki Markup
    \[#Q27 What order do webapps start (or How can I change startup order)?\]
  28. Wiki Markup
    \[#Q28 What's the different between a Valve and Filter?\]
    \\

...

  1. How do I configure Tomcat to NOT to store the sessions during shutdown?
  2. How do I disable tag pooling?
  3. Is there a DTD for server.xml?
  4. How do I change the welcome file? ( I want to show index.jsp instead of index.html)
  5. How do I enable/disable directory listings?
  6. How do I use symbolic links with jars?
  7. How do I change the name of the file in the download Save-As dialog from a servlet? (or jsp)
  8. Is tag pooling broken? It doesn't call release!
  9. Why do I get java.lang.IllegalStateException ?
  10. How do I make a scheduled event on Tomcat?
  11. What is Element "web-app" does not allow "servlet" here?
  12. How do I open a file for reading in my webapp?
  13. Can I run tomcat with the JRE, or do I need the full JDK?
  14. Is tomcat an EJB server? Can I use EJBs with tomcat?
  15. Can I access Tomcat's JNDI provider from outside tomcat?
  16. Who uses tomcat in production?
  17. I'm getting java.lang.ThreadDeath exceptions when reloading my webapp.
  18. Help! Even though I run shutdown.sh (or shutdown.bat), Tomcat does not stop!
  19. How do I debug JSP errors in the Admin web application?
  20. What order do webapps start (or How can I change startup order)?
  21. What's the different between a Valve and Filter?

Answers

Anchor
Q1
Q1
I am unable to compile my JSP!

...

If so, here is some solutions:

...

  • \[http://marc.theaimsgroup.com/?l=tomcat-user&m=104949554010352&w=2 Environment variable issue\]
  • Wiki Markup
    \[http://issues.apache.org/bugzilla/show_bug.cgi?id=16688 Environment issue\] or \[http://issues.apache.org/bugzilla/show_bug.cgi?id=20527 Ant issue\]
  • Wiki Markup
    Others have had success by added JAVA_HOME/bin to their PATH. \[http://marc.theaimsgroup.com/?l=tomcat-user&m=105525594928279&w=2 1\] ... \[http://marc.theaimsgroup.com/?l=tomcat-user&m=105526353505541&w=2 2\] and make sure you are using the full JDK and not the JRE.
    \\

Wiki Markup
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 \[http://web.bvu.edu/staff/david/tcservcfg/ NT Service Config Utility\] is helpful.

I can't get servlets to work under /servlet/*!

Wiki Markup
Using /servlet/ to map servlets is evil, absolutely evil. Even more evil than \[http://www.eviloverlord.com/lists/overlord.html this\] . That being said, here are some threads that may answer this:

...

Wiki Markup
\[http://marc.theaimsgroup.com/?l=tomcat-user&m=103417249925541&w=2 (SECURITY) Apache Tomcat 4.x JSP source disclosure\] vulnerability

...

Wiki Markup
\[http://marc.theaimsgroup.com/?t=103945337100003&r=1&w=2 Cannot Run Servlets, only JSP's, Part II\]

...

  • Environment issue or Ant issue
  • Others have had success by added JAVA_HOME/bin to their PATH. 1 ... 2 and make sure you are using the full JDK and not the JRE.

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.

Anchor
Q2
Q2
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:

Anchor
Q3
Q3
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.

...

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

Wiki MarkupFor another explanation of the invoker servlet, why it's evil, and what to do about it, see \[http://test.javaranch.com/wiki/view?InvokerServlet JavaRanch FAQ\]..

Anchor
Q4
Q4
How to I get Tomcat's version number?

...

Starting with tomcat 5.0.28 - there is now a version.sh (or version.bat) program in the bin directory. It will print the version number of tomcat to Standard output..

Anchor
Q5
Q5
Tomcat eats 100% of the CPU!

Odds are, it might be the garbage collector going wacky.

Wiki MarkupIn 1.4.1 JVMs there is a memory leak which could hampering the garbage collector. \[http://developer.java.sun. com/developer/bugParade/bugs/4724129.html 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 (UNIX): export JAVA_OPTS='-DpropName=propValue'unmigrated-wiki-markup

Windows service users - use \[http://web.bvu.edu/staff/david/tcservcfg/ this\] this

Anchor
Q6
Q6
How do I get a customized 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.

Anchor
Q7
Q7
Should I use the LE version?

Wiki MarkupNo. It was an experiment, it failed. (YMMV) The original purpose of LE "light" edition of Tomcat 4.0, 4.1 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) \[http://marc.theaimsgroup.com/?l=tomcat-user&m=105341005928071&w=2 More info\]info

Anchor
Q8
Q8
How do I configure Tomcat to NOT to store the sessions during shutdown?unmigrated-wiki-markup

\[http://tomcat.apache.org/tomcat-4.1-doc/config/manager.html Look at the Session manager component and tweak accordingly. One way is to tell tomcat to persist sessions to a path which does not exist. (So tomcat will not store, or be able to load the sessions)\]

Anchor
Q9
Q9
How do I disable tag pooling?

To disable tag pooling: See $TOMCAT_HOME/conf/web.xml --> enablePooling=false for the jsp servlet declaration.unmigrated-wiki-markup

*_Note_:* This option, as well as most other configuration options of \[http://tomcat.apache.org/tomcat-6.0-doc/jasper-howto.html JspServlet\], affects code generation and compilation of JSP pages. It will not alter the behavior of JSPs that have already been compiled.as well as most other configuration options of JspServlet, affects code generation and compilation of JSP pages. It will not alter the behavior of JSPs that have already been compiled.

Anchor
Q10
Q10
Is there a DTD for server.xml?unmigrated-wiki-markup

No! Nor can one accurately exist. \[http://marc.theaimsgroup. com/?l=tomcat-user&m=104205666221372&w=2 Here's why\]why

Anchor
Q11
Q11
How do I change the welcome file? ( I want to show index.jsp instead of index.html)unmigrated-wiki-markup

This is done in web.xml by changing welcome-files-list. \[http://marc.theaimsgroup.com/?l=tomcat-user&m=104566785828794&w=2 More detail\].welcome-files-list. More detail.

Anchor
Q12
Q12
How do I enable/disable directory listings?

...

No Format
   <servlet>
       <servlet-name>listing</servlet-name>
       <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
       <init-param>
           <param-name>debug</param-name>
           <param-value>0</param-value>
       </init-param>
       <init-param>
           <param-name>listings</param-name>
           <param-value>true</param-value>
       </init-param>
       <load-on-startup>1</load-on-startup>
   </servlet>

   <servlet-mapping>
       <servlet-name>listing</servlet-name>
       <url-pattern>/</url-pattern>
   </servlet-mapping>

Anchor
Q13
Q13
How do I use symbolic links with jars?unmigrated-wiki-markup

You'll need to tweak with server.xml and \[http://marc.theaimsgroup.com/?l=tomcat-user&m=105159411609623&w=2 do this\]. need to tweak with server.xml and do this. (Don't worry - its really easy!)

Anchor
Q14
Q14
How do I change the name of the file in the download Save-As dialog from a servlet? (or jsp)

Use the Wiki MarkupUse the \[http://www.onjava.com/pub/a/onjava/excerpt/jebp_3/index3.html Content-Disposition\] header.

Anchor
Q15
Q15
Is tag pooling broken? It doesn't call release!

Wiki MarkupIt is not broken, your tag probably is. Many bug reports have been filed about this. \[https://issues.apache.org/bugzilla/show_bug.cgi?id=16001 Bug 16001\] has all the gory details.

Anchor
Q16
Q16
Why do I get java.lang.IllegalStateException ?

...

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

}
}}}

Anchor
Q17
Q17
How do I make a scheduled event on Tomcat?

Wiki MarkupTomcat does not support this directly. Its not part of the Servlet or JSP Specification. If you do need this functionality see \[http://marc.theaimsgroup.com/?t=106192918700004&r=1&w=2 this thread\] or \[http://marc.theaimsgroup.com/?l=tomcat-user&m=106157051231075&w=2 this link\].JSP Specification. If you do need this functionality see this thread or this link.

Anchor
Q18
Q18
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.

Anchor
Q19
Q19
* How do open a file for reading in my webapp?*

Use ServletContext.getResourceAsStream()

Anchor
Q20
Q20
Can I run tomcat with the JRE, or do I need the full JDK?

Tomcat 4 requires the full JDK. Tomcat 5.5 onwards will work with a JRE or a JDK.

Anchor
Q21
Q21
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.

Anchor
Q22
Q22
Can I access Tomcat's JNDI provider from outside tomcat?

Not at this time.

Anchor
Q23
Q23
Who uses tomcat in production?unmigrated-wiki-markup

Numerous organizations across various industries all over the world. A full listing can be found at the \[http://wiki.apache.org/tomcat/PoweredBy Wiki\].

Anchor
Q24
Q24
I'm getting java.lang.ThreadDeath exceptions when reloading my webapp.

Wiki MarkupSee \[http://issues.apache.org/bugzilla/show_bug.cgi?id=26372 Bugzilla discussion\] of this.

Anchor
Q25
Q25
Help! Even though I run shutdown.sh (or shutdown.bat), Tomcat does not stop!

Wiki Markup
Most likely, a non-daemon thread is running. JVM's do not shutdown until there are 0 non-daemon threads. You will need to perform a thread dump \[kill -3 pid for Unix or CTRL+Break for Windows\] to determine the code which started the thread.

Anchor
Q26
Q26
How do I debug JSP errors in the Admin web application?

...

  1. Download Tomcat's base and admin webapp distributions (binaries), unzip to a directory of your choice. We'll use c:\temp in this example. 2. Edit c:\temp\server\webapps\admin\WEB-INF\web.xml to remove the JSPC-generated servlet mappings. These are marked in the web.xml file with comments indicating the beginning and end of the JSPC section. You can simply comment out all these servlet-mappping elements. Be careful not to comment out other servlet mappings such as the Struts dispatcher servlet. 3. Open c:\temp\server\webapps\admin\WEB-INF\lib\catalina-admin.jar with a zip file program like WinZip. Remove the files named *_jsp.class, as these are the compiled JSPs. Do not remove the other class files, the ones under the org/apache/ paths. 4. Download a Tomcat source distribution and unzip it to a directory of your choice, but not the same directory that you used above. We'll use c:\src in this example. 5. Copy everything except the WEB-INF/lib directory from c:\src\container\webapps\admin to c:\temp\server\webapps\admin. Now you will have the uncompiled admin webapp JSPs. 6. If you haven't already, define an admin user in %CATALINA_HOME%\conf\tomcat-users.xml. 7. Start Tomcat, navigate to http://localhost:8080 (or your actual server:port if you have modified the default values), and access the admin web application. It will run slower because Tomcat is now compiling the JSPs on-demand the first time you access them, but should otherwise appear normal.

Anchor
Q27
Q27
What order do webapps start (or how can I change startup order)?

There is no expected startup order. Neither the Servlet spec nor Tomcat define one. You can't rely on the apps starting in any particular order.

Anchor
Q28
Q28
What's the different between a Valve and Filter?

...