Programming/JSP

[JSP] 게시판 CRUD 구현 (+이모티콘)

너굴위 2023. 10. 4. 12:14
728x90
반응형

< 지난 포스팅 정리 >

- DB에서 데이터조작 후 각 변화되거나 불러온 데이터들을 게시판 각각 위치에 html형식으로 배치할 수 있도록 함

- 이모티콘 게시판: 다른 내용 저장방식은 동일, 이모티콘은 동물출력 예제 사용하여

String[] values = request.getParameterValues("pet");

으로 선택된 이모티콘을 저장할수 있도록 함.

 

UI

    1. 목업(wireframe)

         => 디자인의 흐름

         => 프로그램 요소 추출

              UML

              ERD

              DFD

 

Tip.

- 이모티콘의 이름과 경로에 쓰이는 value이름을 동일하게 사용하여 헷갈리는 부분을 없애기

- 제작한 데이터베이스나 테이블 명령어는 설정 파일로 정리하여 보관하기

- 실무에서도 원본파일은 건들지 않고 복제본으로 작업하도록 함

 


* 기본 CRUD 게시판 코드에서 추가 데이터 입력 후 밑에 글 목록 이동할 수 있는 기능 제작하기.

paging

- 데이터의 개수를 지정 (한 페이지당) -> 기본적으로 10개정도로 지정

- 페이지 > >> 를 통해서 넘어갈 수 있도록 함

 

페이지 번호     데이터개수                레코드시작 위치

cpage              recordPerPage          skip

1                      10                              0

2                      10                              10

3                      10                              20

 

skip= (cpage-1)*recordPerPage

 

마지막 페이지

전체 레코드       데이터 개수           전체 페이지수

totalRecord        recordPerPage      totalPage

0                        10                           1

1                        10                           1

2

 

10까지 

 

총 페이지 수를 알 수 있도록 하는 식.

totalPage = ((totalRecord -1) / recordPerPage)+1   

 

 


 

 

 

 

보여질 페이지 목록

cpage          보여질 페이지 갯수                시작블럭위치

                    blockPerPage                         startBlock

1                    5개씩                                     1                ...5

2

5

 

6                  5개씩                                       6                  ...10 

 =============================================

startBlock = cpage - (cpage-1) % blockPerPage

endBlock = cpage - (cpage-1) %blockPerPage+blockPerPage-1

if(endBlock >= totalPage){

               endBlock = totalPage;

}

 

=============================================

board_list1.jsp

       (cpage)

       board_write1.jsp     board_write1_ok.jsp

      (cpage)

       board_view1.jsp

                       (cpage)                      (cpage)

                       board_modify1.jsp     board_modify1_ok.jsp

                     (cpage)

                      board_delete1.jsp      board_delete1_ok.jsp

 

-> 목록으로 돌아갔을 때 보던 목록 그대로 돌아갈 수 있도록 한다.

 

 


이모티콘 포함 게시판 코드

board_list1.jsp  - 제목앞에 이모티콘이 나타날 수 있도록 함
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>


<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>
<%@ page import="javax.sql.DataSource" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.PreparedStatement"%>
<%@ page import="java.sql.ResultSet"%>




<%


request.setCharacterEncoding("utf-8");


//페이지가 없다면 무조건 1페이지로 설정
int cpage=1;




if(request.getParameter("cpage")!=null&&!request.getParameter("cpage").equals("")){ //경로에서 cpage를 받아 파라미터를 가져올 수 있도록 한다.
cpage =Integer.parseInt(request.getParameter("cpage"));
}




//페이지 당 10개씩 자료를 보여줌
int recordPerPage=10;
int totalPage=0;


int blockPerPage=5;




Connection conn=null;
PreparedStatement pstmt =null;
ResultSet rs = null;


int totalRecord=0;


StringBuilder sbHtml = new StringBuilder();


try{
Context initCtx = new InitialContext();
Context envCtx =(Context)initCtx.lookup("java:comp/env");
DataSource dataSource = (DataSource)envCtx.lookup("jdbc/mariadb3");
conn = dataSource.getConnection();


//datediff를 통해 현재날짜와 글 등록 날짜 사이의 차이를 계산하여 24시간 이내에 작성된 글인지 확인할 수 있다.
String sql = "select seq, subject, writer, emot, date_format(wdate,'%Y-%m-%d') wdate, hit, datediff(now(),wdate)wgap from emot_board1 order by seq desc"; //글 등록번호를 기준으로 목록을 내림차순 정리
pstmt = conn.prepareStatement(sql);




rs = pstmt.executeQuery();


//데이터의 총 개수
rs.last();
totalRecord= rs.getRow();
rs.beforeFirst();


totalPage = ((totalRecord -1) / recordPerPage)+1;


int skip =(cpage-1)*recordPerPage; //skip: 어디부터 읽을 지 지정해준다
if(skip!=0)rs.absolute(skip);


for(int i=0;i<recordPerPage&&rs.next();i++){ //데이터를 읽고 append를 통해 표 형식으로 출력
String seq = rs.getString("seq");
String subject = rs.getString("subject");
String writer = rs.getString("writer");
String emot = rs.getString("emot");
String wdate = rs.getString("wdate");
String hit = rs.getString("hit");
int wgap = rs.getInt("wgap");


//System.out.println("이모티콘"+emot);




sbHtml.append("<tr>");
//sbHtml.append("<td>&nbsp;</td>");
sbHtml.append("<td>"+"<img src='../../images/emoticon/emot"+emot+".png' width='15'/>"+"</td>");
sbHtml.append("<td>"+seq+"</td>");
sbHtml.append("<td class='left'>");
sbHtml.append("<a href='board_view1.jsp?cpage="+cpage+"&seq="+seq+"'>"+subject+"</a>&nbsp;");
if(wgap==0){
sbHtml.append("<img src='../../images/icon_new.gif' alt='NEW'>"); //조건에 따라 html태그도 뺐다가 넣었다가 할 수 있다.
}
sbHtml.append("</td>"); //get방식으로 seq를 가지고 감(공백 없이 가지고 가야함)
sbHtml.append("<td>"+writer+"</td>"); //nbsp (스페이스바)
sbHtml.append("<td>"+wdate+"</td>");
sbHtml.append("<td>"+hit+"</td>");
sbHtml.append("<td>&nbsp;</td>");
sbHtml.append("</tr>");
}


} catch(NamingException e){
System.out.println( "[에러] " + e.getMessage() );
} catch(SQLException e){
System.out.println( "[에러] " + e.getMessage() );
} finally {
if(rs!=null)rs.close();
if(pstmt!=null)pstmt.close();
if(conn!=null)conn.close();
}



