2013년 7월 18일 목요일

(130718) 19일차 BoardList.jsp (JSTL 표준 태그 라이브러리 - SQL 태그 테스트)

 - 국제화 태그 부분은 포스팅 생략

 - BoardList.jsp 소스 (JSTL의 SQL 태그를 통해서 데이터베이스에 직접 연결하기)
<%@page import="java.util.Vector"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<!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=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<center>
<h2> 게 시 판 목 록 </h2>
<table border = "1" width = "740" cellpadding="4" cellspacing="2">
<tr bgcolor = "FFFFFFF">
  <th width = "50"> 번호 </th>
  <th width = "330"> 제목 </th>
  <th width = "130"> 작성자 </th>
  <th width = "130"> 날짜 </th>
  <th width = "80"> 조회수 </th>
</tr>
 
  <!-- 커넥션 설정 -->
  <sql:setDataSource
  url = "jdbc:oracle:thin:@127.0.0.1:1521:XE"
  driver = "oracle.jdbc.driver.OracleDriver"
  user = "system"
  password = "123456"
  var = "ds"
  />
 
  <!-- 데이터 베이스에서 가져올 쿼리 설정 및 실행 -->
  <sql:query var = "rs" dataSource = "${ds}">
  select num, subject, writer, reg_date, readcount from bboard
  </sql:query>
 
  <!-- rowsByIndex는 해당 개수만큼의 row - 열을 얻어오는 것 -->
  <c:forEach var = "row" items="${rs.rowsByIndex}">
  <tr>
  <!-- 각 해당 열의 col - 행을 출력 -->
  <c:forEach var = "col" items="${row}">
  <td> <c:out value="${col}"/> </td>
  </c:forEach>
  </tr>
  </c:forEach>

  </table>
</center>
</body>
</html>


 - 결과