This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Setting content encoding in Velocity

May 22nd, 2009, 09:07 AM

For performance reasons I recently decided to switch from using JSP views to Velocity. This has worked great so far, and the response time decreased significantly. There is however one problem, I can't set the content encoding that is returned to the browser in the response headers. This worked just fine in JSP by defining the content type with

Code:

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

When using Velocity the content type is always set to text/html;charset=ISO-8859-1. Characters that are not in this set are displayed as question marks. I have tried setting output.encoding, default.contentType in velocity.properties and setting an CharacterEncodingFilter in web.xml. A VelocityViewResolver has a content type property, but I want to use the ResourceBundleViewResolver.

I have searched using Google and this forum and there appear to be a lot of people with this problem, but I was unable to find an answer to my problem anywhere. Below are the relevant source files of a small sample application I am using to find a solution to this problem.