You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Chris Searle <ch...@empolis.no> on 2005/12/16 10:55:40 UTC

Page encoding - confused

OK.

Using the VelocityViewServlet and I can't get it to play properly with
UTF-8.

We have a file on disk - in UTF-8 encoding. I need to return the
contents of this as part of an HTML response to the browser (this is
the test case - the real life situation is more complex).

So this is loaded from disk (from a struts action) using a
BufferedInputStream specified to have UTF-8 encoding.

The content of this is stored in a java String.

The string is then set as a request parameter which in the velocity
template is referenced.

The velocity.properties file has

input.encoding=UTF-8
output.encoding=UTF-8

as well as a velocimacro.library setting which is used - so the file
is being read.

And on startup the log says:

Velocity   [info] VelocityViewServlet: Default content-type is: text/html; charset=UTF-8

So - as far as I can see - that should give that when this particular
action is called via the web app then the content of the file is
returned to the user in UTF-8.

The content itself (xhtml) starts

<?xml version="1.0" encoding="UTF-8"?>

But - and this is the issue - the content (xhtml body) itself is
returned to the browser encoded in iso-8859-1 (which is the encoding
that tomcat is running under - and which I can't change - mine is not
the only app on this server).

I've obviously missed a step somewhere here - any hints?

-- 
Chris Searle

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Page encoding - confused

Posted by Nathan Bubna <nb...@gmail.com>.
i don't deal with encoding issues much myself, so my ability to help
is limited, but the first question i have is whether something else is
setting the content-type on the HttpServletResponse before the
VelocityViewServlet does?  a filter?  a Struts action? you're looking
for calls to setLocale or setContentType

i vaguely recall that the HttpServletResponse will only take the first
content type set and ignore subsequent ones. (i could be wrong, but
it's worth looking into)

On 12/16/05, Chris Searle <ch...@empolis.no> wrote:
>
> OK.
>
> Using the VelocityViewServlet and I can't get it to play properly with
> UTF-8.
>
> We have a file on disk - in UTF-8 encoding. I need to return the
> contents of this as part of an HTML response to the browser (this is
> the test case - the real life situation is more complex).
>
> So this is loaded from disk (from a struts action) using a
> BufferedInputStream specified to have UTF-8 encoding.
>
> The content of this is stored in a java String.
>
> The string is then set as a request parameter which in the velocity
> template is referenced.
>
> The velocity.properties file has
>
> input.encoding=UTF-8
> output.encoding=UTF-8
>
> as well as a velocimacro.library setting which is used - so the file
> is being read.
>
> And on startup the log says:
>
> Velocity   [info] VelocityViewServlet: Default content-type is: text/html; charset=UTF-8
>
> So - as far as I can see - that should give that when this particular
> action is called via the web app then the content of the file is
> returned to the user in UTF-8.
>
> The content itself (xhtml) starts
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> But - and this is the issue - the content (xhtml body) itself is
> returned to the browser encoded in iso-8859-1 (which is the encoding
> that tomcat is running under - and which I can't change - mine is not
> the only app on this server).
>
> I've obviously missed a step somewhere here - any hints?
>
> --
> Chris Searle
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org