Riucc's Storage
RSS
태그
관리
쓰기
카테고리
  • IT (593)
    • 정리 (0)
    • C# (42)
    • ASP.NET MVC (16)
    • JQuery&Javascript (12)
    • CSS (11)
    • 데이터베이스 (32)
    • Windows Server (6)
    • Active Directory (3)
    • Exchange (9)
    • JAVA (2)
    • JSP (39)
    • JSP 게시판 만들기 (21)
    • JSP 개발 참고 (15)
    • JSP 안드로이드 (4)
    • Servlet (17)
    • Spring (42)
    • HTML (14)
    • NodeJS (46)
    • MongoDB (11)
    • 리눅스 (18)
    • 자료구조 (16)
    • 아이폰 (24)
    • 안드로이드 (68)
    • API 활용하기 (10)
    • 소켓네트워크 (28)
    • 라즈베리파이 (11)
    • AWS클라우드 (10)
    • 빅데이터Hadoop (22)
    • 커널모듈프로그래밍 (8)
    • 기타 (10)
    • 자격증 (26)
Riucc's Storage

[JSP 게시판 만들기] - 특정 게시물 수정하기

JSP 게시판 만들기|2018. 3. 11. 21:15
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

○ 특정 게시물 수정하기

 

// ContentDBProcess.java (아래 메소드 추가)


// 게시글 수정하기

public int contentUpdate(int contentNum, String contentTitle, String contentDetail) {

// 제목과 내용을 바꾸겠다!

String SQL = "UPDATE content SET contentTitle = ?, contentDetail = ? WHERE contentNum = ?";

try {

PreparedStatement pstmt = conn.prepareStatement(SQL);

pstmt.setString(1, contentTitle);

pstmt.setString(2, contentDetail);

pstmt.setInt(3, contentNum);

return pstmt.executeUpdate();

} catch(Exception e) {

e.printStackTrace();

}

return -1; // 데이터베이스 오류

}


// contentUpdate.jsp (새로 작성)


<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%@ page import = "java.io.PrintWriter" %>

<%@ page import = "content.Content" %>

<%@ page import = "content.ContentDBProcess" %>

<!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=UTF-8">

<!-- 부트스트랩 사용하기 위해 -->

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<title>게시글 수정하기 페이지</title>

</head>

<body>

<%

String userEmail = null;

if(session.getAttribute("userEmail") != null){

userEmail = (String) session.getAttribute("userEmail");

}

if (userEmail == null){

PrintWriter script = response.getWriter();

script.println("<script>alert('로그인을 하고 접근하세요')</script>"); 

script.println("<script>location.href = 'login.jsp'</script>"); 

}

int contentNum = 0;

if(request.getParameter("contentNum") != null){

contentNum = Integer.parseInt(request.getParameter("contentNum"));

}

if(contentNum == 0){

PrintWriter script = response.getWriter();

script.println("<script>alert('유효하지 않는 게시물입니다')</script>"); 

script.println("<script>location.href = 'content.jsp'</script>"); 

}

Content content = new ContentDBProcess().getContent(contentNum);

%>


<form method="post" action="contentUpdateProcess.jsp?contentNum=<%=contentNum%>">

<div class="container">

  <h2>게시판 글 수정하기</h2>          

  <table class="table table-hover">

    <tbody>

      <tr>

        <!-- 자신의 글을 수정하려면 이전의 값을 보여줘야하기 때매 value에 이전 값을 출력해준다 -->

      <td><input type="text" class="form-control" placeholder="글 제목" name="contentTitle" maxlength="40" value="<%= content.getContentTitle() %>"></td>

      </tr>

      <tr>

      <td><textarea type="text" class="form-control" placeholder="글 내용을 작성하세요" name="contentDetail" maxlength="1024" style="height: 400px;"><%= content.getContentDetail() %></textarea></td>

      </tr>

    </tbody>

  </table>

  <input type="submit" class="btn btn-primary pull-right" value="글수정">

</div>

</form>

</body>

</html>


// contentUpdateProcess.jsp (새로 작성)


<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%@ page import = "content.Content" %>

<!-- 만들어 놓은 클래스를 사용하기 위한 -->

<%@ page import="content.ContentDBProcess" %>

<!-- 스크립트문 편하게 사용하기 위한 -->

<%@ page import="java.io.PrintWriter" %>

<!-- 건너오는 데이터를 UTF-8 형태로 받아오기 위한 -->

<% request.setCharacterEncoding("UTF-8"); %>


<!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=UTF-8">

<title>게시물 처리 페이지</title>

</head>

<body>

<%

// 세션을 통해 글쓴 이메일 찾아옴

String userEmail = null;

if (session.getAttribute("userEmail") != null){

userEmail = (String) session.getAttribute("userEmail");

}

