자바I/O servlet 에서의 json 한글처리

황제낙엽 2013.04.23 23:28 조회 수 : 1519

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();

 

번호 제목 글쓴이 날짜 조회 수
33 File 클래스 정리 황제낙엽 2019.07.29 91
32 파일 사이즈를 반환하는 유틸 함수 황제낙엽 2019.07.29 120
31 BufferedReader, BufferedWriter를 활용한 빠른 입출력 황제낙엽 2019.07.29 77
30 File.length() 에 대하여 황제낙엽 2019.03.24 221
29 File.delete() 와 File.deleteOnExit() 황제낙엽 2019.03.24 1887
28 메일서버(daum.net)에 POP3를 이용하여 메일 가져오기 예제 file 황제낙엽 2018.10.09 940
27 org.apache.commons.io.FilenameUtils (getExtension) 황제낙엽 2018.04.01 1209
26 File 을 다루기 위한 유틸 클래스 file 황제낙엽 2018.02.28 99
25 HttpsURLConnection 을 사용한 SSL서버 접속 file 황제낙엽 2017.08.02 231
24 HttpURLConnection 사용 샘플( JSP , SERVLET ) 황제낙엽 2017.08.01 254
23 HttpURLConnection 사용하기 황제낙엽 2017.08.01 393
22 [HttpURLConnection] POST로 파라미터 넘기기 황제낙엽 2017.08.01 507
21 HttpURLConnection POST 방식 사용하기 황제낙엽 2017.08.01 370
» servlet 에서의 json 한글처리 황제낙엽 2013.04.23 1519
19 com.oreilly.servlet.multipart 를 이용한 파일 업로드 file 황제낙엽 2013.03.19 104
18 Jar파일에 포함된 리소스 접근하는 방법(How to read a resource from a JAR file ) file 황제낙엽 2012.06.24 164
17 16비트 CRC 체크용 클래스 (사용자 클래스) 황제낙엽 2010.03.14 406
16 파일을 읽어서 CRC 값을 연산하는 메서드 (java.util.zip.CRC32) 황제낙엽 2010.03.14 137
15 byte배열에 대한 CRC 를 계산하는 메서드 (java.util.zip.CRC32) 황제낙엽 2010.03.14 2166
14 org.apache.commons.fileupload.servlet.ServletFileUpload 를 이용한 파일 업로드 file 황제낙엽 2009.11.19 129