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

Hello Addison, others,

One very specific question about JSP: Is it possible (and if yes,
how) to produce an XML file where the correct encoding is automatically
put into the encoding pseudo-attribute of the XML declaration?
Also, is it possible (and how) to use the mechanisms provided
(rather than doing everything on your own) and produce a HTTP
response without a 'charset' parameter on the Content-Type
response header?

Regards,    Martin.


At 22:09 03/11/30 -0500, Addison Phillips [wM] wrote:

>Hi Jungshik,
> >
> > You're absolutely right.  Therefore, the charset declaration in a JSP
> > file serves dual purposes. It indicates the character encoding of the
> > JSP file to the Java compiler (i.e. playing the same role as '-encoding'
> > option when invoking 'javac') and it also indicates in what character
> > encoding the generated html file should be served to the outside world.
> > Someone might argue that there need to be two separate 'directives' for
> > two roles, but I guess it's all right to overload pageEncoding directive.
> >
>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 KS-X-1001) 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/
>
>In addition, the pageEncoding is how the JSP container reads the .jsp file
>in, but the resulting servlet may not be written in the specified encoding
>(e.g. the javac invocation might not use an -encoding directive).
>
>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.
>
>Best Regards,
>
>Addison

Received on Friday, 12 December 2003 10:33:13 UTC