1. apache.org 사이트에 가서 톰캣 다운로드, 톰캣 설치
2. 이클립스에서 server추가
3. ojdbc.jar 추가
New > Dynamic Web Project를 선택해서 프로젝트 생성
WebContent에서 New > Jsp파일 생성
파일명 : booklist.jsp
<%@ page import="java.sql.*" contentType="text/html;charset=EUC-KR" %>
<%
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@localhost:1521:XE";
Connection dbconn=DriverManager.getConnection(url,"madang","madang");
Statement stmt = dbconn.createStatement();
ResultSet myResultSet=stmt.executeQuery("select * from book");
%>
<html>
<head>
<meta charset="EUC-KR">
<title>** BOOK LIST **</title>
</head>
<body>
<table border="1">
<%
if (myResultSet != null) {
while(myResultSet.next()){
String W_BOOKID=myResultSet.getString("bookid");
String W_BOOKNAME=myResultSet.getString("bookname");
String W_PUBLISJER=myResultSet.getString("publisher");
String W_PRICE=myResultSet.getString("price");
%>
<tr>
<td><%=W_BOOKID%></td>
<td><a href="bookview.jsp?bookid=<%=W_BOOKID%>"><%=W_BOOKNAME%></a></td>
<td><%=W_PUBLISJER%></td>
<td><%=W_PRICE%></td>
</tr>
<%
}
}
stmt.close();
dbconn.close();
%>
</table>
</body>
</html>
파일명 : bookview.jsp
<%@ page import="java.sql.*" contentType="text/html; charset=EUC-KR" %>
<%
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:XE";
Connection dbconn=DriverManager.getConnection(url,"madang","madang");
Statement stmt = dbconn.createStatement();
String bookid=request.getParameter("bookid");
ResultSet myResultSet = stmt.executeQuery("select * from book where bookid='"+bookid+"'");
if(myResultSet!=null){
myResultSet.next();
%>
<html>
<head>
<meta charset="EUC-KR">
<title> ** Book VIEW ** </title>
</head>
<body>
<table border="1">
<tr>
<td>책제목</td>
<td><%=myResultSet.getString("BOOKNAME")%></td>
</tr>
<tr>
<td>출판사</td>
<td><%=myResultSet.getString("PUBLISHER")%></td>
</tr>
<tr>
<td>가격</td>
<td><%=myResultSet.getString("PRICE")%></td>
</tr>
</table>
<table>
<tr>
<td>
<a href="booklist.jsp">목록</a>
</td>
</tr>
</table>
<%
}
stmt.close();
dbconn.close();
%>
</body>
</html>
'IT > Jsp' 카테고리의 다른 글
jsp - form 태그에서 서버로 값 넘길 때 한글깨짐 처리 (get, post 방식) (0) | 2018.09.03 |
---|---|
jsp - form 입력값 전송, request 객체, request.getParameter("파라미터이름") (0) | 2018.09.03 |
jsp - 스크립틀릿(scriptlet), 선언문, out.println, (0) | 2018.09.02 |
jsp - include, jspf (0) | 2018.09.01 |
jsp, java, 오라클, db 연결해서 json 출력하기 (0) | 2018.08.23 |