sitelink1 | |
---|---|
sitelink2 | |
sitelink3 | |
sitelink4 | |
sitelink5 | |
sitelink6 |
javax.servlet
Interface ServletResponse
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 ofUTF-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 theContent-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)
Since:
2.4
See Also:
#setLocale
<Sample>
JSONObject resData = new JSONObject();resData.put("USERDATA", "ABC");response.setCharacterEncoding("UTF-8");response.setContentType("application/json;charset=UTF-8");response.setHeader("Cache-Control", "no-cache");PrintWriter out = response.getWriter();if (resData != null) {out.print(resData);}out.flush();out.close();