Announcement Announcement Module
Collapse
No announcement yet.
Adding character encoding to the response Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding character encoding to the response

    The org.springframework.web.filter.CharacterEncodingFi lter sets the character encoding in the html request like:
    request.setCharacterEncoding(this.encoding);

    My experience is that it's also a good idea to set the encoding in the response:
    response.setContentType(this.contentType + " ;charset=" + this.characterEncoding);

    This will tell the browser that pages from the server should be shown using the specified charater encoding. If I got it right, the browser also uses the page's encoding to encode what's posted by a form tag on the page. This is most imporatant if you want users to be able to submit text containing characters not supported by the browser's default encoding.

    Of course, instead of having the filter setting the encoding in the response, you can add it to each page like using a meta tag:
    <meta http-equiv="content-type" content="text/html;charset=utf-8"> but that seems to be unnecessary work to me...


    So the simple question is: Is there any drawbacks putting this extra line to the filter? The only one I can think of is that you sometimes would like to override the setting and set the contentType/encoding to something else, but that setting would be something you'd have to do anyway..

    /Jo
Working...
X