%>


<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="../../css/board.css">
</head>


<body>
<!-- 상단 디자인 -->
<div class="con_title">
<h3>게시판</h3>
<p>HOME &gt; 게시판 &gt; <strong>게시판</strong></p>
</div>
<div class="con_txt">
<div class="contents_sub">
<div class="board_top">
<div class="bold"><span class="txt_orange">1</span></div>
</div>


<!--게시판-->
<div class="board">
<table>
<tr>
<th width="3%">&nbsp;</th>
<th width="5%">번호</th>
<th>제목</th>
<th width="10%">글쓴이</th>
<th width="17%">등록일</th>
<th width="5%">조회</th>
<th width="3%">&nbsp;</th>
</tr>
<!-- 시작 -->
<%=sbHtml.toString() %>
<!---->
</table>
</div>


<div class="btn_area">
<div class="align_right">
<input type="button" value="쓰기" class="btn_write btn_txt01" style="cursor: pointer;" onclick="location.href='board_write1.jsp?cpage=<%=cpage %>'" /> <!--목록에서 게시물 작성활 때 cpage를 넘겨 현재 어디목록에서 작성을 시도하는 것인지에 대한 파라미터를 넘겨준다. -->
</div>




<!--페이지넘버-->
<div class="paginate_regular">
<div align="absmiddle">
<!-- << -->




<%


int startBlock = cpage - (cpage-1) % blockPerPage;
int endBlock = cpage - (cpage-1) %blockPerPage+blockPerPage-1;
if(endBlock >= totalPage){


endBlock = totalPage;
}




if(startBlock==1){ //<< //첫블록계산이 1이면 첫페이지이므로 이동없음
out.println("<span><a>&lt;&lt;</a></span>");
out.println("&nbsp;");
}else{ // 첫블록이 아니라면 다음 블록의 처음으로 이동
out.println("<span><a href='board_list1.jsp?cpage="+(startBlock-blockPerPage)+"'>&lt;&lt;</a></span>");
out.println("&nbsp;");
}






if(cpage==1){ //<
out.println("<span><a>&lt;</a></span>");
}else{
out.println("<span><a href='board_list1.jsp?cpage="+(cpage-1)+"'>&lt;</a></span>");
}








for(int i=startBlock; i<=endBlock;i++){ // 1부터 마지막까지 링크걸기


//현재 페이지에 대한 번호를 링크로 가져와서 10개씩 띄울 수 있도록 한다.
if(i==cpage){
out.println("<span><a href='board_list1.jsp?cpage="+i+"'>["+i+"]</a></span>"); //cpage의 값이 i의 값과 같으면 []로 표시할 수 있도록 함
}else{
out.println("<span><a href='board_list1.jsp?cpage="+i+"'>"+i+"</a></span>"); //그 외는 기본으로 나올 수 있도록 함
}
}




//<span><a>[ 1 ]</a></span>
//<span><a href="board_list1.jsp">2</a></span>
//<span><a href="board_list1.jsp">3</a></span>


out.println("&nbsp;&nbsp");


if(cpage==totalPage){
out.println("<span><a>&gt;</a></span>");
}else{
out.println("<span><a href='board_list1.jsp?cpage="+(cpage+1)+"'>&gt;</a></span>");
}




if(endBlock==totalPage){ //>> //끝블록이면 이동 없음
out.println("<span><a>&gt;&gt;</a></span>");
out.println("&nbsp;");
}else{ //끝블록이 아니라면 한블럭채로 이동
out.println("<span><a href='board_list1.jsp?cpage="+(startBlock+blockPerPage)+"'>&gt;&gt;</a></span>");
out.println("&nbsp;");
}


%>


</div>
</div>
<!--//페이지넘버-->


</div>
<!--//게시판-->
</div>
</div>
<!--//하단 디자인 -->


</body>
</html>

 

board_view1.jsp - 제목 앞에 이모티콘이 나타날 수 있도록 하는 상세보기
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>


<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>


<%@ page import="javax.sql.DataSource" %>


<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.PreparedStatement"%>
<%@ page import="java.sql.ResultSet"%>
<!-- 제목 내용 앞에 ()안에 저장한 이모티콘 넣기 -->
<%




request.setCharacterEncoding("utf-8");


String cpage=request.getParameter("cpage");
String seq = request.getParameter("seq"); //파라미터를 넘겨 등록 번호를 변수에 저장
System.out.println(seq);


String subject="";
String emot="";
String writer ="";
String mail="";
String wip="";
String hit="";
String content="";
String wdate="";




Connection conn=null;
PreparedStatement pstmt =null;
ResultSet rs = null;




