jsp mysql 에서 한글로 입력받는 방법..

aNsITAte의 이미지

http://sapius.dnip.net/~sapius/zpboard/list.jsp

이상하게 한글이 깨져서 나오네요.

아무래도 mysql 에서 불러올때 코드셋이 틀력서 그런거 같은데..

어떻게 해결해야할까요? 설명으로 나온책에는 이런 말은 없는데 ㅡ.ㅡ;;

<%@page contentType="text/html; charset=euc-kr" import="java.sql.*,java.util.*"%>

<%
/*
 * Data Base Connection to Zeropage BBS
 */
        String DB_URL = "jdbc:mysql://165.194.17.15:3306/zeropage";
        String DB_USER = "ID";
        String DB_PASSWORD = "PASS";

        try {
                Class.forName("com.mysql.jdbc.Driver");
        } catch (Exception e) {
                out.println("DB Driver eror<BR/>\n");
                e.printStackTrace();
        }

        Connection conn;
        conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);

        if (conn == null)
                out.println("Connection error<BR/>\n");

        Statement stmt;
        stmt = conn.createStatement();
        if (stmt != null) out.println("Connection SUCCESS<BR/>\n");
%>

<%
        /* get data from zeropage mysql server.  */
//      String query = "select * from open where ";
        String query = "select * from open where id>0 AND id<10";
        ResultSet result = stmt.executeQuery(query);
%>

<%
        Vector id = new Vector();
        Vector date = new Vector();
        Vector loginid = new Vector();
        Vector author = new Vector();
        Vector email = new Vector();
        Vector title = new Vector();
        Vector content = new Vector();
        Vector count = new Vector();

        while (result.next()) {
                id.add(result.getString("id"));
                date.add(result.getString("date"));
                loginid.add(result.getString("loginid"));
                author.add(result.getString("auther"));
                email.add(result.getString("email"));
                title.add(result.getString("title"));
                content.add(result.getString("content"));
                count.add(result.getString("count"));
        }
%>

<%
        out.println("<table style='border-width:1px; border-style:dotted;'>");
        out.println("<tr><td>ID</td><td>DATE</td><td>AUTHOR</td><td>EMAIL</td><td>TITLE</td><td>CONTENT</td><td>COUNT</td></tr>");
        for (int i=0; i<id.size(); i++) {
                out.println(
                                "<!--"+i+"-->\n"+
                                "<tr>\n<td>"+id.get(i)+"</td>\n"+
                                "<td>"+date.get(i)+"</td>\n"+
                                "<td>"+author.get(i)+"</td>\n"+
                                "<td>"+email.get(i)+"</td>\n"+
                                "<td>"+title.get(i)+"</td>\n"+
                                "<td>"+content.get(i)+"</td>\n"+
                                "<td>"+count.get(i)+"</td>\n</tr>"
                                );
        }
        out.println("</table>");
%>

<%
        //Connection close.
        stmt.close();
        conn.close();
%>
aNsITAte의 이미지

JSP하면서 삽질 정말 넌덜머리 날 정도로 하는 것 같습니다.

JSP보타 톰캣설정이 너 어려운것 같네요.

어쨌든 mysql Connector/J 가 3.1이 되면서 문자셋을 설정하는 예약어가

바뀐것 같습니다.

(정확한건지 아니면 그런건지는 ;;)

String DB_URL = "jdbc:mysql://165.194.17.15:3306/zeropage";
String DB_OPT = "useUnicode=true&characterEncoding=KS5601";
String DB_USER = "ID";
String DB_PASSWORD = "PASSWD";
Connection conn = DriverManager.getConnection(DB_URL+'?'+DB_OPT, DB_USER, DB_PASSWORD);

이전버전의 경우 이런식으로 하면 SQL에서 읽어온 데이터를 한글로 출력하는데 큰 문제가 없었습니다.

그런데 3.1버전에서 위와 같은 소스로 돌려보니 문제가 생기더라구요.

mysql 사이트에서 문서를 찾으니까

http://dev.mysql.com/doc/connector/j/en/cj-character-sets.html

MySQL Character Set Name Java-Style Character Encoding Name
usa7 US-ASCII
big5 Big5
gbk GBK
sjis SJIS
gb2312 EUC_CN
ujis EUC_JP
euc_kr EUC_KR
latin1 ISO8859_1
latin1_de ISO8859_1
german1 ISO8859_1
danish ISO8859_1
latin2 ISO8859_2
czech ISO8859_2
hungarian ISO8859_2
croat ISO8859_2
greek ISO8859_7
hebrew ISO8859_8
latin5 ISO8859_9
latvian ISO8859_13
latvian1 ISO8859_13
estonia ISO8859_13
dos Cp437
pclatin2 Cp852
cp866 Cp866
koi8_ru KOI8_R
tis620 TIS620
win1250 Cp1250
win1250ch Cp1250
win1251 Cp1251
cp1251 Cp1251
win1251ukr Cp1251
cp1257 Cp1257
macroman MacRoman
macce MacCentralEurope
utf8 UTF-8
ucs2 UnicodeBig

보니까 JAVA 스타일의 인코딩 명이 EUC_KR 입니다.

그래서

{{{
String DB_URL = "jdbc:mysql://165.194.17.15:3306/zeropage";
String DB_OPT = "useUnicode=true&characterEncoding=EUC_KR";
String DB_USER = "ID";
String DB_PASSWORD = "PASSWD";
Connection conn = DriverManager.getConnection(DB_URL+'?'+DB_OPT, DB_USER, DB_PASSWORD);
}}}

로 지정하니까 제대로 나오네요.

EUC-KR 은 안되구요. 가운데 대쉬는 반드시 언더바로 해야합니다.

http://sapius.dnip.net/~sapius/zpboard/list.jsp

이렇게 잘 나오네요.

그립다는 것은 아직도 네가 내 안에 남아 있다는 뜻이다.
그립다는 것은 지금은 너를 볼 수 없다는 뜻이다.
볼 수는 없지만 보이지 않는 내 안 어느 곳에 네가 남아 있다는 뜻이다.
-이정하의 《혼자 사랑한다는 것은》중에서-

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.