Beating my head -- JSPs and encoding

Beating my head -- JSPs and encoding

Post by Manish Jet » Thu, 31 Jul 2003 23:35:11



[snip example]


You didn't mention which JSP container you're using. With OC4J,
I change the default-charset property in
global-web-application.xml You'll need to consult your
container's manual for instuctions on how to set this up.

Manish

--
Manish Jethani (manish.j at gmx.net)
phone (work) +91-80-51073488
 
 
 

Beating my head -- JSPs and encoding

Post by Malcol » Fri, 01 Aug 2003 08:28:58

Hi, Hegemony Cricket



Possibly the problem is here. May be you should specify the encoding for
the request by calling request.setCharacterEncoding("utf-8") before
getting "blah"-attribute.

Best regards, Yevgen Malafeyev AKA Malcolm.

 
 
 

Beating my head -- JSPs and encoding

Post by mschnitziu » Fri, 01 Aug 2003 11:03:54


Of course, after crunching on this problem for two days, I figured
it out minutes after posting here.

The JSP in question was actually one of several that were included
together to generate a single page. I had only done the

<%@ page contentType="text/html;charset=UTF-8"%>

on the topmost JSP, which generates a

response.setContentType("text/html;charset=UTF-8");

in the compiled JSP. The later JSPs, having not specified the
contentType, by default generate this call in their compiled state:

response.setContentType("text/html;charset=ISO-8859-1");

This overrides the previous call, so the browser tries to show the
page with the default encoding. Once I changed all the JSPs that
comprised the page to the correct content type, the page rendered
correctly.

Of course, I didn't give you all enough information to see the
problem, so you're all off the hook. ;-)

I was misled by the javadoc for JspWriter, which reads

public abstract void print(java.lang.String s)
throws java.io.IOException

Print a string. If the argument is null then the string
"null" is printed. Otherwise, the string's characters are
converted into bytes according to the platform's default
character encoding, and these bytes are written in exactly
the manner of the Writer.write(int) method.

They are not converted according the the platform's default
character encoding at all, it seems, but rather according to
what you specify. Lesson learned.

Thanks for your consideration...


--Mark