Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Preface

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

Questions

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

Answers

Anchor
Q1
Q1
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 are 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.

...

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

...

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

...

If you want to enable it for an individual webapp, then you need to add something similar to the following to your web.xml file (for your individual app):

...

...

   <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?

...

  • 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!");

...

While the above statement is certainly true, there is a potential "workaround":
If you actually have two (or more) apps depending on each other, you may decide to start multiple services in you server.xml:

...

<Service name="Webapps1">
  <Connector .../>

  <Engine ...>
     <Host appbase="webapps1" ...>
       ...        
     </Host>
  </Engine>
</Service>
<Service name="Webapps2">
  <Connector .../>

  <Engine ...>
     <Host appbase="webapps2" ...>
       ...        
     </Host>
  </Engine>
</Service>

...

I.e. you split the regular "/webapps" directory into "/webapps1" and "/webapps2", whereas everything in the former is deployed and started before the later. The drawback is that you need separate ports for the services.

...

Windows service users - use thisCategoryFAQ