728x90

포인트

문자형 UTF-8 인코딩 하기
java.net.URLEncoder.encode(L_searchword,"UTF-8")


String encStr = java.netURLEncoder.encode("주식", "UTF-8");

sntStr 결과값 = > %EC%A3%BC%EC%8B%9D




JSP페이지에서 문자열 encoding / decofing처리 부분 예제 >>

<%!
    public static void setCookie(HttpServletResponse response, String name, String value) {
        value = java.net.URLEncoder.encode(value);
        Cookie cookie = new Cookie(name, value);
        cookie.setMaxAge(60*60*24*31); // 31일
        response.addCookie(cookie);
    }
    public static String getCookie(HttpServletRequest request, String cookieName) {
        Cookie [] cookies = request.getCookies();
        String value = "";
        for(int i=0;i<cookies.length;i++) {
            if(cookieName.equals(cookies[i].getName())) {
                value = java.net.URLDecoder.decode(cookies[i].getValue());
                break;
            }
        }
        return value;
    }
%>


사용예 >>

    // 쿠키 확인하기
    String tmpStr = "";
    boolean isHit = false;
    tmpStr = getCookie (request, "blog_grade");
    if ( !tmpStr.equals("") ) {
        if ( tmpStr.indexOf("["+L_postno+"]") > -1) isHit = true;
    }


   //쿠키 없으면 생성하기
   if ( !isHit ) {
        tmpStr += "["+L_postno+"]";
        setCookie (response, "blog_grade", tmpStr);
        // DB 처리.
        Sql="update n2_board set b_hit=b_hit+1 where b_idx="+L_num;
        db.executeQuery (Sql);
    }



출처 : http://edit.tistory.com/entry/JSP한글파라미더-UTF-8처리

Posted by 앗뜨거
,