The Jakarta Project
      The Tomcat Servlet/JSP Container

Generate Jsps using the JavaEncoding patch ANT HOW-TO

Patches to JspC

written by Johannes Fiala, johannes.fiala@fwd.at on May, 3rd 2003

I was annoyed by the fact that the ant JspC task currently only supports UTF-8. So I patched JspC.java and allowed for using a new parameter javaEncoding="..." which can be set to the encoding you need.

Additionally, this makes the usage of Jspc with ant more consistent with the Jspc Tomcat compilation, which allows javaEncoding to be set in /conf/web.xml:

   javaEncoding        Java file encoding to use for generating java
                      source files. [UTF8]

However, there is a small inconsistency in the original source of TC 4.1.24/5.0.1 compared to /conf/web.xml. It is "UTF8" at web.xml, but "UTF-8" at JspC.java. I left this inconsistency, as I don't know the reasons.

Update history

Update 2003-05-03, 11:00 CEDT:

I patched JspC.java to allow the parameter javaEncoding to be set via the invocation of the jasper2 task at build.xml.

Tested configurations

I tested the following configurations:

  • Tomcat 4.1.24 with JDK 1.4 on Win 2K Professional
  • Tomcat 5.0.1 with JDK 1.4 on Win 2K Professional
Prerequisites

To understand this document, you should already be familiar with ant and the manager app to build and deploy your web applications to a Tomcat server

I've extended the current version of Tomcat to support setting the javaEncoding using build.xml. You have to replace the jasper-compiler.jar at %CATALINA_HOME%/common/lib/jasper-compiler.jar in order to use the functionality described in this HOWTO.

Tomcat 4.1.24:

Download the binary
View/Download the source

Tomcat 5.0.1:

Download the binary
View/Download the source

DISCLAIMER: This patch comes with absolutely no warranty. Use at own risk.

Changes at the Tomcat source files

I had to change the following files of the Tomcat distribution:

  • JspC.java (residing at /common/lib/jasper-compiler.jar)

How to use it

Edit your build.xml and add the parameter javaEncoding="UTF-8" or "ISO-8859-1" (Western European languages) or any encoding you like.

<jasper2
             validateXml="false"
             uriroot="${basedir}/jsp"
             webXmlFragment="${basedir}/webinc.xml"
             outputDir="${basedir}/src" javaEncoding="ISO-8859-1" />

Make sure you delete the JSPs you already generated. Next you can try ant jspc and watch the newly generated Jsps being created at outputDir with the proper encoding.

Open issues/TODO

  • There are currently no open issues

Credits
  • Yoav Shapira: thx for your extensive support at the userlist and for the DOM parsing suggestion.
  • XML/XSLT layout: The XSLT layout has been copied and adapted from the original Tomcat project.

Copyright © Fiala Web Development GmbH, All rights reserved.
written by Johannes Fiala.