O'Reilly logo

Java Servlet & JSP Cookbook by Bruce W. Perry

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5.3. Precompiling JSPs with the Precompilation Protocol

Problem

You want to use the "precompilation protocol" that is part of the JSP specification to precompile one or more JSP files.

Solution

Send a request to the JSP container that includes a jsp_precompile parameter.

Discussion

The JSP 1.2 and 2.0 specifications require compliant JSP containers to support the use of the jsp_precompile request parameter. This parameter suggests that the container precompile the requested JSP. Here is how it works in Tomcat:

  1. Request the JSP that you want precompiled with the jsp_precompile parameter added to the URL, as in http://localhost:8080/home/url_rewrite.jsp?jsp_precompile=true.

    The JSP container is not supposed to execute the JSP page; it just precompiles it. The result of the request, if you were making it in a web browser, is a blank page.

  2. If the JSP file in JSP page syntax has not yet been compiled, or if the JSP file has been changed and has a later modification date than any existing page implementation class, Tomcat creates a new Java source and class file for the JSP in the <Tomcat-install-directory>/work directory. If the JSP file is named url_rewrite.jsp, Tomcat calls the Java source and class files url_rewrite_jsp.java and url_rewrite_jsp.class.

    Supplying the request parameter jsp_precompile (without the "=true" part) is the same as requesting jsp_precompile =true in the URL.

Tip

The precompilation protocol in Tomcat will both create the .java file and compile that file into the JSP ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required