try{
Context initCtx = new InitialContext();
Context envCtx =(Context)initCtx.lookup("java:comp/env");
DataSource dataSource = (DataSource)envCtx.lookup("jdbc/mariadb3");
conn = dataSource.getConnection();


String sql = "update emot_board1 set hit=hit+1 where seq=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,seq);


pstmt.executeUpdate();


sql ="select seq, subject,emot, writer, mail, wip, wdate, hit, content from emot_board1 where seq=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,seq);


rs = pstmt.executeQuery();
//데이터가 하나이기 때문에 while사용할 필요 없음
if(rs.next()){
subject= rs.getString("subject");
emot=rs.getString("emot");
writer =rs.getString("writer");
mail=rs.getString("mail");
wip=rs.getString("wip");
hit=rs.getString("hit");
content=rs.getString("content") == null? "": rs.getString("content").replaceAll("\n","<br />"); //엔터키를 html에서는 br로 인식하여 엔터키로 받을 수 있도록 문자열의 형태를 변경한다.
wdate=rs.getString("wdate");
}


} catch(NamingException e){
System.out.println( "[에러] " + e.getMessage() );
} catch(SQLException e){
System.out.println( "[에러] " + e.getMessage() );
} finally {
if(rs!=null)rs.close();
if(pstmt!=null)pstmt.close();
if(conn!=null)conn.close();
}



%>


<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="../../css/board.css">
</head>


<body>
<!-- 상단 디자인 -->
<div class="con_title">
<h3>게시판</h3>
<p>HOME &gt; 게시판 &gt; <strong>게시판</strong></p>
</div>
<div class="con_txt">
<div class="contents_sub">
<!--게시판-->
<div class="board_view">
<table>
<tr>
<th width="10%">제목</th>
<td width="60%">(<img src="../../images/emoticon/emot<%=emot %>.png" width="15"/>)<%=subject %></td>
<th width="10%">등록일</th>
<td width="20%"><%=wdate %></td>
</tr>
<tr>
<th>글쓴이</th>
<td><%=writer %>(<%=mail %>)(<%=wip %>)</td>
<th>조회</th>
<td><%=hit %></td>
</tr>
<tr>
<td colspan="4" height="200" valign="top" style="padding: 20px; line-height: 160%"><%=content %></td>
</tr>
</table>
</div>


<div class="btn_area">
<div class="align_left">
<input type="button" value="목록" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_list1.jsp?cpage=<%=cpage %>'" />
</div>
<div class="align_right">
<input type="button" value="수정" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_modify1.jsp?seq=<%=seq %>&cpage=<%=cpage %>'" />
<input type="button" value="삭제" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_delete1.jsp?seq=<%=seq %>&cpage=<%=cpage %>'" />
<input type="button" value="쓰기" class="btn_write btn_txt01" style="cursor: pointer;" onclick="location.href='board_write1.jsp?seq=<%=seq %>&cpage=<%=cpage %>'" />
</div>
</div>
<!--//게시판-->
</div>
</div>
<!-- 하단 디자인 -->


</body>
</html>

 

board_write1.jsp - 글 추가 (이모티콘 포함)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>


<%
request.setCharacterEncoding("utf-8");
String cpage=request.getParameter("cpage");


%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="../../css/board.css">


<script type="text/javascript"> //예외처리부분
window.onload = function(){
document.getElementById('wbtn').onclick = function(){
//alert('click'); // 이벤트 동작 확인
if(document.wfrm.info.checked == false){
alert('동의를 하셔야 합니다.');
return;
}
if(document.wfrm.writer.value.trim()==''){
alert('글쓴이를 입력 하셔야 합니다.');
return;
}
if(document.wfrm.password.value.trim()==''){
alert('비밀번호를 입력 하셔야 합니다.');
return;
}
document.wfrm.submit();


};
};
</script>


</head>


<body>
<!-- 상단 디자인 -->
<div class="con_title">
<h3>게시판</h3>
<p>HOME &gt; 게시판 &gt; <strong>게시판</strong></p>
</div>
<div class="con_menu"></div>
<div class="con_txt">
<form action="./board_write1_ok.jsp" method="post" name="wfrm">


