달력

42025  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

시간내서 한번 보자..

http://www.youtube.com/watch?v=yje3JjfmVZ4

'그외 주제들 > Study..합시당~~' 카테고리의 다른 글

ExtJS 강좌 좋은 사이트  (0) 2013.12.31
html5 storage  (0) 2013.12.30
Sencha 동영상들...  (0) 2013.12.27
phonegap tutorial..  (0) 2013.12.26
javascript animation 분석.. QM3 site..  (0) 2013.12.05
Posted by 행복한삶~!!
|

http://www.renaultsamsungm.com/QM3_T/


시간내서 여기  js 분석을 해보자... 

'그외 주제들 > Study..합시당~~' 카테고리의 다른 글

ExtJS 강좌 좋은 사이트  (0) 2013.12.31
html5 storage  (0) 2013.12.30
Sencha 동영상들...  (0) 2013.12.27
phonegap tutorial..  (0) 2013.12.26
웹동네 js 강좌..  (0) 2013.12.05
Posted by 행복한삶~!!
|

sublime text2

그외 주제들/Tool 2013. 11. 20. 13:52

나중에 꼭 한번 써보자..citi에는 거주가 불가능 하구나.. -_-; 

확실히 유용한 정보는 Tistory에 많구나.. 


http://edoli.tistory.com/77


http://juhoi.tistory.com/51


http://edoli.tistory.com/79

'그외 주제들 > Tool' 카테고리의 다른 글

Eclipse 단축키  (0) 2014.01.08
Errors running builder 'JavaScript Validator' on project...  (0) 2013.12.15
Posted by 행복한삶~!!
|

문제 출처

http://www.jungol.co.kr/prog/Hanal/hanalView.php?qs_code=1001&sk=&sv=&menu=&sst=qs_code&sod=asc&page=10&fv=1


강아지와 병아리
Time Limit : 1000MS

 

문제
강아지와 병아리의 합과 다리의 수를 입력받아 강아지와 병아리가 각각 몇 마리씩인지 구하는 프로그램을 작성하시오.

입력형식
강아지와 병아리의 합 1000 이하, 다리의 합 4000 이하의 정수를 공백으로 구분하여 입력받는다.
하나의 결과가 나온 후에도 계속 새로운 입력을 받다가, 0 이 입력되면 프로그램을 종료한다.

출력형식
강아지와 병아리가 각각 몇 마리씩인지 공백으로 구분하여 출력한다.
주어진 데이터로 마리수를 정할 수 없을 때는 "0" 을 출력한다.
데이터의 크기가 주어진 범위를 벗어날 경우는 "INPUT ERROR!"를 출력한다.

입력 예
25 80
15 10
1500 2000
0 0

출력 예
15 10
0
INPUT ERROR!

풀이..

package com.syjung;

import java.util.Scanner;

public class problem1 {
	
	boolean calc_value(String input )
	{
		int ani_sum, count_regs, max_count; 
		int x,y;
		boolean find_answer=false;
	
       // 문자열을 공백을 기준으로 숫자로 분리하기  
		String [] values = input.split(" ", 2);

		// Parameter counter 체크
		if( values.length != 2 )
		{
			System.out.println("Error!! Parameter counters are not 2.");
			return false;
		}
		
		// 문자열을 숫자로 변환, 동물숫자 합과 다리갯수
		ani_sum = max_count = Integer.parseInt(values[0]);
		count_regs = Integer.parseInt(values[1]);
		
		if( ani_sum > 1000 ) 
		{
			System.out.println("Error!! 동물의 합은 1000을 초과 할수 없습니다.");
			return true;
		}
		
		if( count_regs > 4000 ) 
		{
			System.out.println("Error!! 동물의 합은 4000을 초과 할수 없습니다.");
			return true;
		}
		
		if( ani_sum == 0 && count_regs== 0 ) 
		{
			System.out.println("종료!! 감사합니다~");
			return false;
		}
		
		// 동물숫자 합과, 다리갯수의 합과 일치하는 x,y를 찾는다. 
		for( x =0; x < max_count; x++ )
		{
			for(y=0; y < max_count; y++ )
			{
				if( x + y == ani_sum )
				{
					if( 4*x + 2 * y == count_regs )
					{
						System.out.println( String.format( "정답, 강아지 :%d, 병아리:%d ", x, y ) );
						find_answer = true;
						break; 
					}
				}
			}
		}
		
		if ( find_answer == false ) 
		{
			System.out.println( "정답이 없습니다.");
		}
				
		
		return true; 
	}

