The Semb + Wever Family
[ start | index | login ]
start > java > UTF-8 bug in JSTL's xml transform tag

UTF-8 bug in JSTL's xml transform tag

Created by michaelwever. Last edited by michaelwever, 5 years and 245 days ago. Viewed 757 times. #2
[diff] [history] [edit] [rdf]
labels
attachments

UTF-8 bug in JSTL's xml transform tag

While going through the process of making >>work's current project UTF-8 compliant I encountered a nasty bug/problem. I successfully changed all the java files to UTF-8 without any headache. When I got to the JSPs there were a number of little tricks, being:
  • using both contentType and pageEncoding attributes in the page directive, like
    <%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"  %>
  • putting in a filter so ensure a call to
    request.setCharacterEncoding("UTF-8");
    before any jsp or struts form processing
  • adding the attribute charEncoding="UTF-8" to all c:import tags, like
    <c:import url="http://www.wever.org" charEncoding="UTF-8"/>
  • changing the xsls in the database to UTF-8 encoding declaration and UTF-8 output attribute.
But the bug/problem was using XSLT TRaX from inside the JSPs. For example the jsp code:
<c:import var="xslt" url="servlet/Xsl?id=123" charEncoding="UTF-8"/>
<c:import var="xml" url="servlet/Xml?id=321" charEncoding="UTF-8"/>
<x:transform xml="${xml}" xslt="${xslt}"/>
was not working, even when I could get exactly the same xml and xsl to transform correctly with the same Transformer in plain java code. The result was just junk. Not so much wierd characters and entities, but the xml was getting truncated during transformation and simply outputting the same text for every xsl template in the xsl.

Wierd and I was slowly going nuts trying to fix it! Lots of googling and xslt trax source code reading got me nowhere. I even tried using JSLT 2.0, it doesn't work with Oracle 10g yet. (I believe it's working in the 10g 10.0.3 preview).

We were using Sun's JDK1.5 XSLT TRaX default tranformer: com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl and the last thing on my list to try before hitting the sack at 1am sunday morning was to switch transformers:

  1. (Oracle) I've never been able to get Oracle's oracle.xml.jaxp.JXSAXTransformerFactory to work with jstl's xml tags. (Oracle 10g doesn't officially support jdk1.5, and they have no announcement of a timeline to supporting jdk1.5 yet.)
  2. (Xalan) I tried org.apache.xalan.processor.TransformerFactoryImpl but this gave the same result as jdk1.5's default not surprisingly (it's basically the same implemenation).
  3. (Jd.xslt) I could not download jd.xslt as the website was down,
  4. (Saxon) so last I tried Saxon8's net.sf.saxon.TransformerFactoryImpl (saved this to last because of it's download size, and bloat of additional features that I didn't really need to add to the web application).
Viola! Saxon worked! Happy Days!

If someone knows what the real problem is, or if it's been fixed in the other transformer implemenatations please >>email me. Otherwise I think I'm now a Saxon fan.

no comments | post comment
Semb Wever Family:
>>Family Tree, >>Wedding, & >>Photos
>>Music & Movies
>>Mck's Radio Station
>>Hosted GnuPG Keys

< July 2010 >
SunMonTueWedThuFriSat
123
45678910
11121314151617
18192021222324
25262728293031

Corporate links:
Vet Products|Bokklubben|Finn

Opensource projects:
Scarab|NetBeans


Describe here what your SnipSnap is about!

Configure this box!

  1. Login in
  2. Click here: snipsnap-portlet-2
  3. Edit this box



>>The only thing worse than using cracked/stolen software is actually paying for it.
>>Liberate yourself. Free Software Foundation.


XHTML 1.0 validated CSS validated RSS 2.0 validated SnipSnap Get Firefox! RSS Feed
Powered by Gentoo Linux/GNU






Rainforest Site