Maintenance

  • Home
  • Log in
  • « Configured Feisty for testing under VMWare
  • VLAN/Sanako/DHCP update »

Tomcat, Cocoon, AJAX, and Unicode

Posted by mholmes on 25 Apr 2007 in Activity log, Documentation

We have had a series of problems in our Cocoon projects submitting AJAX requests containing data which is not ASCII. Today, after much research, I came up with a solution, based on this useful explanation.

This is the basic setup required to make Unicode work on Cocoon:

  • The important bit we learned today: Tomcat defaults to treating request data as 8859-1, so Cocoon needs to be configured to work around this. In Cocoon's web.xml file, you need to set this:
    <init-param>
      <param-name>container-encoding</param-name>
      <param-value>ISO-8859-1</param-value>
    </init-param>
    <init-param>
      <param-name>form-encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  • The Web page itself must be UTF-8. For maximum reliability, this should be specified in the HTTP headers (so make sure whatever Cocoon serializer you're using to send out the page is set to use UTF-8) and also include a meta tag like this:
    <meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8"/>
  • The XMLHttpRequest object must be using GET; POST is flaky with regard to Unicode.
  • You must set the request header for the XMLHttpRequest like this:
    setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
  • You must encode any data which has non-ascii characters in it prior to transmission, using the JavaScript encodeURIComponent() function.

Provided all this is done, then Unicode characters will be reliably sent back to the server, and understood correctly in the Cocoon pipeline (so the XQuery code which handles them, in the case of our projects, will work properly).

This entry was posted by Martin and filed under Activity log, Documentation.

Maintenance

This blog is the location for all work involving software and hardware maintenance, updates, installs, etc., both routine and urgent.
  • Home
  • Recently
  • Archives
  • Categories

Search

Categories

  • All
  • Announcements
  • Hit by a bus
  • Labs
    • Activity log
    • Documentation
  • Notes
  • R & D
    • Activity log
    • Documentation
  • Servers
    • Activity log
    • Documentation
  • Tasks

All blogs

  • Academic
  • AdaptiveDB
  • Admin
  • Announcements
  • CanMys
  • Cascade
  • CGWP
  • ColDesp
  • Depts
  • DVPP
  • Endings
  • HCMC Blogs
  • Landscapes
  • LEMDO
  • Linguistics
  • Maint
  • LondonMap
  • Mariage
  • MoM
  • Moses
  • Pro-D
  • Projects
  • ScanCan
  • HumsSites
  • Wendat

This collection ©2026 by admin • Help • Photo albums software