	/**
	 * @param args
	 */
	// Create a single shared Scanner for keyboard input
    private static Scanner scanner = new Scanner( System.in );

    // Program execution starts here
    public static void main ( String [] args )
    {    	
    	problem1 prb1 = new problem1();
    	String input;
    	
    	do
    	{
        // Prompt the user
        System.out.print( "Type some data for the program: " );

        // Read a line of text from the user.
        input = scanner.nextLine();

        // Display the input back to the user.
        System.out.println( "input = " + input );
    	
    	} while( prb1.calc_value(input) );

    	System.out.println( "프로그램이 정상 종료되었습니다." );
    } // end main method
}
Posted by 행복한삶~!!
|

'그외 주제들 > 한글처리' 카테고리의 다른 글

다양한 환경에서의 언어 설정  (0) 2013.09.30
자바에서 String 처리  (0) 2013.09.30
Response 구간 정리  (0) 2013.09.30
Request 구간 정리  (0) 2013.09.30
JSP,Servlet에서 한글 문제를 피하려면..  (0) 2013.09.30
Posted by 행복한삶~!!
|

 q시스템 기본 인코딩
¤Windows 시스템의 경우.
¤제어판의 국가 및 언어 옵션에서 선택할 수 있음 ( 영어:CP1252, 한국어:MS949 )
¤Unix 시스템의 경우
LANG 환경 변수에서 플랫폼이 지원하는 locale 을 지정 합니다.
현재 설정된 locale 값은 “locale”을 통해서 확인가능.
사용 가능한 locale은 “locale –a”를 통해 확인가능.
¤참고자료
¡http://develop.sunshiny.co.kr/398
¡http://blog.naver.com/PostView.nhn?blogId=paro01&logNo=100050474751&widgetTypeCall=true
   qJVM 설정
¤file.encoding
java의 기본 encoding type을 지정해준다.  String.getBytes( ) 함수호출시 파라미터가 없을때 file.encoding으로 동작한다file.encoding 을 특별히 지정하지 않았을 경우, shell 환경변수인 LANG 및 LC_ALL값에의해 결정됩니다.
¤client.encoding.override
Request객체에 저장되는 Form 데이타의 인코딩 type이 결정된다. Form데이타는 request.getParameter를 통해서 얻어오는데, client.encoding.override에 따라서 인코딩된 값이 리턴된다. Request 과정분석에서 상세내용을 정리하였다. 
    q web.xml
¤JSP 파일 Encoding Type 한꺼번에 지정 및 locale과 Encoding Type을 지정
각 개별 JSP 파일 및 Response 객체의 설정값이 web.xml 값보다 우선한다.
	
		
			*.jsp
			EUC-KR
		
	

	
		
			ja
			Shift_JIS
		
	


    q 브라우저
¤1.    "도구 -> 인터넷 옵션 -> 언어" 메뉴를 선택한다.
¤2.   영어[en]와 한국어[ko]를 추가하고 원하는 언어를 가장 상단에 위치한다.
 qHTML 설정
¤<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 qXML 설정
¤<?xml version="1.0" encoding="UTF-8" ?>
 qJSP 설정
¤<%@ page pageEncoding="UTF-8" %>
¤<%@ page contentType="text/html;charset=UTF-8" %>
¤charset=euc-kr 일때 확장 한글이 제대로 표현되지 않는다.
¤charset=ms949 일때는 확장 한글이 정상적으로 표현된다.
 qServlet 설정
¤HTTP 요청의 인코딩 지정
¤request.setCharacterEncoding("UTF-8");
¤HTTP 응답의 인코딩 지정
¤response.setContentType("text/html; charset=UTF-8");
¤response.setCharacterEncoding("utf-8");
        qOcacle 설정