<input type="hidden" name = "cpage" value="<%=cpage %>"/>
<div class="contents_sub">
<!--게시판-->
<div class="board_write">
<table>
<tr>
<th class="top">글쓴이</th>
<td class="top"><input type="text" name="writer" value="" class="board_view_input_mail" maxlength="5" /></td>
</tr>
<tr>
<th>제목</th>
<td><input type="text" name="subject" value="" class="board_view_input" /></td>
</tr>
<tr>
<th>비밀번호</th>
<td><input type="password" name="password" value="" class="board_view_input_mail"/></td>
</tr>
<tr>
<th>내용</th>
<td><textarea name="content" class="board_editor_area"></textarea></td>
</tr>
<tr>
<th>이메일</th>
<td><input type="text" name="mail1" value="" class="board_view_input_mail"/> @ <input type="text" name="mail2" value="" class="board_view_input_mail"/></td>
</tr>
<tr>
<th>이모티콘</th>
<td align="center">
<table>
<tr>
<td>
<img src="../../images/emoticon/emot01.png" width="25"/><br />
<input type="radio" name="emot" value="emot01" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot02.png" width="25" /><br />
<input type="radio" name="emot" value="emot02" class="input_radio" checked="checked"/>
</td>
<td>
<img src="../../images/emoticon/emot03.png" width="25" /><br />
<input type="radio" name="emot" value="emot03" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot04.png" width="25" /><br />
<input type="radio" name="emot" value="emot04" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot05.png" width="25" /><br />
<input type="radio" name="emot" value="emot05" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot06.png" width="25" /><br />
<input type="radio" name="emot" value="emot06" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot07.png" width="25" /><br />
<input type="radio" name="emot" value="emot07" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot08.png" width="25" /><br />
<input type="radio" name="emot" value="emot08" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot09.png" width="25" /><br />
<input type="radio" name="emot" value="emot09" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot10.png" width="25" /><br />
<input type="radio" name="emot" value="emot10" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot11.png" width="25"/><br />
<input type="radio" name="emot" value="emot11" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot12.png" width="25" /><br />
<input type="radio" name="emot" value="emot12" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot13.png" width="25" /><br />
<input type="radio" name="emot" value="emot13" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot14.png" width="25" /><br />
<input type="radio" name="emot" value="emot14" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot15.png" width="25" /><br />
<input type="radio" name="emot" value="emot15" class="input_radio" />
</td>
</tr>
<tr>
<td>
<img src="../../images/emoticon/emot16.png" width="25"/><br />
<input type="radio" name="emot" value="emot16" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot17.png" width="25" /><br />
<input type="radio" name="emot" value="emot17" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot18.png" width="25" /><br />
<input type="radio" name="emot" value="emot18" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot19.png" width="25" /><br />
<input type="radio" name="emot" value="emot19" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot20.png" width="25" /><br />
<input type="radio" name="emot" value="emot20" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot21.png" width="25" /><br />
<input type="radio" name="emot" value="emot21" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot22.png" width="25" /><br />
<input type="radio" name="emot" value="emot22" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot23.png" width="25" /><br />
<input type="radio" name="emot" value="emot23" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot24.png" width="25" /><br />
<input type="radio" name="emot" value="emot24" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot25.png" width="25"/><br />
<input type="radio" name="emot" value="emot25" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot26.png" width="25" /><br />
<input type="radio" name="emot" value="emot26" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot27.png" width="25" /><br />
<input type="radio" name="emot" value="emot27" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot28.png" width="25" /><br />
<input type="radio" name="emot" value="emot28" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot29.png" width="25" /><br />
<input type="radio" name="emot" value="emot29" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot30.png" width="25" /><br />
<input type="radio" name="emot" value="emot30" class="input_radio" />
</td>
</tr>
<tr>
<td>
<img src="../../images/emoticon/emot31.png" width="25"/><br />
<input type="radio" name="emot" value="emot31" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot32.png" width="25" /><br />
<input type="radio" name="emot" value="emot32" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot33.png" width="25" /><br />
<input type="radio" name="emot" value="emot33" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot34.png" width="25" /><br />
<input type="radio" name="emot" value="emot34" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot35.png" width="25" /><br />
<input type="radio" name="emot" value="emot35" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot36.png" width="25" /><br />
<input type="radio" name="emot" value="emot36" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot37.png" width="25" /><br />
<input type="radio" name="emot" value="emot37" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot38.png" width="25" /><br />
<input type="radio" name="emot" value="emot38" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot39.png" width="25" /><br />
<input type="radio" name="emot" value="emot39" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot40.png" width="25"/><br />
<input type="radio" name="emot" value="emot40" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot41.png" width="25" /><br />
<input type="radio" name="emot" value="emot41" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot42.png" width="25" /><br />
<input type="radio" name="emot" value="emot42" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot43.png" width="25" /><br />
<input type="radio" name="emot" value="emot43" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot44.png" width="25" /><br />
<input type="radio" name="emot" value="emot44" class="input_radio" />
</td>
<td>
<img src="../../images/emoticon/emot45.png" width="25" /><br />
<input type="radio" name="emot" value="emot45" class="input_radio" />
</td>
</tr>
</table>
</td>
</tr>
</table>


<table>
<tr>
<br />
<td style="text-align:left;border:1px solid #e0e0e0;background-color:f9f9f9;padding:5px">
<div style="padding-top:7px;padding-bottom:5px;font-weight:bold;padding-left:7px;font-family: Gulim,Tahoma,verdana;">※ 개인정보 수집 및 이용에 관한 안내</div>
<div style="padding-left:10px;">
<div style="width:97%;height:95px;font-size:11px;letter-spacing: -0.1em;border:1px solid #c5c5c5;background-color:#fff;padding-left:14px;padding-top:7px;">
1. 수집 개인정보 항목 : 회사명, 담당자명, 메일 주소, 전화번호, 홈페이지 주소, 팩스번호, 주소 <br />
2. 개인정보의 수집 및 이용목적 : 제휴신청에 따른 본인확인 및 원활한 의사소통 경로 확보 <br />
3. 개인정보의 이용기간 : 모든 검토가 완료된 후 3개월간 이용자의 조회를 위하여 보관하며, 이후 해당정보를 지체 없이 파기합니다. <br />
4. 그 밖의 사항은 개인정보취급방침을 준수합니다.
</div>
</div>
<div style="padding-top:7px;padding-left:5px;padding-bottom:7px;font-family: Gulim,Tahoma,verdana;">
<input type="checkbox" name="info" value="1" class="input_radio"> 개인정보 수집 및 이용에 대해 동의합니다.
</div>
</td>
</tr>
</table>
</div>


<div class="btn_area">
<div class="align_left">
<input type="button" value="목록" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_list1.jsp?cpage=<%=cpage %>'" />
</div>
<div class="align_right">
<input type="button" value="쓰기" id="wbtn" class="btn_write btn_txt01" style="cursor: pointer;" />
</div>
</div>
<!--//게시판-->
</div>
</form>
</div>
<!-- 하단 디자인 -->


</body>
</html>
board_write1_ok.jsp - 글 추가 sql 처리 페이지
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>


<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>


<%@ page import="javax.sql.DataSource" %>




<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.PreparedStatement"%>


<%


request.setCharacterEncoding("utf-8"); //내용을 파라미터로 가져온다 (파라미터로 name명을 작성하면 된다.)
String cpage = request.getParameter("cpage");


String subject = request.getParameter("subject");
String writer = request.getParameter("writer");
String mail ="";
if(!request.getParameter("mail1").equals("")&&!request.getParameter("mail1").equals("")){ //메일의 @으로 인해 잘못된 입력이 생길 수 있기 때문에 예외처리를 해준다.
mail=request.getParameter("mail1")+"@"+request.getParameter("mail2");
}
String password = request.getParameter("password");
String content = request.getParameter("content");
String emot = request.getParameter("emot").replaceAll("emot", "");




String wip = request.getRemoteAddr();




Connection conn=null;
PreparedStatement pstmt =null;


