이 블로그 검색

2011년 1월 17일 월요일

jsp에서 xml생성

  • jsp에서 xml생성 : 
         제일 윗줄을  <%@ page contentType="text/xml; charset=EUC-KR"%>로 변경해야 되는 경우도 있다.
           (이유는 모름)
    <?xml version="1.0" encoding="euc-kr" ?>
    <%@ page contentType="text/xml; charset=euc-kr" %>
    <%@ page import = "java.sql.Connection" %>
    <%@ page import = "java.sql.Statement" %>
    <%@ page import = "java.sql.ResultSet" %>
    <%@ page import = "java.sql.SQLException" %>
    <%@ page import = "util.Util" %>
    <%@ page import = "util.DB" %>
    <%
     Connection conn = null;
     Statement stmt = null;
     ResultSet rs = null;
     try {
      conn = DB.getConnection();
      stmt = conn.createStatement();
      rs = stmt.executeQuery("select * from COMMENT order by ID");
    %>
    <result>
     <code>success</code>
     <data><![CDATA[
     [
    <%
      if (rs.next()) {
       do {
        if (rs.getRow() > 1) { %>
      ,
    <%
        }
    %>
      {
       id: <%= rs.getInt("ID") %>,
       name: '<%= rs.getString("NAME") %>',
       content: '<%= rs.getString("CONTENT") %>',
       mclass: '<%= rs.getInt("mClass") %>'
      }
    <%
       } while(rs.next());
      }
    %>
     ]
     ]]></data>
    </result>
    <% } catch(Throwable e) {
      out.clearBuffer();
     %>
    <result>
     <code>error</code>
     <message><![CDATA[<%= e.getMessage() %>]]></message>
    </result>
    <% } finally {
      if (rs != null) try { rs.close(); } catch(SQLException ex) {}
      if (stmt != null) try { stmt.close(); } catch(SQLException ex) {}
      if (conn != null) try { conn.close(); } catch(SQLException ex) {}
     }
    %>
    [출처] JSP + Ajax XML|작성자 시골사람

    댓글 없음:

    댓글 쓰기