본문 바로가기
프로젝트/JSP 게시판 만들기

JSP 게시판 만들기 7

by 리드민 2022. 8. 30.
반응형

1] 개발 환경

hardware
cpu : intel i7-5820k, gpu : nvidia gtx 970, ram : ddr4 16GB, mainboard : x99a chipset 2011V3 board, secondary storage : 1TB SSD, 4TB HDD
OS
windows pro 64bits

 

software
jdk version 1.8.0_301
eclipse version 2022-06 (4.24.0)
apache-tomcat version 9.0.54
oracle Database 18c

 

[2] 목적

  이클립스 프로그램, oracle Database, apache-tomcat을 이용해서 게시판을 만드는 것을 목적으로 한다. 사용 언어는 html, css, java, javascript이다. sql 쿼리문도 사용한다. 과정이 길기 때문에 시리즈로 쓸 예정이다.

 

[3] 이 게시물에서 하는 것

  게시물 삭제, 게시물 수정

 

[4] 프로그램 코드

() delete.jsp

project folder > src > main > webapp > board > delete.jsp

<%@page import="com.jsp.board.BoardDAO"%>
<%@ 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>
	
	<%
		String strID = request.getParameter("bId");
		
		BoardDAO dao = BoardDAO.getInstance();
		
		int result = dao.delete(strID);
		
		if(result == 1){
	%>
			<script>
				alert('해당글이 삭제되었습니다.');
				window.location = 'boardList.jsp';
			</script>
	
	<%
		}else{
	%>
			<script>
				alert('해당글이 삭제되지 않았습니다.');
				window.location = 'boardList.jsp';
			</script>
	<%
		}
	%>
	
	
	
</body>
</html>

 

() modifyForm.jsp

project folder > src > main > webapp > board > modifyForm.jsp

<%@page import="com.jsp.board.BoardDTO"%>
<%@page import="com.jsp.board.BoardDAO"%>
<%@ 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>

<!-- 부트스트랩 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

<style type="text/css">
	table{
		width : 50% !important;
		margin-left:25%; 
    	margin-right:25%;
		
	}
</style>

</head>
<body>
	<%
		request.setCharacterEncoding("UTF-8");
	%>
	
	<%--
		넘어온 파라미터를 EL param 객체로 채우기
	 --%>

	
	<br><h1 style="text-align: center;">게시글 수정</h1><br>
	
	<form action="modifyCheck.jsp" method="post" accept-charset="UTF-8">
		<input type="hidden" name="bId" value="${param.bId }">
		<table class="table table-bordered">
			<tr> 
				<th scope="col">번호</th>
				<td>${param.bId }</td>
			</tr>
			
			<tr>
				<th scope="col">조회수</th>
				<td>${param.bHit } </td>
			</tr>
			
			<tr>
				<th scope="col">이름</th>
				<td> <input type="text" name="bName" value="${param.bName }"></td>
			</tr>
			
			<tr>
				<th scope="col">제목</th>
				<td> <input type="text" name="bTitle" value="${param.bTitle }"></td>
			</tr>
			
			<tr>
				<th scope="col">내용</th>
				<td> 
					<textarea rows="10" cols="30" name="bContent" >${param.bContent}</textarea>
				</td>
			</tr>
			
			<tr>
				<td colspan="2"> 
					<a href="boardList.jsp">목록보기</a> &nbsp;&nbsp;&nbsp;&nbsp;
					<input type="submit" value="수정"> 
				</td>
			</tr>
			
		</table>
	</form>
	
	<!-- 부트스트랩 자바스크립트 -->
	<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</body>
</html>

 

() modifyCheck.jsp

project folder > src > main > webapp > board > modifyCheck.jsp

<%@page import="com.jsp.board.BoardDAO"%>
<%@ 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>
	
	<%--
		1. 넘어온 데이터 받기
		2. DAO 객체 생성하기
		3. write 메소드 호출 후 결과값 얻기
		4. 결과값을 얻은 후에 로직 처리하기 
		  (boardList.jsp로 이동하기)
	 --%>
	
	<%
		request.setCharacterEncoding("UTF-8");
		
		String bName = request.getParameter("bName");
		String bTitle = request.getParameter("bTitle");
		String bContent = request.getParameter("bContent");
		
		BoardDAO dao = BoardDAO.getInstance();
		
		int result = dao.write(bName, bTitle, bContent);
	
		if(result == 1){
	%>
			<script>
				alert('글이 등록되었습니다.');
				window.location = 'boardList.jsp';
			</script>
	
	<%
		}else{
	%>
			<script>
				alert('글이 등록되지 않았습니다.');
				window.location = 'boardList.jsp';
			</script>
	<%
		}
	%>
	
	
</body>
</html>

반응형

'프로젝트 > JSP 게시판 만들기' 카테고리의 다른 글

JSP 게시판 만들기 8(후기)  (0) 2022.08.31
JSP 게시판 만들기 6  (0) 2022.08.28
JSP 게시판 만들기 5  (0) 2022.08.28
JSP 게시판 만들기 4  (0) 2022.08.24
JSP 게시판 만들기 3  (0) 2022.08.20