// 정상: 0 / 비정상: 1


int flag =1;


try{
Context initCtx = new InitialContext();
Context envCtx =(Context)initCtx.lookup("java:comp/env");
DataSource dataSource = (DataSource)envCtx.lookup("jdbc/mariadb3");
conn = dataSource.getConnection();


String sql ="insert into emot_board1 values (0,?,?,0,?,?,?,?,?,now()) "; //DB에서 넣는 내용과 폼을 통해 입력하는 내용을 구분하여 적어야 한다
pstmt =conn.prepareStatement(sql);
pstmt.setString(1,subject);
pstmt.setString(2,writer);
pstmt.setString(3,password);
pstmt.setString(4,content);
pstmt.setString(5,emot);
pstmt.setString(6,mail);
pstmt.setString(7,wip);


if(pstmt.executeUpdate()==1){ //쿼리 업데이트 내용이 1이면 정상적으로 등록되었다는 flag=0으로 설정한다.
flag=0;
}




} catch(NamingException e){
System.out.println( "[에러] " + e.getMessage() );
} catch(SQLException e){
System.out.println( "[에러] " + e.getMessage() );
} finally{
if(pstmt!=null)pstmt.close();
if(conn!=null)conn.close();
}


out.println("<script type='text/javascript'>");
if(flag ==0){
//정상
out.println("alert('글쓰기 성공');");
out.println("location.href='./board_list1.jsp?cpage="+cpage+"';");
}else if(flag==1){
//에러
out.println("alert('글쓰기 실패');");
out.println("history.back();");
}
out.println("</script>");


%>





<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>


</body>
</html>

 

board_delete1.jsp - 글 삭제
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>


<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>


<%@ page import="javax.sql.DataSource" %>




<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.PreparedStatement"%>
<%@ page import="java.sql.ResultSet"%>






<%
request.setCharacterEncoding("utf-8");
String cpage = request.getParameter("cpage");
String seq= request.getParameter("seq"); //seq파라미터를 가져온다.


String subject ="";
String writer="";


Connection conn=null;
PreparedStatement pstmt =null;
ResultSet rs = null;




try{
Context initCtx = new InitialContext();
Context envCtx =(Context)initCtx.lookup("java:comp/env");
DataSource dataSource = (DataSource)envCtx.lookup("jdbc/mariadb3");
conn = dataSource.getConnection();


String sql = "select subject, writer from emot_board1 where seq=?"; //seq를 파라미터로 넘겨서 해당 seq에 맞는 subject와 writer을 가져와 hmtl에 set한다.
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,seq);


rs=pstmt.executeQuery();


if(rs.next()){
subject= rs.getString("subject");
writer =rs.getString("writer");
}


}catch(NamingException e){
System.out.println( "[에러] " + e.getMessage() );
} catch(SQLException e){
System.out.println( "[에러] " + e.getMessage() );
} finally{
if(rs!=null)pstmt.close();
if(pstmt!=null)pstmt.close();
if(conn!=null)conn.close();
}


%>






<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="../../css/board.css">
<script type ="text/javascript">
window.onload=function(){
document.getElementById('dbtn').onclick=function(){
//alert('click');
if(document.dfrm.password.value.trim()==''){
alert('비밀번호를 입력하셔야 합니다.');
return;
}
document.dfrm.submit();
};
};
</script>
</head>


<body>
<!-- 상단 디자인 -->
<div class="con_title">
<h3>게시판</h3>
<p>HOME &gt; 게시판 &gt; <strong>게시판</strong></p>
</div>
<div class="con_txt">
<form action="./board_delete1_ok.jsp" method="post" name="dfrm">
<input type="hidden" name = "seq" value="<%=seq %>"/> <!-- seq내용 넘겨주기 -->
<input type="hidden" name = "cpage" value="<%=cpage %>"/> <!-- cpage내용 넘겨주기 -->
<div class="contents_sub">
<!--게시판-->
<div class="board_write">
<table>
<tr>
<th class="top">글쓴이</th>
<td class="top"><input type="text" name="writer" value="<%=writer %>" class="board_view_input_mail" maxlength="5" readonly/></td>
</tr>
<tr>
<th>제목</th>
<td><input type="text" name="subject" value="<%=subject %>" class="board_view_input" readonly/></td>
</tr>
<tr>
<th>비밀번호</th>
<td><input type="password" name="password" value="" class="board_view_input_mail"/></td>
</tr>
</table>
</div>


<div class="btn_area">
<div class="align_left">
<input type="button" value="목록" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_list1.jsp?seq=<%=seq %>&cpage=<%=cpage %>'" />
<input type="button" value="보기" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_view1.jsp?seq=<%=seq %>&cpage=<%=cpage %>'" />
</div>
<div class="align_right">
<input type="button" id="dbtn" value="삭제" class="btn_write btn_txt01" style="cursor: pointer;" />
</div>
</div>
<!--//게시판-->
</div>
</form>
</div>
<!-- 하단 디자인 -->


</body>
</html>
board_delete1_ok.jsp - 글 삭제 sql 처리 페이지
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>


<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>


<%@ page import="javax.sql.DataSource" %>




<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.PreparedStatement"%>






<%
request.setCharacterEncoding("utf-8");


String cpage = request.getParameter("cpage");
String seq = request.getParameter("seq");
String password = request.getParameter("password");


//System.out.println(seq);
//System.out.println(password);


Connection conn = null;
PreparedStatement pstmt = null;


//flag가 2면 시스템 오류
//0이면 정상삭제
//1이면 비밀번호 오류
int flag =2;




try{
Context initCtx = new InitialContext();
Context envCtx =(Context)initCtx.lookup("java:comp/env");
DataSource dataSource = (DataSource)envCtx.lookup("jdbc/mariadb3");
conn = dataSource.getConnection();


//비밀번호를 프로그램으로 가져오지 말 것...
//비밀번호 암호화 필수
String sql = "delete from emot_board1 where seq=? and password=?"; //db안에서 비교할 수 있도록 함
// 결과는 0아니면 1로 나뉘어 진다.
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,seq);
pstmt.setString(2,password);


int result = pstmt.executeUpdate();
if(result==0){
//비밀번호 오류
flag=1;
}else if(result==1){
//정상 삭제
flag=0;
}
out.println("<script type='text/javascript'>");
if(flag ==0){
//정상
out.println("alert('글삭제 성공');");
out.println("location.href='./board_list1.jsp?cpage="+cpage+"&seq="+seq+"';");
}else if(flag==1){
//비밀번호 오류
out.println("alert('비밀번호 오류');");
out.println("history.back();");
}else if(flag==2){
//오류
out.println("alert('글삭제 실패');");
out.println("history.back();");
}
out.println("</script>");




} catch(NamingException e){
System.out.println( "[에러] " + e.getMessage() );
} catch(SQLException e){
System.out.println( "[에러] " + e.getMessage() );
} finally{
if(pstmt!=null)pstmt.close();
if(conn!=null)conn.close();
}




%>

 

board_modify1.jsp - 글 수정(이모티콘 포함)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>


<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>


<%@ page import="javax.sql.DataSource" %>




<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.PreparedStatement"%>
<%@ page import="java.sql.ResultSet"%>




<%


request.setCharacterEncoding("utf-8");
String seq = request.getParameter("seq");


String cpage=request.getParameter("cpage");


String subject="";
String writer ="";
String content="";
String mail[]=null;
String emot="";




Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs = null;




try{
Context initCtx = new InitialContext();
Context envCtx =(Context)initCtx.lookup("java:comp/env");
DataSource dataSource = (DataSource)envCtx.lookup("jdbc/mariadb3");
conn = dataSource.getConnection();


String sql = "select subject, writer, content, mail, emot from emot_board1 where seq=?"; //seq를 파라미터로 넘겨서 해당 seq에 맞는 subject와 writer을 가져와 hmtl에 set한다.
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,seq);


rs=pstmt.executeQuery();


if(rs.next()){
subject= rs.getString("subject");
writer =rs.getString("writer");
content=rs.getString("content");
if(rs.getString("mail")==null){ //mail의 내용이 있다면
mail=new String[]{"",""}; //mail의 공간을 2개로 나눔 (공백으로 공간 마련하기)
}else{
mail=rs.getString("mail").split("@"); //@을 기준으로 앞뒤를 나누어 문자열을 얻어 배열에 저장
}


emot=rs.getString("emot");


}


}catch(NamingException e){
System.out.println( "[에러] " + e.getMessage() );
} catch(SQLException e){
System.out.println( "[에러] " + e.getMessage() );
} finally{
if(rs!=null)pstmt.close();
if(pstmt!=null)pstmt.close();
if(conn!=null)conn.close();
}






%>


<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="../../css/board.css">
<script type ="text/javascript">
window.onload=function(){
document.getElementById('ubtn').onclick=function(){
//alert('click');
if(document.ufrm.password.value.trim()==''){
alert('비밀번호를 입력하셔야 합니다.');
return;
}
document.ufrm.submit();
};
};
</script>
</head>