¤설정된 Encoding 모드 조회방법
¤select * from nls_database_parameters where parameter like '%CHARACTERSET%';
¤Oracle Database 문자 셋 변경 방법
¤ 환경 변수 또는 %ORACLE_HOME%/dbs/init[SID].ora 설정
  NLS_LANG='American_America.Ko16ksc5601‘
  ORA_NLS33='$ORACLE_HOME/ocommon/nls/admin/data‘
  NLS_DATE_FORMAT='YYYY-MM-DD‘

     DriverManager에서 문자셋 설정 방법
  java.util.Properties props = new java.util.Properties();
  props.put("charSet", "KSC5601" );
  DriverManager.getConnection(dbUrl, props);

'그외 주제들 > 한글처리' 카테고리의 다른 글

참고 자료..  (0) 2013.09.30
자바에서 String 처리  (0) 2013.09.30
Response 구간 정리  (0) 2013.09.30
Request 구간 정리  (0) 2013.09.30
JSP,Servlet에서 한글 문제를 피하려면..  (0) 2013.09.30
Posted by 행복한삶~!!
|

getBytes 이해하

JAVA에서는 전세계 모든 언어를 지원하기 위해서 문자열을 Unicode로 저장한다.

하지만 아직 다양한 환경에서 UNICODE가 아니 전통적인 인코딩 방식이 사용되고 있는데,
String.getBytes() 함수를 통해서 간편하게 다른 Encoding Type으로 변환을 지원한다.

예를 들어 TCP/IP 통신 및 File I/O 등을 통해서 ISO-8859-1으로 인코딩된 문자열을 수신했을 때 적절하게 변환하여야 정상적으로 한글 출력이 된다.

사용방법 참조 http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#getBytes()

1               String chkStr2 = 1”;

2  byte [] bytes = chkStr2.getBytes( “ksc5601” );

3

4  for ( byte b : bytes )     

5  {

6      out.print(String.format("0x%02X ", b));

7  }

세부 진행 순서는 다음과 같다..
1번 라인에서 1”UTF-16BE 형식으로 아래와 같이 저장된다.
0xD55C
0x0020 0xB620 0x0020 0xD3B2 0x0031

2 라인에서는 UTF-16BEKSC5601 코드값으로 변환한다.
’ 0xD55C è 0xC7D1

‘ ‘ (공백) 0x0020 è 0x20

0xB620 è 0x3F (‘?’),  KSC5601에 포함되지 않는 확장 한글이라 ? 로 대체된다. 펲도 동일함

‘1’ 0x0031 è 0x31

따라서 출력결과는 다음과 같다. 0xC7 0xD1 0x20 0x3F 0x20 0x3F 0x20 0x31

2번라인 getBytes()에서 파라미터를 변경해서 다양한 인코딩 결과를 출력해보면 아래와 같다.

Default : 0xC7 0xD1 0x20 0x8C 0x63 0x20 0xBC 0x84 0x20 0x31   è file.encoding = ms949일때 예임. 파라미터 없이 getBytes() 호출하면 file.encoding값에 따라서 동작함
ISO-8859-1 : 0x3F 0x20 0x3F 0x20 0x3F 0x20 0x31   è 한글 코드인 0xD55C 0xB620 0xD3B2 모두 ? 변환된다. 모르는 코드들이니깐..
EUC-KR : 0xC7 0xD1 0x20 0x3F 0x20 0x3F 0x20 0x31    è KSC5601와 결과가 동일하다.
UTF-8 : 0xED 0x95 0x9C 0x20 0xEB 0x98 0xA0 0x20 0xED 0x8E 0xB2 0x20 0x31 è UTF-16에서 UTF-8변환된값..
ms949 : 0xC7 0xD1 0x20 0x8C 0x63 0x20 0xBC 0x84 0x20 0x31 è ,펲도 정상적으로 변환된다


한글<->8859변환

아래 코드는 유명한 한글과 8859_1간의 상호 변환 코드이다.

1      strTemp = 1”;

2      // Unicode 한글을 (ms949를 거쳐서)  8859-1로 변환..

3      strTemp = new String(strTemp.getBytes(“ms949"),"8859_1");

4       // 8859-1 String(ms949를 거쳐서) unicode로변환

5       strTemp = new String(strTemp.getBytes("8859_1")," ms949 ");  

예를 들어 외부 시스템과 I/O시에 해당 시스템이 ISO_8859_1 방식만을 지원한다면 한글 문자열은 변환과정을 거쳐서 저장하고 읽어와야 한다.

그 이유는 JAVA StringUTF-16을 지원하고, 외부 시스템은 ISO-8859-1만을 지원하므로 적절한 변환이 필요하다.

인터넷에 검색을 해보면 예제들은 99% “ms949” 대신 “ksc5601”를 사용하고 있다. 대부분 그 차이를 모르기 때문인 것 같다.

앞 페이지의 예제를 보듯이 KSC5601는 확장한글( ‘’,’8800여자)를 지원하지 못하기 때문에 ms949사용해야 한글 손실이 없다.

8859_1변환 ( 3번라인 )
     
strTemp = new String(strTemp.getBytes(“ms949"),"8859_1");

UTF-16 è ms949 è 8859-1 로 변환해야 한다.

ms949로 중간변환 없이 바로 strTemp.getBytes(8859_1”)로 한글을 바로 읽어오면.. 앞장에서와 같이 한글은 모두 ? 로 변경되어 버린다.

strTemp.getBytes(“ms949")를 수행하면.. 0xC7 0xD1 0x20 0x8C 0x63 0x20 0xBC 0x84 0x20 0x31 형태로 byte 배열형태로 읽어오고..

이를 8859_1로 변환해도..완전 동일한 0xC7 0xD1 0x20 0x8C 0x63 0x20 0xBC 0x84 0x20 0x31 값이 된다. ( 8859_10~0xFF까지 범위임)

최종적으로 strTemp에는 0x00C7 0x00D1 0x0020 0x008C 0x0063 0x0020 0x00BC 0x0084 0x0020 0x0031 형태 값이 된다.

ms949재변환  (5번 라인)
     
strTemp = new String(strTemp.getBytes("8859_1")," ms949 ");

8859-1 è ms949 è UTF-16 순서로 변환해야 한다.

외부 I/O를 통해서 받아온 데이터가 ISO-8859-1Encoding되어 String 변수에 0x00C7 0x00D1 0x0020 0x008C 0x0063 0x0020 0x00BC 0x0084 0x0020 0x0031 와 같은 형태로 저장되어 있을때..

이를 getBytes(“8859-1 “) 를 하면.. 0xC7 0xD1 0x20 0x8C 0x63 0x20 0xBC 0x84 0x20 0x31 값을 그대로 얻어오고..

“ms949” 파라미터에 의해.. 0xC7D1 0x20 0x8C63 0x20 0xBC84 0x20 0x31 같은 형태로 ms949 code값으로 묶어지고..
다시 해당 글씨들의 UNICODE값 치환된 UTF-16 형태인 0xD55C 0x0020 0xB620 0x0020 0xD3B2 0x0031 로 변환되어  strTemp로 최종적으로 저장된다.


인터넷에서 자료를 찾다보면 대부분 ms949 대신 euc-kr을 사용하고 있다. 하지만 java에서 ms949를 공식적으로 지원하고 있으므로 ms949를 사용하는게 바람직하다. 드믄경우지만 이름에 확장한글인 '믜'자을 사용하는 사람도 있으니..당연히 현대한글 11,172자를 표현가능한 ms949를 사용하는게 맞다.

'그외 주제들 > 한글처리' 카테고리의 다른 글

참고 자료..  (0) 2013.09.30
다양한 환경에서의 언어 설정  (0) 2013.09.30
Response 구간 정리  (0) 2013.09.30
Request 구간 정리  (0) 2013.09.30
JSP,Servlet에서 한글 문제를 피하려면..  (0) 2013.09.30
Posted by 행복한삶~!!
|

Response객체는 브라우저에 전달되는 HTML 결과 생성할 때 사용된다. Response객체의 Encoding CharterSet에 따라서 브라우저에서 출력되는 한글이 깨져보일수 있으므로 주위를 해야 한다. 하지만 걱정할 필요는 없다.
아래 제시되는 3가지 방법중 한 가지만 제대로 해도 한글 출력에 문제가 없다.
 

q
Response Charset에 따라서 출력되는 HTML Bodycharset에 영향을 미치게 된다.
qCharter set을 명시적으로 지정하라.
¤대략 3가지 방법으로 설정 가능하며 같은 효과가 있다.
1.Page 설정 통해서 설정
¡<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
¡pageEncoding 생략시 charset에 따라서 Page Encoding
2.함수 호출 1
Response.setCharacterEncoding(“UTF-8”);
Response.setContentType("text/html");
3.함수 호출 2
Response.setContentType("text/html;charset=UTF-8");
¤방법 1,2,3 중복해서 호출될 경우, 마지막 호출된 값이 유효하다.
¤하지만 PrintWriter pw = response.getWriter(); 함수 호출 이후에는 setCharacterEncoding(), setContentType() 함수가 호출되어도 무시된다.  
q명시적으로 Charset을 설정하지 않았다면 아래 단계로 디폴트 값 설정 됨
1.HTTP RequestContent-Language 참조
2.<locale-encoding-mapping-list> 정보를 web.xml에서 찾는다.
3.ISO-8859-1 을 사용한다.

qSRV.5.4 Response data Encoding ( servlet-2_5-mrel2-spec.pdf 에서 발췌 )

Servlets should set the locale and the character encoding of a response. The locale is set using the ServletResponse.setLocale method. The method can be called repeatedly; but calls made after the response is committed have no effect. If the servlet does not set the locale before the page is committed, the container’s default locale is used to determine the response’s locale, but no specification is made for the communication with a client, such as Content-Language header in the case of HTTP.

<locale-encoding-mapping-list>

<locale-encoding-mapping>

<locale>ja</locale>

<encoding>Shift_JIS</encoding>

</locale-encoding-mapping>

</locale-encoding-mapping-list>

If the element does not exist or does not provide a mapping, setLocale uses a container dependent mapping. The setCharacterEncoding, setContentType, and setLocale methods can be called repeatedly to change the character encoding.

Calls made after the servlet response’s getWriter method has been called or after the response is committed have no effect on the character encoding. Calls to setContentType set the character encoding only if the given content type string

provides a value for the charset attribute. Calls to setLocale set the character encoding only if neither setCharacterEncoding nor setContentType has set the character encoding before.

If the servlet does not specify a character encoding before the getWriter method of the ServletResponse interface is called or the response is committed, the default ISO-8859-1 is used.

Containers must communicate the locale and the character encoding used for the servlet response’s writer to the client if the protocol in use provides a way for doing so. In the case of HTTP, the locale is communicated via the Content-Language header, the character encoding 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.

'그외 주제들 > 한글처리' 카테고리의 다른 글

다양한 환경에서의 언어 설정  (0) 2013.09.30
자바에서 String 처리  (0) 2013.09.30
Request 구간 정리  (0) 2013.09.30
JSP,Servlet에서 한글 문제를 피하려면..  (0) 2013.09.30
Unicode ( 유니코드 )  (0) 2013.09.30
Posted by 행복한삶~!!
|

     브라우저에서 Form Post/Get할때 è WAS è JSP/Servlet Source 코드Request.getParameter(“ID”) 까지 과정에서 영향을 미치는 환경설정값과 동작을 설명하고자 한다.

q브라우저에서 Static Page 호출
¤<a Href=“targetpage.jsp”..> link </a> 형태로 jsp / Servlet / html 호출시에는 http get 으로 link를 호출하게 된다.  경우 브라우저에서 WAS로 전달되는 데이터가 없으므로 Request 과정에는 별다르게 고려할 사항이 없다.
q브라우저에서 Form Post/Get할때 è WAS è Source 코드- Request.getParameter(“ID”) 까지 과정
1.브라우저에서 Form 데이터  Encoding (Form Data) 하는 단계
1.기본적으로 뒤에 따로 정리된 Form 인코딩 방법에 따라서 Form Encoding을 수행하지만, 브라우저 특성에 따라서 약간씩 다르게 Encoding 한다.
2.WAS에서 Form 데이터를 Request 객체에 반영하는 단계
1.WAS에서는 client.encoding.override에 따라서 인코딩하여 값을 Request에 반영한다.
2.client.encoding.override 값이 없다면 ISO-8859-1인코딩 하어 Request 객체에 Form 데이터를 반영한다.
3.소스코드에서 Request Encoding Type 재 변경하는 단계
1.doGet(),doPost() or JSP에서 Request 객체의 Encoding type을 강제로 변경하고 싶다면  Request.setCharacterEncoding( “EncodingType“)을 호출하면 된다. client.encoding.override 가 적절하게 설정되어 있다면 굳이 호출할 필요가 없다.

1. 브라우저에서 Form 데이터  Encoding
¤Chrome IE Form Encoding 비교
¤IE8 Encoding Data ( CustomerID=한글똠펲123 )
¡http://localhost:9080/HelloJSP/FirstServlet?CustomerID=%C7%D1%B1%DB%26%2346624%3B%26%2354194%3B123
¡확장한글 변환 방식
¡확장한글은 Numeric character reference 방식의 유니코드로 변환된다.
http://en.wikipedia.org/wiki/Numeric_character_reference
¡=0xB620=46624 è %26%2346624%3B = &#46624;
¡유니코드 표기 형태로 변환되기 때문에 서버에서 어떻게 Encoding과정을 거치더라도IE에서는 확장한글이 정상적으로 표기된다.
¤Chrome Encoding Data ( CustomerID=한글똠펲123 )
¡http://localhost:9080/HelloJSP/getform.jsp?CustomerID=%C7%D1%B1%DB%8Cc%BC%84123

¡한글은 MS949코드값으로 Encoding된다.  

¤EUC-KR에 포함되지 않는 확장 한글이 서로 다르게 Encoding 처리한다.
¡ChromeW3의 가이드대로 Encoding 하지만, IE는 고유의 방식으로 인코딩한다.
¤Form Encoding 데이터가 다르기 때문에 JSP/Servlet에서 어떻게 처리해주는지에 따라서 브라우저마다 확장한글의 출력 결과가 다르게 나타날 수 있다.

                 (2013-10-22  추가) Form이 있는 JSP 파일의 Page encoding-type에 따라서 Form data encoding이 달라진다.. -_-; 
           위의 예는 <%@ page contentType="text/html; charset=euc-kr"%>형태로 euc-kr로 저장된 경우이고, 
           charset=ISO-8859-1이거나 따로 지정하지 않아서 default로 ISO-8859-1된는 경우의 파라미터 인코딩은 아래와 같다.
           동일하게  CustomerID=한글똠펲123을 form encoding한 결과는
         CustomerID
=%26%2354620%3B%26%2344544%3B%26%2346624%3B%26%2354194%3B123+
           와 같다 모든 한글이 Numeric character reference 로 표현된다. IE 및 Chrome모두 동일한 결과이다. 
           참 이해가 안가는 동작이다.. -_-; form jsp파일 page encoding이 왜 영향을 미치는 것일까?
           WAS에서 생성된 html파일은 결국 같고 브라우저 단에서 form encoding이 발생되는데..
           왜 html을 생성하는 jsp 파일의 page encoding이 form encoding에까지 영향을 미치는지 신기하기만 하다.. -_-;
           html 파일 자체 및 header viewer로 header를 비교해봐도 차이점이 없는데..어떤값에 영향을 받는지..
           좀 더 탐구가 필요하다..

                 모든 한글은 numeric character reference로 표현되므로, action jsp 나 servlet에서 request.getParameter("ID")를
           하면 한글깨지는 현상없이 그냥 잘 얻어온다. 심지어 request.setCharacterEncoding("euc-kr") 를 호출할 필요도
           없고, 어떤 encoding type에서도 한글은 정상적으로 얻어올 수 있다.


2. WAS단에서는 Form 데이터를 Request 객체에 반영
¤client.encoding.override 값에 따라서 Encoding된 결과가 Request객체에 반영됨.
¤Form Test 문자열 한글똠펲123”
 

client.encoding.overide
 
설정 값

Request.getParameter(“ID”) 결과

IE

비고

Chrome

비고

EUC-KR

한글똠펲123

한글??123

확장한글은 깨짐

ms949

한글똠펲123

한글똠펲123

모두 정상 출력됨

ISO-8859-1 or

미설정

??똠펲123

Encoding변환으로 

정상출력 가능함.

????123

Encoding변환으로 

정상출력 가능함.

UTF-8

한글똠펲123

JSP파일은
1.
<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %> 로 지정
2. ISO-8859-1로 지정
3. pageEncoding 및 Charset을 지정하지 않아 Default로 ISO-8859-1로 지정 되도록.

한글똠펲123

1.의 경우 form jsp 및 action jsp파일모두 utf-8로 일치해야 함

2,3의 경우 form jsp에서  form data encoding시에 Numeric character reference으로 한글이 encoding된다. 

¤client.encoding.overide 값이 없으면 ISO-8859-1 값이 Default 이다.
¤"ISO-8859-1 or 미설정"의 경우 아래와 같은 인코딩 변환으로 정상 출력이 가능하다.
¤Request.setCharacterEncoding(“ms949”) 호출 또는 String Encoding 변환.
String parameter = new String(
Resquest.getParameter(“ID”).getBytes(ISO-8859-1), “ms949”);

3. 소스코드에서 Request Encoding Type 변경
¤client.encoding.override 값이 잘 설정되어 있다면 JSP Servlet에서 굳이 Request.setCharacterEncoding을 호출할 필요가 없다.
¤예를 들어 client.encoding.override=ms949 이고 Request.setCharacterEncoding(“euc-kr”)을 호출한다면. 똠펲등의 확장한글은 모두 ?으로 변환된다. 그래서 Request.setCharacterEncoding를 호출할 때는 동작을 명확히 이해하고 호출해야 한다.
¤client.encoding.override 값이 미설정 상태라면 defaultISO-8859-1이 된다.
정상적으로 한글을 출력하기 위해서는 Request.setCharacterEncoding(“ms949”)getParameter하기전에 호출해야 한다.  또는 String parameter = new String( Resquest.getParameter(“ID”).getBytes(ISO-8859-1), “ms949”); 코드로 변환하여도 정상적으로 한글 출력을 할수 있다. 하지만 개별 문자열을 변환하기 보다는 Request.setCharacterEncoding(“ms949”)를 호출하는것이 더 적절한 문자열 처리 방식이다.
¤당연히 client.encoding.override=ms949설정 했을때도 동일하다.

qForm 인코딩 방법, application/x-www-form-urlencoded  
¤This is the default content type. Forms submitted with this content type must be encoded as follows:
¤Control names and values are escaped. Space characters are replaced by `+', and then reserved characters are escaped as described in [RFC1738], section 2.2: Non-alphanumeric characters are replaced by `%HH', a percent sign and two hexadecimal digits representing the ASCII code of the character. Line breaks are represented as "CR LF" pairs (i.e., `%0D%0A').
¤The control names/values are listed in the order they appear in the document. The name is separated from the value by `=' and name/value pairs are separated from each other by `&'.
q Request data encoding ( servlet-2_5-mrel2-spec.pdf 에서 발췌)

Currently, many browsers do not send a char encoding qualifier with the Content-

Type header, leaving open the determination of the character encoding for reading

HTTP requests. The default encoding of a request the container uses to create the

request reader and parse POST data must be “ISO-8859-1” if none has been

specified by the client request. However, in order to indicate to the developer in this

case the failure of the client to send a character encoding, the container returns null

from the getCharacterEncoding method.

If the client hasn’t set character encoding and the request data is encoded with

a different encoding than the default as described above, breakage can occur. To

remedy this situation, a new method setCharacterEncoding(String enc) has

been added to the ServletRequest interface. Developers can override the

character encoding supplied by the container by calling this method. It must be

called prior to parsing any post data or reading any input from the request. Calling

this method once data has been read will not affect the encoding.


'그외 주제들 > 한글처리' 카테고리의 다른 글

자바에서 String 처리  (0) 2013.09.30
Response 구간 정리  (0) 2013.09.30
JSP,Servlet에서 한글 문제를 피하려면..  (0) 2013.09.30
Unicode ( 유니코드 )  (0) 2013.09.30
문자셋과 인코딩  (0) 2013.09.30
Posted by 행복한삶~!!
|

한글 처리에 영향을 주는 곳

10여군대 이상의 곳에서 Encoding 관련 정보들이 있고, 한글 처리에 영향을 미칠수 있다. 
client 부터 WAS까지, WAS에서 DB 및 외부 I/O처리, 다시 WAS에서 Client까지 전 구간을 완벽하게 이해하는것은 어려운 일일수 있지만 몇가지만 정확하게 알고 있으면 한글 깨지는 문제는 피 할수 있다.
특별히 빨간색으로 표기된 부분의 환경설정이 중요하다.

한글 문제를 피하려면?

q몇 가지 환경설정만 잘하면된다.
¤전체 브라우징 과정을 살펴보면 많은 과정을 거치면서 10여군대 이상의 encoding관련 설정에 영향을 받는다. 모든 과정을 완벽히 이해하는것은 힘들지만 몇 가지 환경설정 및 핵심 구간의 동작을 이해하면 한글 문제를 할 수 있다.
¤필수 환경 설정
¤WAS JVM 설정
¤HTML Meta Tag
¤JSP 페이 설정
¤Servlet Response/Request 설정
¤DB 언어 설정
¤3가지 구간의 세부 동작을 이해하자!
¤브라우저부터 Request 객체까지
¡Static Page 호출 Form 데이터 수신 과정 이해
¤Java 언어에서의 Encoding 이해 및 외부 I/OEncoding 이해
¤Response 객체에서 Encoding 이해
q언어 처리는 크게 2가지 상황이 있다.
¤한글과 영어만 제대로 나오면 되는 경우 ( 다국어 처리를 고려하지 않음 )
¤한국어,중국어,일본어, 힌두어 등 다국어를 동시에 처리해야 하는 경우.

    한글과 영어만 고려한 환경설정 ( 다국어 처리를 고려하지 않음 )

qWAS JVM 설정
¤file.encoding=ms949, client.encoding.override=ms949
qHTML Meta Tag설정
¤<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
qJSP 페이지 설정
¤<%@ page pageEncoding=“ms949contentType="text/html;charset=ms949" %>
pageEncoding 생략시 charset 값으로 pageEncoding )
qServlet Response/Request 설정
¤HTTP 요청의 인코딩 지정 ( client.encoding.override가 정의되어 있다면 생략해도 됨 )
¤request.setCharacterEncoding(“ms949”);
¤HTTP 응답의 인코딩 지정
¤response.setContentType("text/html; charset=ms949"); or
response.setCharacterEncoding(“ms949");
q빨간색으로 표기된 ms949대신 euc-kr을 사용하면 euc-kr의 문제인 현대한글 중 2350자만 표현 가능한 문제가 발생한다. (,펲등의 한글이 깨짐) 그래서 euc-kr 대신 ms949를 사용하는것이 바람직하다. 
ms949가 비록 ms에서 만든 환영받지못한 Charter Set이지만, 오라클 DB, JAVA, 많은 WAS에서 대부분 지원하고 있는 표준의 역할을 하고 있다. ( 물론 unicode를 사용하지 않는 경우에 한해겠지만.. )
¤오라클도 ms949를 지원하므로 ms949 로 설정해야 현대한글이 모두 표현된다.
¤Html의 경우 charset=euc-kr로 을 줘도 브라우저에서 현대한글이 정상적으로 출력된다.
 
    다국어를 지원해야 하는 경우의 환경설정
q하나의 페이지에서 다국어를 입력,출력해야 한다면 모든 설정을 UTF-8로 통일시켜야 한다.
qWAS JVM 설정
¤file.encoding=UTF-8, client.encoding.override=UTF-8
qHTML 설정
¤<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
qJSP 페이지
¤<%@ page pageEncoding=“UTF-8" %> ( 생략가능, 생략시 charset 값으로 pageEncoding )
¤<%@ page contentType="text/html;charset=UTF-8" %>
qServlet 설정
¤HTTP 요청의 인코딩 지정
¤request.setCharacterEncoding(“UTF-8”);
¤HTTP 응답의 인코딩 지정
¤response.setContentType("text/html; charset=UTF-8"); or
response.setCharacterEncoding(“UTF-8");
qDBMS
¤DBMS 설정값도 UTF-8로 설정해야 한다

'그외 주제들 > 한글처리' 카테고리의 다른 글

Response 구간 정리  (0) 2013.09.30
Request 구간 정리  (0) 2013.09.30
Unicode ( 유니코드 )  (0) 2013.09.30
문자셋과 인코딩  (0) 2013.09.30
Character-Set & Encoding이란?  (0) 2013.09.30
Posted by 행복한삶~!!
|