본문 바로가기
웹 프로그래밍(풀스택-->java)/웹프로그래밍(백엔드-->java)

34. Jsp 게시판 - Dao 클래스 설정, BoardWriteForm

by 백엔드개발자0107 2021. 12. 5.

오늘은 BoardWriteForm.jsp와 BoardDAO클래스를 만들어 보았다.

 

BoardWriteForm.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

<center>
<h2>게시글 쓰기 </h2>

<form action="BoardWriteProc.jsp" method="post">
<table width ="600" border="1" bordercolor="gray" bgcolor="skyblue">
	<tr height="40">
	<td align="center" width="150">작성자</td>
	<td align="center" width="450"> <input type="text" name="writer" size="60"> </td>
	</tr>
	<tr height="40">
	<td align="center" width="150">제목</td>
	<td align="center" width="450"> <input type="text" name="subject" size="60"> </td>
	</tr>
	<tr height="40">
	<td align="center" width="150">이메일</td>
	<td align="center" width="450"> <input type="email" name="email" size="60"> </td>
	</tr>
	<tr height="40">
	<td align="center" width="150">비밀번호</td>
	<td align="center" width="450"> <input type="password" name="password" size="60"> </td>
	</tr>
	<tr height="40">
	<td align="center" width="150">글내용 </td>
	<td align="center" width="450"> <textarea rows="10" cols="50" name="content" size="60"></textarea> </td>
	</tr>
	<tr height="40">
	<td align="center" colspan="2">
	 <input type="submit"  value="글쓰기">&nbsp;&nbsp;
	 <input type="reset"  value="다시작성">&nbsp;&nbsp;
	 <button onclick="location.href='BoardList.jsp' ">전체게시글보기</button>
	  </td>
	</tr>

</table>
</form>
</center>


</body>
</html>

BoardDAO.class

package db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class BoardDAO {

	Connection con;
	PreparedStatement pstmt;
	ResultSet rs;
	
	//데이터베이스의 커넥션풀을 사용하도록 설정하는 메소드 
	public void getCon() {
		
		try {
			
			Context initctx = new InitialContext();
			Context envctx =(Context) initctx.lookup("java:comp/env");
			DataSource ds = (DataSource)envctx.lookup("jdbc/pool");
			//datascource
			con = ds.getConnection();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
	}
	
	
	
}

위 코드들을 잘 보고 이해하자.!