RE: JSP containers and default charset (was: Re DefaultCharset considered harmful)

On Sun, 30 Nov 2003, Addison Phillips [wM] wrote:

I'm sorry to resurrect an old thread, but recently I stumbled upon this
issue once more. Besides, for those who would come across this
issue in the future, we may have to add it to the appropriate
sections of our authoring tech document (where 'form' and
'character encoding specification' are dealt with) along with
what's to be done with this in other popular server-side 'scripts'/cgi
(asp, perl, etc)

> Not quite: there are two directives: pageEncoding and contentType and they
> can indicate *different* encodings. If you use pageEncoding on its own, it
> is assumed that the encoding of the source JSP file should be the encoding
> used to deliver the file. If you use contentType on its own, then the page
> is delivered in the encoding specified, but read as Latin-1. If you want to
> use one encoding (say EUC-KR) for the JSP file and a different encoding
> for the delivery (say UTF-8) then you can use both directives together.
>
> For example, see Norbert Lindeberg's excellent article here:
> http://developer.java.sun.com/developer/technicalArticles/Intl/MultilingualJ
> SP/

....

> One more note: if your JSP page reads data from a HttpServletRequest object,
> you may have to call the setCharacterEncoding() method on that object before
> retrieving parameters sent to your JSP page via GET or POST.

  With recent versions of Apache tomcat 4.1.29 and 5.x, I found that
request.setCharacterEncoding() doesn't have any effect for GET by
default because it treats the URI as if it's in ISO-8859-1 whatever you
do with setCharacterEncoding() (setCharacterEncoding() normally only
applies to the request body NOT the URI.). For POST, it works just fine.
By setting 'useBodyEncodingForURI' attribute to true in server.xml for
the http/1.1 connector, we can get setCharacterEncoding() applied to
GET as well. The following bugzilla entries for apache mention
two other methods.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23929
http://www.mail-archive.com/taglibs-user@jakarta.apache.org/msg06319.html
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=12253

  Jungshik

Received on Saturday, 1 May 2004 23:48:14 UTC