<body>
<!-- 상단 디자인 -->
<div class="con_title">
<h3>게시판</h3>
<p>HOME &gt; 게시판 &gt; <strong>게시판</strong></p>
</div>
<div class="con_txt">
<form action="./board_modify1_ok.jsp" method="post" name="ufrm">
<input type="hidden" name = "seq" value="<%=seq %>"/>
<input type="hidden" name = "cpage" value="<%=cpage %>"/>
<div class="contents_sub">
<!--게시판-->
<div class="board_write">
<table>
<tr>
<th class="top">글쓴이</th>
<td class="top"><input type="text" name="writer" value="<%=writer %>" class="board_view_input_mail" maxlength="5" readonly/></td>
</tr>
<tr>
<th>제목</th>
<td><input type="text" name="subject" value="<%=subject %>" class="board_view_input" /></td>
</tr>
<tr>
<th>비밀번호</th>
<td><input type="password" name="password" value="" class="board_view_input_mail"/></td>
</tr>
<tr>
<th>내용</th>
<td><textarea name="content" class="board_editor_area"><%=content %></textarea></td>
</tr>
<tr>
<th>이메일</th>
<td><input type="text" name="mail1" value="<%=mail[0] %>" class="board_view_input_mail"/> @ <input type="text" name="mail2" value="<%=mail[1] %>" class="board_view_input_mail"/></td>
</tr>
<tr>
<th>이모티콘</th>
<td align="center">
<table>
<tr>
<td>
<img src="../../images/emoticon/emot01.png" width="25"/><br />
<input type="radio" name="emot" value="emot01" class="input_radio" <%=emot.equals("01")? "checked": "" %> />
</td>
<td>
<img src="../../images/emoticon/emot02.png" width="25" /><br />
<input type="radio" name="emot" value="emot02" class="input_radio" <%=emot.equals("02")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot03.png" width="25" /><br />
<input type="radio" name="emot" value="emot03" class="input_radio" <%=emot.equals("03")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot04.png" width="25" /><br />
<input type="radio" name="emot" value="emot04" class="input_radio" <%=emot.equals("04")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot05.png" width="25" /><br />
<input type="radio" name="emot" value="emot05" class="input_radio" <%=emot.equals("05")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot06.png" width="25" /><br />
<input type="radio" name="emot" value="emot06" class="input_radio" <%=emot.equals("06")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot07.png" width="25" /><br />
<input type="radio" name="emot" value="emot07" class="input_radio" <%=emot.equals("07")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot08.png" width="25" /><br />
<input type="radio" name="emot" value="emot08" class="input_radio" <%=emot.equals("08")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot09.png" width="25" /><br />
<input type="radio" name="emot" value="emot09" class="input_radio" <%=emot.equals("09")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot10.png" width="25" /><br />
<input type="radio" name="emot" value="emot10" class="input_radio" <%=emot.equals("10")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot11.png" width="25"/><br />
<input type="radio" name="emot" value="emot11" class="input_radio" <%=emot.equals("11")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot12.png" width="25" /><br />
<input type="radio" name="emot" value="emot12" class="input_radio" <%=emot.equals("12")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot13.png" width="25" /><br />
<input type="radio" name="emot" value="emot13" class="input_radio" <%=emot.equals("13")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot14.png" width="25" /><br />
<input type="radio" name="emot" value="emot14" class="input_radio" <%=emot.equals("14")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot15.png" width="25" /><br />
<input type="radio" name="emot" value="emot15" class="input_radio" <%=emot.equals("15")? "checked": "" %>/>
</td>
</tr>
<tr>
<td>
<img src="../../images/emoticon/emot16.png" width="25"/><br />
<input type="radio" name="emot" value="emot16" class="input_radio" <%=emot.equals("16")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot17.png" width="25" /><br />
<input type="radio" name="emot" value="emot17" class="input_radio" <%=emot.equals("17")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot18.png" width="25" /><br />
<input type="radio" name="emot" value="emot18" class="input_radio" <%=emot.equals("18")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot19.png" width="25" /><br />
<input type="radio" name="emot" value="emot19" class="input_radio" <%=emot.equals("19")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot20.png" width="25" /><br />
<input type="radio" name="emot" value="emot20" class="input_radio" <%=emot.equals("20")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot21.png" width="25" /><br />
<input type="radio" name="emot" value="emot21" class="input_radio" <%=emot.equals("21")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot22.png" width="25" /><br />
<input type="radio" name="emot" value="emot22" class="input_radio" <%=emot.equals("22")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot23.png" width="25" /><br />
<input type="radio" name="emot" value="emot23" class="input_radio" <%=emot.equals("23")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot24.png" width="25" /><br />
<input type="radio" name="emot" value="emot24" class="input_radio" <%=emot.equals("24")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot25.png" width="25"/><br />
<input type="radio" name="emot" value="emot25" class="input_radio" <%=emot.equals("25")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot26.png" width="25" /><br />
<input type="radio" name="emot" value="emot26" class="input_radio" <%=emot.equals("26")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot27.png" width="25" /><br />
<input type="radio" name="emot" value="emot27" class="input_radio" <%=emot.equals("27")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot28.png" width="25" /><br />
<input type="radio" name="emot" value="emot28" class="input_radio" <%=emot.equals("28")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot29.png" width="25" /><br />
<input type="radio" name="emot" value="emot29" class="input_radio" <%=emot.equals("29")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot30.png" width="25" /><br />
<input type="radio" name="emot" value="emot30" class="input_radio" <%=emot.equals("30")? "checked": "" %>/>
</td>
</tr>
<tr>
<td>
<img src="../../images/emoticon/emot31.png" width="25"/><br />
<input type="radio" name="emot" value="emot31" class="input_radio" <%=emot.equals("31")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot32.png" width="25" /><br />
<input type="radio" name="emot" value="emot32" class="input_radio" <%=emot.equals("32")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot33.png" width="25" /><br />
<input type="radio" name="emot" value="emot33" class="input_radio" <%=emot.equals("33")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot34.png" width="25" /><br />
<input type="radio" name="emot" value="emot34" class="input_radio" <%=emot.equals("34")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot35.png" width="25" /><br />
<input type="radio" name="emot" value="emot35" class="input_radio" <%=emot.equals("35")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot36.png" width="25" /><br />
<input type="radio" name="emot" value="emot36" class="input_radio" <%=emot.equals("36")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot37.png" width="25" /><br />
<input type="radio" name="emot" value="emot37" class="input_radio" <%=emot.equals("37")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot38.png" width="25" /><br />
<input type="radio" name="emot" value="emot38" class="input_radio" <%=emot.equals("38")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot39.png" width="25" /><br />
<input type="radio" name="emot" value="emot39" class="input_radio" <%=emot.equals("39")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot40.png" width="25"/><br />
<input type="radio" name="emot" value="emot40" class="input_radio" <%=emot.equals("40")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot41.png" width="25" /><br />
<input type="radio" name="emot" value="emot41" class="input_radio" <%=emot.equals("41")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot42.png" width="25" /><br />
<input type="radio" name="emot" value="emot42" class="input_radio" <%=emot.equals("42")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot43.png" width="25" /><br />
<input type="radio" name="emot" value="emot43" class="input_radio" <%=emot.equals("43")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot44.png" width="25" /><br />
<input type="radio" name="emot" value="emot44" class="input_radio" <%=emot.equals("44")? "checked": "" %>/>
</td>
<td>
<img src="../../images/emoticon/emot45.png" width="25" /><br />
<input type="radio" name="emot" value="emot45" class="input_radio" <%=emot.equals("45")? "checked": "" %>/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>


<div class="btn_area">
<div class="align_left">
<input type="button" value="목록" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_list1.jsp?cpage=<%=cpage %>'" />
<input type="button" value="보기" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_view1.jsp?seq=<%=seq %>&cpage=<%=cpage %>'" /> <!-- 보기는 view로 넘어가기 때문에 어떤 seq를 가지고 있는지가 필요하다(primary key) -->
</div>
<div class="align_right">
<input type="button" id="ubtn" value="수정" class="btn_write btn_txt01" style="cursor: pointer;" />
</div>
</div>
<!--//게시판-->
</div>
</form>
</div>
<!-- 하단 디자인 -->


</body>
</html>
board_modify1_ok.jsp - 글 수정 sql 처리 페이지
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>


<%@ page import="javax.sql.DataSource" %>


<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.SQLException" %>


<%
request.setCharacterEncoding( "utf-8" );




