Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-514

ServletResponse#setContentType needs to be called before ServletResponse#getWriter

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-6
    • 1.0-beta-9
    • 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)

      { response.setContentType("text/html; charset=Shift_JIS"); }

      }

      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).

      Attachments

        1. GROOVY-514.patch
          4 kB
          Kouhei Mori

        Activity

          People

            guillaume Guillaume Sauthier
            ko-hey Kouhei Mori
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: