• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setting characters encoding

 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are the following used for different purpose? in terms of setting the response type.

1. response.setCharacterEncoding();
2.<%@ page session="true" contentType="text/html; charset=UTF-8"%>
3.<%@ page session="true" contentType="text/html; charset=UTF-8" pageEncoding=""UTF-8%>

If they are different .could someone explain?
 
Rajeev Rnair
Ranch Hand
Posts: 310
1
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
response.setContentType("text/html; charset=UTF-8"); and
<%@ page contentType="text/html; charset=UTF-8"%> are same.

Character encoding can be subset of Content type. For example:
response.setCharacterEncoding("UTF-8"); and
<%@ page pageEncoding="UTF-8"%> are same.

If you use contentType, you may not need to use characterEncoding! Please check the ServletResponse API
setCharacterEncoding

public void setCharacterEncoding(java.lang.String charset)
Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8. If the character encoding has already been set by setContentType(java.lang.String) or setLocale(java.util.Locale), this method overrides it. Calling setContentType(java.lang.String) with the String of text/html and calling this method with the String of UTF-8 is equivalent with calling setContentType with the String of text/html; charset=UTF-8.
This method can be called repeatedly to change the character encoding. This method has no effect if it is called after getWriter has been called or after the response has been committed.

Containers must communicate the character encoding used for the servlet response's writer to the client if the protocol provides a way for doing so. In the case of HTTP, the character encoding is communicated as part of the Content-Type header for text media types. Note that the character encoding cannot be communicated via HTTP headers if the servlet does not specify a content type; however, it is still used to encode text written via the servlet response's writer.

Parameters:
charset - a String specifying only the character set defined by IANA Character Sets (http://www.iana.org/assignments/character-sets)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic