notice1.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="<a href='http://code.jquery.com/jquery-1.11.1.min.js">[removed]http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(function() {
success:function(data){
$(data).find('obj').each(function(){
var num='<tr><td>'+$(this).find('num').text()+'</td></tr>';
var title='<tr><td>'+$(this).find('title').text()+'</td></tr>';
var content='<tr><td>'+$(this).find('content').text()+'</td></tr>';
var reg_date='<tr><td>'+$(this).find('reg_date').text()+'</td></tr>';
var readcount='<tr><td>'+$(this).find('readcount').text()+'</td></tr>';
$('table > tbody').append('<tr>'+num+title+content+reg_date+'</tr>');
});
}
});
});
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<table border="1" id="output">
<thead>
<tr>
<th>글번호</th>
<th>제목</th>
<th>내용</th>
<th>날짜</th>
<th>조회수</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>
</body>
</html>
notice.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*, org.json.simple.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String url = "jdbc:mysql://localhost:3306/leeyoungi";
String id = "root";
String pw = "1111";
Connection con;
Statement stmt = null;
ResultSet rs;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url,id,pw);
stmt = con.createStatement();
String sql = "select num,title,content,reg_date,readcount from notice";
rs = stmt.executeQuery(sql);
JSONArray arr = new JSONArray();
while (rs.next()) {
int num = rs.getInt("num");
String title = rs.getString("title");
String content = rs.getString("content");
Date reg_date = rs.getDate("reg_date");
int readcount=rs.getInt("readcount");
JSONObject obj = new JSONObject();
obj.put("reg_date", reg_date);
obj.put("readcount", readcount);
obj.put("num",num);
obj.put("title", title);
obj.put("content", content);
if(obj != null)
arr.add(obj);
}
out.print(arr);
} catch (Exception e) {
e.printStackTrace();
}
%>
</body>
</html>
json으로해서 파싱해서 ajax로 출력을 할려고하는데 출력이안되는데 문제가 먼지 모르겟어요... 문제점과 해결책좀 알려주세요.
댓글 0