You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Bill Boland <bo...@attbi.com> on 2002/06/01 06:53:45 UTC

VelocityServlet, response output and character encoding

I made some assumptions (bad start) with the documentation
(http://jakarta.apache.org/velocity/developer-guide.html) for the
output.encoding key/value in the velocity.properties. It mentioned that
this was used for the VelocityServlet. I had set this to UTF-8 but
encountered some problems. I displayed the $res.characterEncoding within
a template and found that the response encoding was still the default
and not UTF-8. I dug a bit deeper into the VelocityServlet source code
and saw that the encoding is applied to the OutputStreamWriter that
bridges to the response output stream but it is not applied when setting
the content type of the response output stream (only the content type is
assigned).

 

To get around this (and correct my problem) I had to set the contentType
and character encoding myself in the setContentType() method that can be
overridden. My question is: Shouldn't the default behavior of
setContentType also set the response output encoding? Or is it desirable
to have the output encoding for velocity be different than what is
assigned to the response output stream?

 

 I'm new at trying to use the encoding stuff so I just wanted to see how
others use this with the VelocityServlet. Thanks.

 

Bill

 

PS: It would be nice if the defaultContentType and encoding fields of
the VelocityServlet were changed from private to protected so that
subclasses can use/override this information easily (without dipping
into the RuntimeSingleton).