Differences between revisions 2 and 3
Revision 2 as of 2009-09-20 23:56:52
Size: 3520
Editor: localhost
Comment: converted to 1.6 markup
Revision 3 as of 2013-02-02 21:12:11
Size: 0
Comment: Delete obsolete recipe. It was for Tomcat 5,5, but is not needed and not applicable to Tomcat 6 and later.
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
##language:en
== Editing the default JSP home page loaded by Tomcat ==

The contents of the default Tomcat home page comes from the ROOT webapp servlet called {{{org.apache.jsp.index_jsp}}}.
The page that you see in {{{$CATALINA_HOME/webapps/ROOT/index.jsp}}}
has been precompiled into a class file ({{{org.apache.jsp.index_jsp.class}}}) stored in a JAR file
({{{catalina-root.jar}}}) in the ROOT webapp's {{{WEB-INF/lib}}} directory.
Because of this servlet, Tomcat will not look at the contents of the ROOT web application's
{{{index.jsp}}} file if you change it.

The easiest way to change the contents of the {{{index.jsp}}} page is to remove this
{{{index_jsp}}} servlet from the ROOT webapp. Once you remove the {{{index_jsp}}} servlet and restart Tomcat,
Tomcat will see the {{{index.jsp}}} file in the ROOT directory and compile it on the fly into a class file.
You now will be able to edit the ROOT/index.jsp file and have those changes take effect immediately by reloading the {{{http://localhost:8080/}}} page.

To remove the {{{index_jsp}}} servlet, edit the ROOT web application's configuration file,
{{{$CATALINA_HOME/webapps/ROOT/WEB-INF/web.xml}}}. Comment out the definition of the servlet and the servlet mapping, so that section of the file will look like this (note the commented out section):

{{{
<!-- JSPC servlet mappings start -->

  <!-- Commenting out so I can change the index.jsp page
    <servlet>
        <servlet-name>org.apache.jsp.index_jsp</servlet-name>
        <servlet-class>org.apache.jsp.index_jsp</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>org.apache.jsp.index_jsp</servlet-name>
        <url-pattern>/index.jsp</url-pattern>
    </servlet-mapping>
  -->
<!-- JSPC servlet mappings end -->
}}}

Once you disable the {{{index_jsp}}} servlet and restart Tomcat, how does Tomcat know to compile the
{{{index.jsp}}} page in the ROOT web app's directory? Easy. First, when you request the default page of a web application, Tomcat (like every servlet container) will look for a welcome file. The default welcome files are defined at the bottom of {{{$CATALINA_HOME/conf/web.xml}}}. This web.xml file acts as a global web.xml file used for all web applications installed in Tomcat. The default welcome file list includes {{{index.jsp}}}, which means Tomcat will try to load that file (if found) in order to display it. Second, the {{{$CATALINA_HOME/conf/web.xml}}} configuration file also defines a servlet called simply {{{jsp}}}.
This section of the {{{web.xml}}} file:

{{{
    <!-- The mapping for the JSP servlet -->
    <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>*.jsp</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>*.jspx</url-pattern>
    </servlet-mapping>
}}}

maps all {{{.jsp}}} and {{{.jspx}}} pages to the jsp servlet. The jsp servlet performs the work of compiling the source JSP file into a servlet and then executing the servlet. The JSP servlet, by default, will check the JSP source page every time it is requested to see if it was modified since the last time it was compiled. If the page changed within 4 seconds of the last time it was compiled, the servlet will recompile the source JSP page before running it. The behavior of the jsp servlet is quite configurable. You can see all its options defined in the
{{{$CATALINA_HOME/conf/web.xml}}} configuration file.