Permalink to this page: https://cwiki.apache.org/confluence/x/VColBg
Preface
This section contains various miscellaneous questions that are asked frequently enough to be listed here.
Questions
...
Are you seeing this?
No Format |
---|
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:
Wiki Markup \[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\]
Wiki Markup \[http://marc.theaimsgroup.com/?t=104326854100001&r=1&w=2 Tomcat configuration problem: JSPs work, servlets don\] \\
Why is the invoker evil?
- I can't get servlets to work under /servlet/*!
- Why is the invoker evil?
- How to I get Tomcat's version number?
- Tomcat eats 100% of the CPU!
- How do I get a customized error page?
- Should I use the LE version (of Tomcat 4)?
- How do I configure Tomcat to NOT to store the sessions during shutdown?
- Is there a DTD for server.xml?
- How do I change the welcome file? ( I want to show index.jsp instead of index.html)
- How do I enable/disable directory listings?
- How do I use symbolic links with jars?
- How do I change the name of the file in the download Save-As dialog from a servlet? (or jsp)
- Is tag pooling broken? It doesn't call release!
- How do I disable tag pooling?
- Why do I get java.lang.IllegalStateException ?
- How do I make a scheduled event on Tomcat?
- What is Element "web-app" does not allow "servlet" here?
- How do I open a file for reading in my webapp?
- Can I run Tomcat with the JRE, or do I need the full JDK?
- Is Tomcat an EJB server? Can I use EJBs with Tomcat?
- Can I access Tomcat's JNDI provider from outside Tomcat?
- Who uses Tomcat in production?
- I'm getting java.lang.ThreadDeath exceptions when reloading my webapp.
- Help! Even though I run shutdown.sh (or shutdown.bat), Tomcat does not stop!
- How do I debug JSP errors in the Admin web application?
- What order do webapps start (or How can I change startup order)?
- What's the difference between a Valve and Filter?
- How do I set system properties at startup?
Answers
Anchor | ||||
---|---|---|---|---|
|
Are you seeing this?
No Format |
---|
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:
- Environment variable issue
- 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".
Anchor | ||||
---|---|---|---|---|
|
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:
- (SECURITY) Apache Tomcat 4.x JSP source disclosure vulnerability
- Cannot Run Servlets, only JSP's, Part II
- Tomcat configuration problem: JSPs work, servlets don't
Anchor | ||||
---|---|---|---|---|
|
This is opinions of the writer (YMMV) Quickie about the invoker: The invoker is a dynamic servlet 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.
For 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\].. Wiki Markup
Anchor | ||||
---|---|---|---|---|
|
javax.servlet.ServletContext.getServerInfo();
Starting with tomcat 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 Tomcat to Standard output.
Anchor | ||||
---|---|---|---|---|
|
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. \[http://developer.java.sun.com/developer/bugParade/bugs/4724129. html More information\] Otherwise - get a memory profiler and/or tweak your memory settings. Wiki Markup
Anchor | ||||
---|---|---|---|---|
|
...
get a customized error page?
In your WEB-INF/web.xml
file:
Code Block | ||
---|---|---|
| ||
<error-page>
<error-code>404</error-code>
<location>/error/404.html</location>
</error-page> |
You may
Example (windows): SET JAVA_OPTS='-DpropName=propValue'
Example (UNIX): export JAVA_OPTS='-DpropName=propValue'
Wiki Markup |
---|
Windows service users - use \[http://web.bvu.edu/staff/david/tcservcfg/ this\] |
How do I get a customized error page?
In web.xml ...
No Format |
---|
<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.
Anchor | ||||
---|---|---|---|---|
|
...
(of Tomcat 4)?
No. It was an experiment, it failed. (YMMV) The original purpose of LE was because 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&=105341005928071&w=2 More info\] More info
Anchor | ||||
---|---|---|---|---|
|
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)\] |
How do I disable tag pooling?
...
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 | ||||
---|---|---|---|---|
|
No! Nor can one accurately exist. \[http://marc.theaimsgroup.com/?l=tomcat-user&m=104205666221372&w=2 Here's why\]exist. Here's why Wiki Markup
Anchor | ||||
---|---|---|---|---|
|
...
This is done in web.xml by changing welcome-files-list. \[http://marc.theaimsgroup.com/?l=tomcat-user&m=104566785828794&w=2 More detail\]. More detail.
Anchor | ||||
---|---|---|---|---|
|
To make a global change, this is done in TOMCATCATALINA_HOMEBASE/conf/web.xml by changing the listings property for the default servlet.
If you want to enable it for an individual webapp, then you need to add something similar to the following to your WEB-INF/web.xml
file (for your individual app):
Code Block | |
---|---|
| |
| |
<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 | ||||
---|---|---|---|---|
|
You'll need to tweak with server.xml and \[http://marc.theaimsgroup.com/?l=tomcat-user&m=105159411609623&w=2 do this\]. (Don't worry - its really easy!) Update: you should be worried – this feature has its drawbacks. Wiki Markup
Anchor | ||||
---|---|---|---|---|
|
Wiki Markup |
---|
Use the \[http://www.onjava.com/pub/a/onjava/excerpt/jebp_3/index3.html Content-Disposition\] header. |
Use the Content-Disposition header (as defined by RFC6266).
Anchor | ||||
---|---|---|---|---|
|
It 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. Wiki Markup
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()
orServletResponse.resetBuffer()
- Calling either
HttpServletResponse.sendError()
orHttpServletResponse.sendRedirect()
. - Calling
RequestDispatcher.forward()
which includes performing a jsp:forward - Calling
RequestDispatcher.forward()
which includes performing a jsp:forward
- Calling
...
There is also a nice description of the life cycle.
Note, that this issue does not affect the SimpleTag
tags and tag files of JSP 2.0 and later specifications, because those do not use tag pooling.
Anchor | ||||
---|---|---|---|---|
|
To disable tag pooling: See $CATALINA_BASE/conf/web.xml file and set enablePooling=false for the JspServlet
declaration.
Note: This option, 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 | ||||
---|---|---|---|---|
|
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()
orServletResponse.resetBuffer()
- Calling either
HttpServletResponse.sendError()
orHttpServletResponse.sendRedirect()
. - Calling
RequestDispatcher.forward()
which includes performing a jsp:forward - Calling
RequestDispatcher.forward()
which includes performing a jsp:forward
- Calling
Remember that if you call forward()
or sendRedirect()
, any following lines of code will still execute. For example:
Code Block | ||
---|---|---|
| ||
{ ... 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! */ } |
Anchor |
---|
...
|
...
|
...
Tomcat does not support this directly. Its not part of the Servlet or JSP Specification. If you do need this functionality see Apache TomEE which includes support for the @Schedule annotation and ScheduleExpression API, or see this thread or this link.
Anchor | ||||
---|---|---|---|---|
|
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 | ||||
---|---|---|---|---|
|
...
Use ServletContext.getResourceAsStream()
Anchor | ||||
---|---|---|---|---|
|
...
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 | ||||
---|---|---|---|---|
|
...
Tomcat an EJB server? Can I use EJBs with
...
Tomcat?
Tomcat is not an EJB server. Tomcat is not a full J2EE JavaEE server. Tomcat is a Servlet container. Tomcat does support those parts of the J2EE JavaEE specification that are required for Servlets, such as a subset of JNDI functionality. Furthermore, you can connect to remote J2EE JavaEE servers, or run tomcat Tomcat embedded inside a full J2EE JavaEE server.
Can I access Tomcat's JNDI provider from outside tomcat?
Not at this time.
Who uses tomcat in production?
...
Apache TomEE is a Java EE certified distribution built from Tomcat and contains support for EJB, CDI, JSF, JPA, BeanValidation and Transactions. The goal of TomEE is to maintain all Tomcat functionality and identity, only adding what is necessary to pass that Java EE 6 Web Profile TCK. A second distribution, called TomEE Plus, adds JAX-RS, JAX-WS, JMS and support for the JavaEE Connector Architecture.
Anchor | ||||
---|---|---|---|---|
|
Not at this time.
Anchor | ||||
---|---|---|---|---|
|
Numerous organizations across various industries all over the world. There is a PoweredBy page in this wiki.
Anchor | ||||
---|---|---|---|---|
|
...
java.lang.ThreadDeath
exceptions when reloading my webapp....
See Bugzilla discussion of this.
Anchor | ||||
---|---|---|---|---|
|
...
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.dump to determine the code which started the thread. Wiki Markup
Anchor | ||||
---|---|---|---|---|
|
The admin web application that ships was shiped with Tomcat's binary distribution contains of Tomcat 5.5 and earlier, contained pre-compiled JSPs and mappings for them. In order to debug these JSPs, you need to get the source versions, place them in the admin webapp directory, and disable the JSPC-generated web.xml servlet mappings. Here's how to do it from scratch for a clean Tomcat installation:
...
-generated web.xml servlet mappings. Here's how to do it from scratch for a clean Tomcat installation:
- Download Tomcat's base and admin webapp distributions (binaries), unzip to a directory of your choice. We'll use c:\temp in this example.
- 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.
- 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. - 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.
- 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.
- If you haven't already, define an admin user in %CATALINA_HOME%\conf\tomcat-users.xml.
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 | ||||
---|---|---|---|---|
|
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.
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:
Code Block | ||
---|---|---|
| ||
<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.
Anchor | ||||
---|---|---|---|---|
|
A Filter lives in the webapp space and its behavior is defined by the Servlet spec. It will work across all Servlet containers.
A Valve can do everything a Filter can do but is Tomcat specific, and potentially not portable across Tomcat versions. A Valve can be executed earlier in the lifecycle of a request, access Tomcat internals, and do other "interesting" decorations to your webapp in the chance you cannot change your deployed webapp.
If you can achieve the desired functionality with a Filter, it is the preferred way to go.
Anchor | ||||
---|---|---|---|---|
|
Create a setenv.bat
or setenv.sh
file. It is documented in RUNNING.txt.
Example (windows):
Code Block | ||||
---|---|---|---|---|
| ||||
SET CATALINA_OPTS='-DpropName=propValue' |
Example (UNIX):
Code Block | ||||
---|---|---|---|---|
| ||||
export CATALINA_OPTS='-DpropName=propValue' |
Windows service users — use service configuration application (e.g. tomcat9w.exe
).