String cpage=request.getParameter("cpage");
String seq = request.getParameter( "seq" );


String password = request.getParameter( "password" );


String subject = request.getParameter( "subject" );
String mail = "";
if(!request.getParameter( "mail1" ).equals( "" ) && !request.getParameter( "mail2" ).equals( "" )) {
mail = request.getParameter( "mail1" ) + "@" + request.getParameter( "mail2" );
}


String content = request.getParameter( "content" );
String emot[] = request.getParameterValues("emot");


Connection conn = null;
PreparedStatement pstmt = null;


int flag = 2;
try {
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup( "java:comp/env" );
DataSource dataSource = (DataSource)envCtx.lookup( "jdbc/mariadb3" );


conn = dataSource.getConnection();


String sql = "update emot_board1 set subject=?, mail=?, content=?, emot=? where seq=? and password=?";
pstmt = conn.prepareStatement( sql );
pstmt.setString( 1, subject );
pstmt.setString( 2, mail );
pstmt.setString( 3, content );
pstmt.setString( 4, emot[0].replaceAll("emot", ""));


pstmt.setString( 5, seq );
pstmt.setString( 6, password );


int result = pstmt.executeUpdate() ; //비밀번호 오류 확인
if( result == 0 ) {
flag = 1;
} else if( result == 1 ) {
flag = 0;
}
} catch( NamingException e ) {
System.out.println( "[에러] : " + e.getMessage() );
} catch( SQLException e ) {
System.out.println( "[에러] : " + e.getMessage() );
} finally {
if( pstmt != null ) pstmt.close();
if( conn != null ) conn.close();
}


out.println( "<script type='text/javascript'>" );
if(flag == 0) {
out.println( "alert('글수정 성공');" );
out.println( "location.href='board_view1.jsp?cpage="+cpage+"&seq="+seq+"';" );
} else if(flag == 1) {
out.println( "alert('비밀번호 오류');" );
out.println( "history.back();" );
} else {
out.println( "alert('글수정 에러');" );
out.println( "history.back();" );
}
out.println( "</script>" );
%>

 


error 확인

 

1.  board기능에서 board_??_ok로 넘어갈 때 action에 해당 jsp 이름을 제대로 작성했는가? .jsp까지 작성해야함

<form action="./board_write1_ok.jsp" method="post" name="wfrm">

2. sql을 적용하려는 버튼이 잘 연결 되었는지(id로), sql문이 잘 작성 되었는지

 


 

board_insert1_ok.jsp - 데이터 강제적으로 집어넣기(100개) 목록확인을 위한...
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>


<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>


<%@ page import="javax.sql.DataSource" %>




<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.PreparedStatement"%>




<%


//100개의 데이터를 강제입력
request.setCharacterEncoding("utf-8");


Connection conn=null;
PreparedStatement pstmt =null;




try{
Context initCtx = new InitialContext();
Context envCtx =(Context)initCtx.lookup("java:comp/env");
DataSource dataSource = (DataSource)envCtx.lookup("jdbc/mariadb3");
conn = dataSource.getConnection();


String sql ="insert into emot_board1 values (0,?,?,0,?,?,?,?,?,now()) ";
pstmt =conn.prepareStatement(sql);


for(int i=1;i<=100;i++){ //가상데이터를 100개 입력
pstmt.setString(1,"제목"+i);
pstmt.setString(2,"이름");
pstmt.setString(3,"1234");
pstmt.setString(4,"내용"+i);
pstmt.setString(5,"01");
pstmt.setString(6,"test@test.com");
pstmt.setString(7,"000.000.000.000");


pstmt.executeUpdate();


}


} catch(NamingException e){
System.out.println( "[에러] " + e.getMessage() );
} catch(SQLException e){
System.out.println( "[에러] " + e.getMessage() );
} finally{
if(pstmt!=null)pstmt.close();
if(conn!=null)conn.close();
}


out.println("<script type='text/javascript'>");
out.println("alert('글쓰기 성공');");
out.println("location.href='./board_list1.jsp';");
out.println("</script>");
%>


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>


</body>
</html>

 


파라미터 넘기는 종류 확인하기

  • <input type="hidden" name = "seq" value="<%=seq %>"/>

=> html 부분에서 버튼을 통해 특정 파라미터를 넘기고 싶으면  해당 문장을 통해 value값을 넘기면 된다.

=> html상에서는 hidden으로 보이지 않지만, 값은 넘길 수 있다.

 

  • <input type="button" value="보기" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='board_view1.jsp?seq=<%=seq %>&cpage=<%=cpage %>'" />

=> html부분에서 넘기는 파라미터 값이 2개 이상이면 &을 사용해 넘길 수 있도록 한다.

=> 보통 특정한 처리 없이 버튼을 눌러 다른 페이지로 이동할 때 input을 통해 파라미터를 넘기는 방식이다.

 

  • out.println( "location.href='board_view1.jsp?cpage="+cpage+"&seq="+seq+"';" );

=> JAVA 부분에서 넘기는 파라미터 값이 2개 이상이면 html과 동일하게 &을 사용해 넘길 수 있도록 한다.

=> 문자열과 변수의 구분을 잘 해야하기 때문에 단일 따옴표나 쌍따옴표 사용을 유의하도록 하자

 


 

  • 이모티콘 수정 하는 부분 중에서....

String emot[] = request.getParameterValues("emot");  //배열로 할 시에 나중에 checkbox에도 사용 가능할 듯 싶다.

//지금은 radio버튼이기 때문에 하나의 값만 나오기 때문에 배열을 사용하지 않고 그냥 작성해도 무관하다

 

대신에 sql문에 setString하는 부분에서 

pstmt.setString( 4, emot[0].replaceAll("emot", ""));

이모티콘 값 중 숫자 부분만 가져오면 되기 때문에 emot는 공백으로 문자열을 변경하도록 한다.

728x90
반응형