if(userEmail == null){

PrintWriter script = response.getWriter();

script.println("<script>alert('로그인을 하세요')</script>"); 

script.println("<script>location.href = 'login.jsp'</script>"); 

}

int contentNum = 0;

if(request.getParameter("contentNum") != null){

contentNum = Integer.parseInt(request.getParameter("contentNum"));

}

if(contentNum == 0){

PrintWriter script = response.getWriter();

script.println("<script>alert('유효하지 않는 게시물입니다')</script>"); 

script.println("<script>location.href = 'content.jsp'</script>"); 

}

// 글 제목이 널이나 빈값이 있으면 처리해주는 구문

Content content = new ContentDBProcess().getContent(contentNum);

if(request.getParameter("contentTitle") == null || request.getParameter("contentDetail") == null

|| request.getParameter("contentTitle").equals("") || request.getParameter("contentDetail").equals("")) {

PrintWriter script = response.getWriter();

script.println("<script>alert('입력이 안 된 부분이 있습니다')</script>"); 

script.println("<script>history.back()</script>"); 

} else {

ContentDBProcess contentProc = new ContentDBProcess();

int result = contentProc.contentUpdate(contentNum, request.getParameter("contentTitle"), request.getParameter("contentDetail"));

if( result == -1 ){ // 글쓰기 실패시

PrintWriter script = response.getWriter();

script.println("<script>alert('글 수정에 실패하였습니다')</script>"); 

script.println("<script>history.back()</script>"); 

} else { // 글쓰기 성공시

PrintWriter script = response.getWriter();

script.println("<script>location.href = 'content.jsp'</script>");

}

}

%>

</body>

</html>





저작자표시 (새창열림)

'JSP 게시판 만들기' 카테고리의 다른 글

[JSP 게시판 만들기] - 디자인 및 배포  (0) 2018.03.11
[JSP 게시판 만들기] - 특정 게시물 삭제하기  (0) 2018.03.11
[JSP 게시판 만들기] - 특정 게시물을 클릭하여 자세히 보기  (0) 2018.03.11
[JSP 게시판 만들기] - 게시판에 게시물DB 출력하기  (0) 2018.03.11
[JSP 게시판 만들기] - 글쓰기 기능 + DB 구현하기  (0) 2018.03.11

댓글()
카테고리
  • IT (593)
    • 정리 (0)
    • C# (42)
    • ASP.NET MVC (16)
    • JQuery&Javascript (12)
    • CSS (11)
    • 데이터베이스 (32)
    • Windows Server (6)
    • Active Directory (3)
    • Exchange (9)
    • JAVA (2)
    • JSP (39)
    • JSP 게시판 만들기 (21)
    • JSP 개발 참고 (15)
    • JSP 안드로이드 (4)
    • Servlet (17)
    • Spring (42)
    • HTML (14)
    • NodeJS (46)
    • MongoDB (11)
    • 리눅스 (18)
    • 자료구조 (16)
    • 아이폰 (24)
    • 안드로이드 (68)
    • API 활용하기 (10)
    • 소켓네트워크 (28)
    • 라즈베리파이 (11)
    • AWS클라우드 (10)
    • 빅데이터Hadoop (22)
    • 커널모듈프로그래밍 (8)
    • 기타 (10)
    • 자격증 (26)
최근 등록 현황
최근 글
최근 월별 글
최근 댓글
최근 글
최근 월별 글
최근 댓글
최근 글
최근 월별 글
최근 댓글
달력
지난달
2025.10
다음달
일월화수목금토
1234
567891011
12131415161718
19202122232425
262728293031
태그 구름
  • 정보처리산업기사 16년
  • 소켓 프로그래밍
  • 정보처리산업기사 15년 필기
  • 이클립스 디비 연동
  • 정보처리산업기사 총정리
  • 안드로이드 카카오 로그인 연동
  • 소켓
  • 리눅스
  • 안드로이드 카카오 로그인
  • 안드로이드 intent
  • nodejs MySQL 연동하기(Connection Pool)
  • 정보처리산업기사 정리
  • 정규화
  • 정보처리산업기사 필기 정리
  • 정보처리산업기사 16년 필기
  • 이클립스 mysql 연동
  • 카카오 로그인
  • 안드로이드
  • jsp
  • 커널 모듈 프로그래밍
  • nodejs express
  • 정보처리산업기사 요약
  • 정규형
  • 자료구조
  • 정보처리기사 실기 정리
  • 데이터베이스
  • 정보처리산업기사 15년
  • 정보처리산업기사 필기
  • 카카오 로그인 연동
  • HTML
카운터
전체 방문자
오늘
어제
Skin by M1REACT. Designed by M1STORY.TISTORY.COM. Valid XHTML 1.0 and CSS 3. Copyright ⓒ Riucc's Storage. All rights reserved.

티스토리툴바