Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.0-beta-6
-
None
-
None
Description
groovy.servlet.TemplateServlet can specify charset of the response by overriding
TemplateServlet#setContentType method, for example as follows:
public class MyTemplateServlet extends TemplateServlet {
protected void setContentType(HttpServletRequest request, HttpServletResponse response)
}
But, it does not work correctly.
Because right now groovy.servlet.TemplateServlet calls TemplateServlet#setContentType AFTER ServletResponse#getWriter,
but ServletResponse#setContentType needs to be called BEFORE ServletResponse#getWriter.
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletResponse.html
The charset for the MIME body response can be specified with
setContentType(java.lang.String). For example, "text/html; charset=Shift_JIS".
The charset can alternately be set using setLocale(java.util.Locale).
If no charset is specified, ISO-8859-1 will be used.
The setContentType or setLocale method must be called before
getWriter for the charset to affect the construction of the writer.
I'll attach a patch for TemplateServlet and GroovyServlet (with some cleanup of unused code).
This problem was originally reported by taedium in http://d.hatena.ne.jp/taedium/20040601#p1 (Japanese).