JSP&Servlet ์์ ํ๊ธ์ฒ๋ฆฌ
GET ๋ฐฉ์
ํผ ํ๊ทธ์ method ์์ฑ์ด GET ๋ฐฉ์์ธ ๊ฒฝ์ฐ๋ ํ์ด์ง์์ ์ฌ์ฉํ๊ณ ์๋ ์บ๋ฆญํฐ ์ ์ผ๋ก ์ธ์ฝ๋ฉ ๋์ด ํ๋ผ๋ฏธํฐ๊ฐ ์ ์ก๋๋ค.
ํ์ด์ง์ charset ์ค์
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">ย
๋ฌธ์์ด์ ์บ๋ฆญํฐ ์ ๋ณ๊ฒฝ ์ฒ๋ฆฌ
import java.io.*;ย
public class Test{ public static void main(String args[]){ย
String Str1 = new String("Welcome to Tutorialspoint.com");ย
try{ byte[] Str2 = Str1.getBytes();ย
System.out.println("Returned Value " + Str2 );ย
Str2 = Str1.getBytes( "UTF-8" );ย
System.out.println("Returned Value " + Str2 );ย
Str2 = Str1.getBytes( "ISO-8859-1" );ย
System.out.println("Returned Value " + Str2 );ย
}catch( UnsupportedEncodingException e){ย
System.out.println("Unsupported character set");ย
}ย
}ย
server.xml ์ ์ค์
GET๋ฐฉ์์ผ๋ก ์ ์ก๋์ด ์ค๋ ํ๋ผ๋ฏธํฐ๋ค์ ์บ๋ฆญํฐ์ ์ ์ผ๊ด๋ณ๊ฒฝ ์ํด. Connector ํ๊ทธ์ URIEncoding="utf-8" ์ถ๊ฐ
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="utf-8"/>
๊ทธ๋ฆฌ๊ณ connector ํ๊ทธ์ useBodyEncodingForURI="true" ์์ฑ์ ์ถ๊ฐํ๊ณ ํ์ด์ง ํน์ ์๋ธ๋ฆฟ์์ request.setCharacterEncoding("utf-8")์ ์ง์ ํ์ฌ ์ฌ์ฉํ ์ ์๋ค.
POST ๋ฐฉ์
POST ๋ฐฉ์์์๋ request.setCharacterEncoding("utf-8")์ ์ฌ์ฉํ์ฌ ํ๊ธ์ ์ฒ๋ฆฌํ๋ค. (๋จ, GET ๋ฐฉ์๊ณผ ๋ฌ๋ฆฌ server.xml ์ useBodyEncodingForURI="true" ๋ฅผ ์ด์ฉํ ํ์์์ด ๊ธฐ๋ณธ์ ์ผ๋ก ์ด ๋ฐฉ์์ผ๋ก ์ธ์ฝ๋ฉ ๋ฐฉ์์ ๋ณ๊ฒฝํ ์ ์๋ค.)














