2016년 8월 11일 목요일

08day JSP

1.사진포함 게시판 만들기
폴더 구성


create table album1(
 seq            number                            not null   primary key,
 grp  number      not null,
 grps  number      not null,
 grpl  number      not null, 
 writer          varchar2(12)                      not null,
 password    varchar2(12)                      not null,
 theme       varchar2(100)                     not null,
 subject       varchar2(100)                     not null,
 content      varchar2(2000),
 photo1      varchar2(200),
 photo2  varchar2(200),
 hit            number                            not null,
 wip           varchar2(15)                      not null,
 wdate        date                                not null
 );

create sequence album_seq;

insert into album1 values (board_seq.nextval, board_seq.currval, 0, 0, '이름', '1234','여름여행', '제목', '내용입니다', null, null,
0, '000.000.000.000', sysdate);

2. DTO, DTO_list, DAO
BoardTO
package model1;

// 데이터용 클래스 만듦
public class BoardTO {
 private String seq;
 private String grp;
 private String grps;
 private String grpl;
 private String writer;
 private String password;
 private String theme;
 private String subject;
 private String content;
 private String photo1;
 private String photo2;
 private String hit;
 private String wip;
 private String wdate;
 private int wgap;
 
 public String getSeq() {
  return seq;
 }
 public String getGrp() {
  return grp;
 }
 public String getGrps() {
  return grps;
 }
 public String getGrpl() {
  return grpl;
 }
 public String getWriter() {
  return writer;
 }
 public String getPassword() {
  return password;
 }
 public String getTheme() {
  return theme;
 }
 public String getSubject() {
  return subject;
 }
 public String getContent() {
  return content;
 }
 public String getPhoto1() {
  return photo1;
 }
 public String getPhoto2() {
  return photo2;
 }
 public String getHit() {
  return hit;
 }
 public String getWip() {
  return wip;
 }
 public String getWdate() {
  return wdate;
 }
 public int getWgap() {
  return wgap;
 }
 public void setSeq(String seq) {
  this.seq = seq;
 }
 public void setGrp(String grp) {
  this.grp = grp;
 }
 public void setGrps(String grps) {
  this.grps = grps;
 }
 public void setGrpl(String grpl) {
  this.grpl = grpl;
 }
 public void setWriter(String writer) {
  this.writer = writer;
 }
 public void setPassword(String password) {
  this.password = password;
 }
 public void setTheme(String theme) {
  this.theme = theme;
 }
 public void setSubject(String subject) {
  this.subject = subject;
 }
 public void setContent(String content) {
  this.content = content;
 }
 public void setPhoto1(String photo1) {
  this.photo1 = photo1;
 }
 public void setPhoto2(String photo2) {
  this.photo2 = photo2;
 }
 public void setHit(String hit) {
  this.hit = hit;
 }
 public void setWip(String wip) {
  this.wip = wip;
 }
 public void setWdate(String wdate) {
  this.wdate = wdate;
 }
 public void setWgap(int wgap) {
  this.wgap = wgap;
 }

}


BoardListTO
package model1;
//페이징 데이터용 클래스
import java.util.ArrayList;

public class BoardListTO {
    private int cpage;
    private int recordPerPage;
    private int blockPerPage;
    private int totalPage;
    private int startBlock;
    private int endBlock;
    private ArrayList<BoardTO> boardList;
    
    //생성자 초기설정 
    public BoardListTO(){
        this.cpage= 1;
        this.recordPerPage = 10;
        this.blockPerPage = 5;
        this.totalPage = 1;
    }
    
    public int getCpage() {
        return cpage;
    }
    public int getRecordPerPage() {
        return recordPerPage;
    }
    public int getBlockPerPage() {
        return blockPerPage;
    }
    public int getTotalPage() {
        return totalPage;
    }
    public int getStartBlock() {
        return startBlock;
    }
    public int getEndBlock() {
        return endBlock;
    }
    public ArrayList<BoardTO> getBoardList() {
        return boardList;
    }
    public void setCpage(int cpage) {
        this.cpage = cpage;
    }
    public void setRecordPerPage(int recordPerPage) {
        this.recordPerPage = recordPerPage;
    }
    public void setBlockPerPage(int blockPerPage) {
        this.blockPerPage = blockPerPage;
    }
    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }
    public void setStartBlock(int startBlock) {
        this.startBlock = startBlock;
    }
    public void setEndBlock(int endBlock) {
        this.endBlock = endBlock;
    }
    public void setBoardList(ArrayList<BoardTO> boardList) {
        this.boardList = boardList;
    }
    
}


BoardDAO
package model1;

import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

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

public class BoardDAO {
    private DataSource dataSource = null;
    
    public BoardDAO(){
        try {
            Context initCtx = new InitialContext();
            Context envCtx = (Context)initCtx.lookup("java:comp/env");
            this.dataSource = (DataSource)envCtx.lookup("jdbc/oracle");
        } catch (NamingException e) {
            System.out.println("에러 : "+ e.getMessage());
        }
    }
    
    public void boardWrite(){
        
    }
    public int boardWriteOk(BoardTO to){
        Connection conn = null;
        PreparedStatement pstmt = null;
        int flag = 1;
        
        try{
            conn = dataSource.getConnection();

            //DB에 데이터쓰기
            String sql = "insert into album1 values (album_seq.nextval, album_seq.currval, 0, 0, ?, ?, ?, ?, ?, ?, ?, 0, ?, sysdate)";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, to.getWriter());
            pstmt.setString(2, to.getPassword());
            pstmt.setString(3, to.getTheme());
            pstmt.setString(4, to.getSubject());
            pstmt.setString(5, to.getContent());
            pstmt.setString(6, to.getPhoto1());
            pstmt.setString(7, to.getPhoto2());
            pstmt.setString(8, to.getWip());
            
            if(pstmt.executeUpdate() ==1){
                flag =0;
            }
            }catch(SQLException e){
                System.out.println("에러 : " + e.getMessage());
            }finally{
                if(pstmt !=null)try{pstmt.close();}catch(SQLException e){};
                if(conn !=null)try{conn.close();}catch(SQLException e){};
            }
        return flag;
    }
    //
    public BoardListTO boardList(BoardListTO listTO){
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        
        try {
            int cpage = listTO.getCpage();
            int recordPerPage = listTO.getRecordPerPage();
            int blockPerPage = listTO.getBlockPerPage();
            
            conn = this.dataSource.getConnection();
            
            String sql = "select seq, theme, subject, writer, hit, trunc(sysdate-wdate) wgap from album1 order by seq desc";
            pstmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            
            rs = pstmt.executeQuery();
            
            //전체데이터 갯수
            rs.last();
            int totalRecord = rs.getRow();
            rs.beforeFirst();
            //전체 페이지 갯수
            listTO.setTotalPage((totalRecord -1)/recordPerPage+1);
            //페이지를 넘길떄 처음 읽을 데이터의 행
            int skip = (cpage -1)*recordPerPage;
            if(skip !=0) rs.absolute(skip);
            
            //recordPerPage만큼 짤라서 화면에 출력
            ArrayList<BoardTO> boardList = new ArrayList<>();
            for(int i =0;i<recordPerPage && rs.next();i++){
                BoardTO to = new BoardTO();
                to.setSeq(rs.getString("seq"));
                to.setTheme(rs.getString("theme"));
                to.setSubject(rs.getString("subject"));
                to.setWriter(rs.getString("writer"));
                to.setHit(rs.getString("hit"));
                to.setWgap(rs.getInt("wgap"));
                
                boardList.add(to);
            }
            //화면하단의 페이지 블락 시작, 끝
            listTO.setBoardList(boardList);
            listTO.setStartBlock(((cpage-1)/blockPerPage)*blockPerPage+1);
            listTO.setEndBlock(((cpage-1)/blockPerPage)*blockPerPage+blockPerPage);
            if(listTO.getEndBlock() >= listTO.getTotalPage()){
                listTO.setEndBlock(listTO.getTotalPage());
            }
        } catch (SQLException e) {
            System.out.println("에러 : "+ e.getMessage());
        } finally{
            if(rs!=null)try {rs.close();} catch (SQLException e) {}
            if(pstmt!=null)try {pstmt.close();} catch (SQLException e) {}
            if(conn!=null)try {conn.close();} catch (SQLException e) {}
        }
        
        return listTO;
    }
    //
    public BoardTO boardView(BoardTO to){
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        
        try{
            conn = this.dataSource.getConnection();
            
            //조회수 증가
            String sql = "update album1 set hit=hit+1 where seq=?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, to.getSeq());
            pstmt.executeUpdate();
            
            //view창 데이터 출력
            sql = "select theme, subject, writer, wip, to_char(wdate,'YY.MM.DD') wdate, hit, content, photo1, photo2 from album1 where seq=?";
            pstmt=conn.prepareStatement(sql);
            pstmt.setString(1, to.getSeq());
            
            rs = pstmt.executeQuery();
            if(rs.next()){
                to.setTheme(rs.getString("theme"));
                to.setSubject(rs.getString("subject"));
                to.setWriter(rs.getString("writer"));
                to.setWip(rs.getString("wip"));
                to.setWdate(rs.getString("wdate"));
                to.setHit(rs.getString("hit"));
                to.setContent(rs.getString("content")==null?"":rs.getString("content").replaceAll("\n", "<br>")); //엔터키 처리
                to.setPhoto1(rs.getString("photo1")==null?"noimage.png":rs.getString("photo1"));
                to.setPhoto2(rs.getString("photo2")==null?"noimage.png":rs.getString("photo2"));
            }
        }catch(SQLException e){
            System.out.println("에러 : " + e.getMessage());
        }finally{
            if(rs!=null)try {rs.close();} catch (SQLException e) {}
            if(pstmt!=null)try {pstmt.close();} catch (SQLException e) {}
            if(conn!=null)try {conn.close();} catch (SQLException e) {}
        }
        return to;
    }
    //
    public ArrayList<BoardTO> boardViewNav(BoardTO to){
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        
        ArrayList<BoardTO> boardList = new ArrayList<>();
        try{
            conn = this.dataSource.getConnection();
             //앞창
            String sql = "select seq, subject from (select seq,subject from album1 where seq<? and subject!='삭제됨' order by seq desc) where rownum<2";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, to.getSeq());
            rs = pstmt.executeQuery();
            if(rs.next()){
                BoardTO toNav = new BoardTO();
                toNav.setSeq(rs.getString("seq"));
                toNav.setSubject(rs.getString("subject"));
                boardList.add(toNav);
            }
            //뒤창
            sql = "select seq, subject from (select seq,subject from album1 where seq>? and subject!='삭제됨' order by seq) where rownum<2";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, to.getSeq());
            rs = pstmt.executeQuery();
            if(rs.next()){
                BoardTO toNav = new BoardTO();
                toNav.setSeq(rs.getString("seq"));
                toNav.setSubject(rs.getString("subject"));
                boardList.add(toNav);
            }
        }catch(SQLException e){
            System.out.println("에러 : " + e.getMessage());
        }finally{
            if(rs!=null)try {rs.close();} catch (SQLException e) {}
            if(pstmt!=null)try {pstmt.close();} catch (SQLException e) {}
            if(conn!=null)try {conn.close();} catch (SQLException e) {}
        }
        return boardList;
    }
    //
    public BoardTO boardModify(BoardTO to){
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        
        try{
            conn = this.dataSource.getConnection();
            
            //modify창 데이터 출력
            String sql = "select theme, subject, writer, content, photo1, photo2 from album1 where seq=?";
            pstmt=conn.prepareStatement(sql);
            pstmt.setString(1, to.getSeq());
            
            rs = pstmt.executeQuery();
            if(rs.next()){
                to.setTheme(rs.getString("theme"));
                to.setSubject(rs.getString("subject"));
                to.setWriter(rs.getString("writer"));
                to.setContent(rs.getString("content")==null?"":rs.getString("content"));
                to.setPhoto1(rs.getString("photo1")==null?"noimage.png":rs.getString("photo1"));
                to.setPhoto2(rs.getString("photo2")==null?"noimage.png":rs.getString("photo2"));
            }
        }catch(SQLException e){
            System.out.println("에러 : " + e.getMessage());
        }finally{
            if(rs!=null)try {rs.close();} catch (SQLException e) {}
            if(pstmt!=null)try {pstmt.close();} catch (SQLException e) {}
            if(conn!=null)try {conn.close();} catch (SQLException e) {}
        }
        return to;
    }
    //
    public int boardModifyOk(BoardTO to){
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        
        int flag = 2;
        
        try{
            conn = this.dataSource.getConnection();
            
            //사진업로드를 안했으면 원래 DB 사진 이름 가져옴 //업로드 했으면 원래 파일 지움
            String sql = "select photo1, photo2 from album1 where seq=?";
            pstmt=conn.prepareStatement(sql);
            pstmt.setString(1, to.getSeq());
            rs = pstmt.executeQuery();
            String prePhoto1 = "";
            String prePhoto2 = "";
            if(rs.next()){
                if(to.getPhoto1().equals("")){
                    to.setPhoto1(rs.getString("photo1")==null?"":rs.getString("photo1"));
                }else if(!to.getPhoto1().equals(rs.getString("photo1"))){
                    prePhoto1 = rs.getString("photo1")==null?"":rs.getString("photo1");
                }
                if(to.getPhoto2().equals("")){
                    to.setPhoto2(rs.getString("photo2")==null?"":rs.getString("photo2"));
                }else if(!to.getPhoto2().equals(rs.getString("photo2"))){
                    prePhoto2 = rs.getString("photo2")==null?"":rs.getString("photo2");
                }
            }
            
            //DB데이터 수정
            sql = "update album1 set subject=?, theme=?, content=?, photo1=?, photo2=? where seq=? and password=?";

            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, to.getSubject());
            pstmt.setString(2, to.getTheme());
            pstmt.setString(3, to.getContent());
            pstmt.setString(4, to.getPhoto1());
            pstmt.setString(5, to.getPhoto2());
            pstmt.setString(6, to.getSeq());
            pstmt.setString(7, to.getPassword());
            
            int result = pstmt.executeUpdate();
            if(result ==0){
                flag =1;
            }else if(result ==1){
                flag =0;
                //파일 삭제
                if(!prePhoto1.equals("")){
                    File f = new File("C:\\Users\\user\\Documents\\AlbumEx01\\WebContent\\gallery", prePhoto1);
                    f.delete();
                }
                if(!prePhoto2.equals("")){
                    File f = new File("C:\\Users\\user\\Documents\\AlbumEx01\\WebContent\\gallery", prePhoto2);
                    f.delete();
                }
            }
        }catch(SQLException e){
            System.out.println("에러 : " + e.getMessage());
        }finally{
            if(pstmt !=null)try{pstmt.close();}catch(SQLException e){};
            if(conn !=null)try{conn.close();}catch(SQLException e){};
        }
        return flag;
    }
    public BoardTO boardDelete(BoardTO to){
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        
        try{
            conn = this.dataSource.getConnection();
            
            //delete창 데이터 출력
            String sql = "select subject, writer from album1 where seq=?";
            pstmt=conn.prepareStatement(sql);
            pstmt.setString(1, to.getSeq());
            
            rs = pstmt.executeQuery();
            if(rs.next()){
                to.setSubject(rs.getString("subject"));
                to.setWriter(rs.getString("writer"));
            }
        }catch(SQLException e){
            System.out.println("에러 : " + e.getMessage());
        }finally{
            if(rs!=null)try {rs.close();} catch (SQLException e) {}
            if(pstmt!=null)try {pstmt.close();} catch (SQLException e) {}
            if(conn!=null)try {conn.close();} catch (SQLException e) {}
        }
        return to;
    }
    public int boardDeleteOk(BoardTO to){
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        int flag = 2;
        
        try{
            conn = this.dataSource.getConnection();
            //삭제할 사진명
            String sql = "select photo1, photo2 from album1 where seq=?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, to.getSeq());
            
            rs = pstmt.executeQuery();
            String photo1 = "";
            String photo2 = "";
            if(rs.next()) {
                photo1 = rs.getString("photo1")==null?"":rs.getString("photo1");
                photo2 = rs.getString("photo2")==null?"":rs.getString("photo2");
            }
            
            //delete 처리
            sql = "update album1 set subject='삭제됨', photo1='', photo2='', content='' where seq=? and password=?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, to.getSeq());
            pstmt.setString(2, to.getPassword());
            
            int result = pstmt.executeUpdate();
            if(result ==0){
                flag =1;
            }else if(result ==1){
                flag =0;
                //파일 삭제
                if(!photo1.equals("")){
                    File f = new File("C:\\Users\\user\\Documents\\AlbumEx01\\WebContent\\gallery", photo1);
                    f.delete();
                }
                if(!photo2.equals("")){
                    File f = new File("C:\\Users\\user\\Documents\\AlbumEx01\\WebContent\\gallery", photo2);
                    f.delete();
                }
            }
        }catch(SQLException e){
            System.out.println("에러 : " + e.getMessage());
        }finally{
            if(pstmt!=null)try {pstmt.close();} catch (SQLException e) {}
            if(conn!=null)try {conn.close();} catch (SQLException e) {}
        }
        return flag;
    }
}


3.board_write1
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<link href='../css/board.css' rel='stylesheet' type='text/css'>
<script type="text/javascript">
    function ChkForm() {
        //필수 입력값 검사
        if(document.wfrm.subject.value.trim() ==""){
            alert('제목을 입력하셔야 합니다.');
            return false;
        }
        if(document.wfrm.writer.value.trim() ==""){
            alert('이름을 입력하셔야 합니다.');
            return false;
        }
        if(document.wfrm.password.value.trim() ==""){
            alert('암호를 입력하셔야 합니다.');
            return false;
        }
    }
</script>
<form action='board_write1_ok.jsp' method='post' name='wfrm' enctype="multipart/form-data" onSubmit='return ChkForm(this)'>
<table width='808' border='0' cellspacing='0' cellpadding='0'>
<tr>
    <td height='34' colspan='7'></td>
</tr>
<tr bgcolor='#99ccff'>
    <td height='5' colspan='7'></td>
</tr>
<tr>
    <td width='117' height='36' align='left' valign='middle' style='padding-left:40px;'><img src='../images/bar_name03.gif' width='33' height='9'></td>
    <td width='3' align='center' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='2' height='14'></td>
    <td width='172' align='left' valign='middle' class='textlist' style='padding-left:5px;'>
        <input type='text' name='writer' size='20' maxlength='10' class='box_03'>
    </td>
    <td width='3' align='left' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='1' height='14'></td>
    <td width='92' align='center' valign='middle' class='text'><img src='../images/text_password.gif' width='63' height='10'></td>
    <td width='3' align='left' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='2' height='14'></td>
    <td width='215' align='left' valign='middle' class='style2' style='padding-left:5px;'>
        <input type='password' name='password' size='20' maxlength='10' class='box_04'>
    </td>
</tr>
<tr>
    <td height='1' colspan='7' align='left' bgcolor='#d9d9e6'></td>
</tr>
<tr>
    <td width='139' height='36' align='left' valign='middle' style='padding-left:40px;'><img src='../images/bar_photo.gif' width='37' height='9'></td>
    <td width='3' align='center' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='2' height='14'></td>
    <td colspan='5' align='left' valign='middle' class='textlist' style='padding-left:5px;'>
        <input type='file' name='photo1' size='50' maxlength='45' class='box_05'>
    </td>
</tr>
<tr>
    <td height='1' colspan='7' align='left' bgcolor='#d9d9e6'></td>
</tr>
<tr>
    <td width='139' height='36' align='left' valign='middle' style='padding-left:40px;'><img src='../images/bar_photo.gif' width='37' height='9'></td>
    <td width='3' align='center' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='2' height='14'></td>
    <td colspan='5' align='left' valign='middle' class='textlist' style='padding-left:5px;'>
        <input type='file' name='photo2' size='50' maxlength='45' class='box_05'>
    </td>
</tr>
<tr>
    <td height='1' colspan='7' align='left' bgcolor='#d9d9e6'></td>
</tr>
<tr>
    <td width='139' height='36' align='left' valign='middle' style='padding-left:40px;'><img src='../images/bar_theme02.gif' width='39' height='9'></td>
    <td width='3' align='center' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='2' height='14'></td>
    <td colspan='5' align='left' valign='middle' style='padding-left:5px;'>
        <select name='theme'>
            <option value='봄여행'>봄여행</option>
            <option value='여름여행'>여름여행</option>
            <option value='가을여행'>가을여행</option>
            <option value='겨울여행'>겨울여행</option>
        </select>
    </td>
</tr>
<tr>
    <td height='1' colspan='7' align='left' bgcolor='#d9d9e6'></td>
</tr>
<tr>
    <td width='139' height='36' align='left' valign='middle' style='padding-left:40px;'><img src='../images/bar_title02.gif' width='31' height='9'></td>
    <td width='3' align='center' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='2' height='14'></td>
    <td colspan='5' align='left' valign='middle' class='textlist' style='padding-left:5px;'>
        <input type='text' name='subject' size='50' maxlength='100' class='box_05'>
    </td>
</tr>
<tr>
    <td height='1' colspan='7' align='left' bgcolor='#d9d9e6'></td>
</tr>
<tr>
    <td width='139' height='218' align='left' valign='middle' style='padding-left:40px;'><img src='../images/bar_contents.gif' width='60' height='9'></td>
    <td width='3' align='center' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='2' height='14'></td>
    <td colspan='5' align='left' valign='middle' class='textlist' style='padding-left:5px;'>
        <textarea name='content' cols='48' rows='13' class='textarea_1'></textarea>
    </td>
</tr>
<tr bgcolor='#99ccff'> 
    <td height='3' colspan='7'></td>
</tr>
</table>

<table width='808' border='0' cellspacing='0' cellpadding='0'>
<tr>
    <td width='80' height='50'>
        <a href='board_list1.jsp'><img src='../images/button_list.gif' width='70' height='23' border='0'></a>
    </td>
    <td align='right' class='text'>
        <input type='image' src='../images/button_ok.gif' width='70' height='23' border='0'>
    </td>
</tr>
<tr>
    <td height='21' colspan='2'></td>
</tr>
</table>


4.board_write1_ok
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.oreilly.servlet.MultipartRequest" %>
<%@ page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy" %>
<%@page import="model1.BoardTO"%>
<%@page import="model1.BoardDAO"%>

<%
    //업로드
    String uploadPath = "C:\\Users\\user\\Documents\\AlbumEx01\\WebContent\\gallery";
    int maxFileSize = 1024 * 1024 * 20;
    String encoding = "utf-8";
    MultipartRequest multi = new MultipartRequest(request, uploadPath, maxFileSize, encoding, new DefaultFileRenamePolicy());    

    request.setCharacterEncoding("utf-8");
    //데이터 클래스를 생성, 클라이언트 정보 넣음
    BoardTO to = new BoardTO();
    to.setWriter(multi.getParameter("writer"));
    to.setPassword(multi.getParameter("password"));
    to.setTheme(multi.getParameter("theme"));
    to.setSubject(multi.getParameter("subject"));
    to.setContent(multi.getParameter("content"));
    to.setPhoto1(multi.getFilesystemName("photo1") == null ? "" : multi.getFilesystemName("photo1"));
    to.setPhoto2(multi.getFilesystemName("photo2") == null ? "" : multi.getFilesystemName("photo2"));
    to.setWip(request.getRemoteAddr());
    
    
    //DAO클래스에서 write_ok에서 필요한 DB데이터를 처리해서 리턴
    BoardDAO dao = new BoardDAO();
    int flag = dao.boardWriteOk(to);
    
      //성공실패 메시지   
    out.println("<script type='text/javascript'>");
    if(flag ==0){
        out.println("alert('글쓰기에 성공했습니다')");
        out.println("location.href='board_list1.jsp';");
    }else{
        out.println("alert('글쓰기에 실패했습니다')");
        out.println("history.back()");
    }
    out.println("</script>");
    
%>


5.board_list1
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="model1.BoardTO" %>    
<%@ page import="model1.BoardListTO" %>    
<%@ page import="model1.BoardDAO" %>   
<%@page import="java.util.ArrayList"%>
<%
    request.setCharacterEncoding("utf-8");
    
    //페이지 번호
    int cpage = 1;
    if(request.getParameter("cpage") != null && !request.getParameter("cpage").equals("")) {
        cpage = Integer.parseInt(request.getParameter("cpage"));
    }
    //페이지네비게이션 초기값 지정
    BoardListTO listTO = new BoardListTO();
    listTO.setCpage(cpage);
    
    //DAO list에서 현재페이지에 맞는 페이지네비게이션 값 리턴
    BoardDAO dao = new BoardDAO();
    listTO = dao.boardList(listTO);
    
    int totalPage =listTO.getTotalPage();
    int blockPerPage = listTO.getBlockPerPage();
    int startBlock = listTO.getStartBlock();
    int endBlock = listTO.getEndBlock();
    ArrayList<BoardTO> boardList = listTO.getBoardList(); 
        
    StringBuffer result = new StringBuffer();
    
    //레코드 데이터 리턴
    for(BoardTO to : boardList) {
        String seq = to.getSeq();
        String theme = to.getTheme();
        String subject = to.getSubject();
        String writer = to.getWriter();
        String hit = to.getHit();
        int wgap = to.getWgap();
        
        result.append("<tr valign='middle'>");
        result.append("    <td width='44' height='55' align='center' class='text'>"+seq+"</td>");
        result.append("    <td align='center' class='text'>"+theme+"</td>");
        result.append("    <td width='14'></td>");
        result.append("    <td align='center'>");
        if(!subject.equals("삭제됨")){
            result.append("        <a href='board_view1.jsp?cpage=" + cpage + "&seq=" + seq + "' class='text'>"+subject+"</a>");    
        }else{
            result.append("<span class='text'>삭제됨</span>");
        }
        if(wgap == 0) {
            result.append("        <img src='../images/icon_new.gif' width='25' height='9' border='0' align='absmiddle'>");
        }
        result.append("    </td>");
        result.append("    <td width='17'></td>");
        result.append("    <td width='98' align='center' class='text'>"+writer+"</td>");
        result.append("    <td width='53' align='center' class='text'>"+hit+"</td>");
        result.append("</tr>");
        result.append("<tr valign='middle' bgcolor='#d9d9e6'>");
        result.append("    <td height='1' colspan='8' align='center' class='text'></td>");
        result.append("</tr>");
    }     
%>


<link href='../css/board.css' rel='stylesheet' type='text/css'>

<table width='808' border='0' cellspacing='0' cellpadding='0'>
<tr>
    <td height='34'></td>
</tr>
<tr>
    <td align='center' valign='top' style='padding-top:10px;'>
        <table width='808' border='0' cellspacing='0' cellpadding='0'>
        <tr valign='bottom'>
            <td width='44' height='29' align='center' valign='bottom' background='../images/bar_bg01.gif'><img src='../images/bar_no.gif' width='17' height='17'></td>
            <td width='100' align='center' valign='bottom' background='../images/bar_bg01.gif'><img src='../images/bar_theme.gif' width='41' height='17'></td>
            <td><img src='../images/bar_bg02.gif' width='15' height='29'></td>
            <td width='482' align='center' valign='bottom' background='../images/bar_bg06.gif'><img src='../images/bar_title.gif' width='30' height='19'></td>
            <td width='15' valign='bottom' background='../images/bar_bg01.gif'><img src='../images/bar_bg04.gif' width='15' height='29'></td>
            <td width='99' align='center' valign='bottom' background='../images/bar_bg01.gif'><img src='../images/bar_name.gif' width='33' height='18'></td>
            <td width='53' align='center' valign='bottom' background='../images/bar_bg01.gif'><img src='../images/bar_hit.gif' width='18' height='18'></td>
        </tr>

<!-- 반복시작 -->
<%=result %>
<!-- 반복끝 -->
        
        </table>
    </td>
</tr>
</table>

<table width='808' border='0' cellspacing='0' cellpadding='0'>
<tr>
    <td height='21' colspan='3'></td>
</tr>
<tr>
    <td width='80' height='23'><a href='board_list1.jsp'><img src='../images/button_list.gif' width='70' height='23' border='0'></a></td>
    <td width='656' align='center' class='text'>
    <!-- 페이지 네비게이션 -->
<%
    if(startBlock == 1) {
        out.println("<img src='../images/button_page_prew2.gif' width='11' height='9' border='0' align='absmiddle'>");
    } else {
        out.println("<a href='board_list1.jsp?cpage=" + (startBlock - blockPerPage) + "'><img src='../images/button_page_prew2.gif' width='11' height='9' border='0' align='absmiddle'></a>");
    }
    
    // 이전 페이지 가기
    if(cpage == 1) {
        out.println("<img src='../images/button_page_prew1.gif' width='9' height='9' border='0' align='absmiddle'>");    
    } else {
        out.println("<a href='board_list1.jsp?cpage=" + (cpage - 1) + "'><img src='../images/button_page_prew1.gif' width='9' height='9' border='0' align='absmiddle'></a>");    
    }

     // 현재 페이지 표시
     for(int i=startBlock ; i<=endBlock ; i++) {
          if (cpage == i) {
               out.println("<strong>[" + i + "]</strong>&nbsp;");
          } else {
               out.println("<a href='board_list1.jsp?cpage=" + i + "'>" + i + "</a>&nbsp;");
          }
     }
     
     if(cpage == totalPage) {
          out.println("<img src='../images/button_page_next1.gif' width='9' height='9' border='0' align='absmiddle'>");
     } else {
          out.println("<a href='board_list1.jsp?cpage=" + (cpage + 1) + "'><img src='../images/button_page_next1.gif' width='9' height='9' border='0' align='absmiddle'></a>");
     }

     if(endBlock == totalPage) {
         out.println("<img src='../images/button_page_next2.gif' width='11' height='9' border='0' align='absmiddle'>");
     } else {
        out.println("<a href='board_list1.jsp?cpage=" + (startBlock + blockPerPage) + "'><img src='../images/button_page_next2.gif' width='11' height='9' border='0' align='absmiddle'></a>");
     }
%>
    </td>
    <td width='80' align='right'><a href='board_write1.jsp'><img src='../images/button_write.gif' width='70' height='23' border='0'></a></td>
</tr>
<tr>
    <td height='21' colspan='3'></td>
</tr>
</table>


6.board_view1
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="model1.BoardTO"%>
<%@page import="model1.BoardDAO"%>
<%
    request.setCharacterEncoding("utf-8");
    
    //선택글 번호 받아서 TO에 넣음
    BoardTO to = new BoardTO();
    to.setSeq(request.getParameter("seq"));
    
    //DAO View에서 필요한 DB데이터를 처리해서 리턴
    BoardDAO dao = new BoardDAO();
    to = dao.boardView(to);
    
    String seq = to.getSeq();
    String theme = to.getTheme();
    String subject =to.getSubject();
    String writer = to.getWriter();
    String wip = to.getWip();
    String wdate = to.getWdate();
    String hit = to.getHit();
    String content = to.getContent();
    String photo1 = to.getPhoto1();
    String photo2 = to.getPhoto2();
    
    //앞뒤글
    ArrayList<BoardTO> toNav = new ArrayList<BoardTO>();
    toNav = dao.boardViewNav(to);
    String prev = "이전글이 존재하지 않습니다";
    String prevseq = "";
    String next = "다음글이 존재하지 않습니다";
    String nextseq = "";
    if(toNav.size()!=0){
        for(BoardTO ton : toNav){
               if(Integer.parseInt(ton.getSeq())<Integer.parseInt(to.getSeq())){
                   prev = ton.getSubject();
                   prevseq = ton.getSeq();
               }else{
                   next = ton.getSubject();
                   nextseq = ton.getSeq();
               }
        }
    } 
%>


<link href='../css/board.css' rel='stylesheet' type='text/css'>

<table width='808' border='0' cellspacing='0' cellpadding='0'>
<tr>
    <td height='34'></td>
</tr>
<tr>
    <td align='center' valign='top'>
        <table width='808' border='0' cellspacing='0' cellpadding='0'>
        <tr valign='bottom'>
            <td width='440' height='29' align='center' valign='bottom' background='../images/bar_bg01.gif'><img src='../images/bar_theme.gif' width='41' height='17'></td>
            <td width='15' background='../images/bar_bg02.gif'></td>
            <td width='84' align='center' valign='bottom' background='../images/bar_bg06.gif'><img src='../images/bar_name02.gif' width='31' height='19'></td>
            <td width='15' valign='bottom' background='../images/bar_bg04.gif'></td>
            <td width='109' align='center' valign='bottom' background='../images/bar_bg01.gif'><img src='../images/bar_date.gif' width='27' height='17'></td>
            <td width='50' align='center' valign='bottom' background='../images/bar_bg01.gif'><img src='../images/bar_hit.gif' width='18' height='18'></td>
            <td width='95' align='center' valign='bottom' background='../images/bar_bg01.gif'></td>
        </tr>
        <tr valign='middle'>
            <td height='36' align='center' class='text'><%=theme %></td>
            <td width='15'></td>
            <td align='center' class='text'><%=writer %></td>
            <td width='15'></td>
            <td align='center' class='text'><%=wdate %></td>
            <td width='50' align='center' class='text'><%=hit %></td>
            <td align='center' class='text'><%=wip %></td>
        </tr>
        <tr valign='middle' bgcolor='#d9d9e6'>
            <td height='1' colspan='7' align='center' class='text'></td>
        </tr>
        <tr valign='middle' bgcolor='#f9fcff'>
            <td height='29' colspan='7' align='center' class='style1'><%=subject %></td>
        </tr>
        <tr valign='middle' bgcolor='#d9d9e6'>
            <td height='1' colspan='7' align='center' class='text'> </td>
        </tr>
        <tr valign='top'>
            <td height='281' colspan='7' align='center'>
                <table width='800' border='0' cellspacing='0' cellpadding='0'>
                <tr>
                    <td align='center'>
                        <table width='300' height='250' border='0' cellspacing='0' cellpadding='3'>
                        <tr>
                            <!-- 사진 2개있으면 두장 한개 있으면 한장 -->
                            <% 
                            if(!photo1.equals("noimage.png")&&!photo2.equals("noimage.png")){
                                out.println("<td bordercolor='#cccccc'><img src='../gallery/"+photo1+"' width='300' height='225' border='0'></td>");
                                out.println("<td bordercolor='#cccccc'><img src='../gallery/"+photo2+"' width='300' height='225' border='0'></td>");
                            }else if(!photo1.equals("noimage.png") || !photo1.equals("noimage.png")) {
                                if(!photo1.equals("noimage.png")){
                                    out.println("<td bordercolor='#cccccc'><img src='../gallery/"+photo1+"' width='300' height='225' border='0'></td>");
                                }else{
                                    out.println("<td bordercolor='#cccccc'><img src='../gallery/"+photo2+"' width='300' height='225' border='0'></td>");
                                }
                            }else{
                                out.println("<td bordercolor='#cccccc'><img src='../gallery/noimage.png' width='300' height='225' border='0'></td>");
                            }
                            %>
                        </tr>
                        </table>
                    </td>
                </tr>
                <tr valign='middle'>
                    <td height='1' colspan='7' align='center' class='text' background='../images/line.gif'></td>
                </tr>
                <tr>
                    <td width='800' valign='top' class='text' style='padding-left:10px; padding-top:10px;'>
                        <%=content %>
                    </td>
                </tr>
                </table>
            </td>
        </tr>

<!--  -->
<!--  -->
        <tr valign='middle'>
            <td height='28' colspan='7' align='center' class='text'></td>
        </tr>
        <tr valign='middle'>
            <td height='64' colspan='7' align='center'>
                <table width='808'  border='0' cellspacing='0' cellpadding='0'>
                <tr bgcolor='#6699ff'>
                    <td height='3' colspan='2'></td>
                </tr>
                <tr>
                    <td width='85' height='29' align='center'><img src='../images/text_prev.gif' width='27' height='9'></td>
                    <td width='723' align='left' class='text'>
                        <% if(prevseq.equals("")){
                                out.println(prev);
                            }else{
                                out.println("<a href='board_view1.jsp?seq="+prevseq+"' class='text'>"+prev+"</a>");
                            }; 
                        %>
                    </td>
                </tr>
                <tr bgcolor='#d9d9e6'>
                    <td height='1' colspan='2'></td>
                </tr>
                <tr>
                    <td height='29' align='center'><img src='../images/text_next.gif' width='27' height='9'></td>
                    <td align='left' class='text'>
                        <% if(nextseq.equals("")){
                                out.println(next);
                            }else{
                                out.println("<a href='board_view1.jsp?seq="+nextseq+"' class='text'>"+next+"</a>");
                            }; 
                        %>
                    </td>
                </tr>
                <tr>
                    <td height='2' colspan='2' bgcolor='#6699ff'></td>
                </tr>
                </table>
            </td>
        </tr>
        </table>
    </td>
</tr>
</table>

<table width='808' border='0' cellspacing='0' cellpadding='0'>
<tr>
    <td width='80' height='50'>
        <a href='board_list1.jsp'><img src='../images/button_list.gif' width='70' height='23' border='0'></a>
    </td>
    <td align='right' class='text'>
        <a href='board_modify1.jsp?seq=<%=seq%>'><img src='../images/button_modify.gif' width='70' height='23' border='0'></a>
        <a href='board_delete1.jsp?seq=<%=seq%>'><img src='../images/button_delete.gif' width='71' height='23' border='0'></a>
        <a href='board_write1.jsp'><img src='../images/button_write.gif' width='70' height='23' border='0'></a>
    </td>
</tr>
<tr>
    <td height='21' colspan='2'></td>
</tr>
</table>


7.board_modify1
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="model1.BoardTO"%>
<%@page import="model1.BoardDAO"%>

<%
    request.setCharacterEncoding("utf-8");
    
    //선택글 번호 받아서 TO에 넣음
    BoardTO to = new BoardTO();
    to.setSeq(request.getParameter("seq"));
    
     
    //DAO modify에서 필요한 DB데이터를 처리해서 리턴
    BoardDAO dao = new BoardDAO();
    to = dao.boardModify(to);

    String seq = to.getSeq();
    String writer = to.getWriter();
    String theme = to.getTheme();
    String subject =to.getSubject();
    String content = to.getContent();
    String photo1 = to.getPhoto1();
    String photo2 = to.getPhoto2();
    
%>
<link href='../css/board.css' rel='stylesheet' type='text/css'>
<script type="text/javascript">
    function ChkForm() {
        //필수 입력값 검사
        if(document.wfrm.subject.value.trim() ==""){
            alert('제목을 입력하셔야 합니다.');
            return false;
        }
        if(document.wfrm.password.value.trim() ==""){
            alert('암호를 입력하셔야 합니다.');
            return false;
        }
    }
</script>
<form action='board_modify1_ok.jsp' method='post' name='wfrm' enctype="multipart/form-data" onSubmit='return ChkForm(this)'>
<input type='hidden' name='seq' value='<%=seq%>'>  <%-- seq를 히든으로 보냄 --%>
<table width='808' border='0' cellspacing='0' cellpadding='0'>
<tr>
    <td height='34' colspan='7'></td>
</tr>
<tr bgcolor='#99ccff'>
    <td height='5' colspan='7'></td>
</tr>
<tr>
    <td width='117' height='36' align='left' valign='middle' style='padding-left:40px;'><img src='../images/bar_name03.gif' width='33' height='9'></td>
    <td width='3' align='center' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='2' height='14'></td>
    <td width='172' align='left' valign='middle' class='textlist' style='padding-left:5px;'>
        <input type='text' name='writer' size='20' maxlength='10' class='box_03' value='<%=writer %>' readonly>
    </td>
    <td width='3' align='left' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='1' height='14'></td>
    <td width='92' align='center' valign='middle' class='text'><img src='../images/text_password.gif' width='63' height='10'></td>
    <td width='3' align='left' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='2' height='14'></td>
    <td width='215' align='left' valign='middle' class='style2' style='padding-left:5px;'>
        <input type='password' name='password' size='20' maxlength='10' class='box_04'>
    </td>
</tr>
<tr>
    <td height='1' colspan='7' align='left' bgcolor='#d9d9e6'></td>
</tr>
<tr>
    <td width='139' height='36' align='left' valign='middle' style='padding-left:40px;'><img src='../images/bar_photo.gif' width='37' height='9'></td>
    <td width='3' align='center' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='2' height='14'></td>
    <td colspan='5' align='left' valign='middle' class='textlist' style='padding-left:5px;'>
        <div>:   <%=photo1 %></div>
        <div><input type='file' name='photo1' size='50' maxlength='45' class='box_05'></div>
    </td>
</tr>
<tr>
    <td height='1' colspan='7' align='left' bgcolor='#d9d9e6'></td>
</tr>
<tr>
    <td width='139' height='36' align='left' valign='middle' style='padding-left:40px;'><img src='../images/bar_photo.gif' width='37' height='9'></td>
    <td width='3' align='center' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='2' height='14'></td>
    <td colspan='5' align='left' valign='middle' class='textlist' style='padding-left:5px;'>
        <div>:   <%=photo2 %></div>
        <div><input type='file' name='photo2' size='50' maxlength='45' class='box_05'></div>
    </td>
</tr>
<tr>
    <td height='1' colspan='7' align='left' bgcolor='#d9d9e6'></td>
</tr>
<tr>
    <td width='139' height='36' align='left' valign='middle' style='padding-left:40px;'><img src='../images/bar_theme02.gif' width='39' height='9'></td>
    <td width='3' align='center' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='2' height='14'></td>
    <td colspan='5' align='left' valign='middle' style='padding-left:5px;'>
        <select name='theme'>
            <option value='봄여행' <%= theme.equals("봄여행")?"selected='selected'":"" %>>봄여행</option>
            <option value='여름여행' <%= theme.equals("여름여행")?"selected='selected'":"" %>>여름여행</option>
            <option value='가을여행' <%= theme.equals("가을여행")?"selected='selected'":"" %>>가을여행</option>
            <option value='겨울여행' <%= theme.equals("겨울여행")?"selected='selected'":"" %>>겨울여행</option>
        </select>
    </td>
</tr>
<tr>
    <td height='1' colspan='7' align='left' bgcolor='#d9d9e6'></td>
</tr>
<tr>
    <td width='139' height='36' align='left' valign='middle' style='padding-left:40px;'><img src='../images/bar_title02.gif' width='31' height='9'></td>
    <td width='3' align='center' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='2' height='14'></td>
    <td colspan='5' align='left' valign='middle' class='textlist' style='padding-left:5px;'>
        <input type='text' name='subject' size='50' maxlength='100' class='box_05' value='<%=subject %>'>
    </td>
</tr>
<tr>
    <td height='1' colspan='7' align='left' bgcolor='#d9d9e6'></td>
</tr>
<tr>
    <td width='139' height='218' align='left' valign='middle' style='padding-left:40px;'><img src='../images/bar_contents.gif' width='60' height='9'></td>
    <td width='3' align='center' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='2' height='14'></td>
    <td colspan='5' align='left' valign='middle' class='textlist' style='padding-left:5px;'>
        <textarea name='content' cols='48' rows='13' class='textarea_1'><%=content %></textarea>
    </td>
</tr>
<tr bgcolor='#99ccff'> 
    <td height='3' colspan='7'></td>
</tr>
</table>

<table width='808' border='0' cellspacing='0' cellpadding='0'>
<tr>
    <td width='80' height='50'>
        <a href='board_list1.jsp'><img src='../images/button_list.gif' width='70' height='23' border='0'></a>
    </td>
    <td align='right' class='text'>
        <input type='image' src='../images/button_ok.gif' width='70' height='23' border='0'>
    </td>
</tr>
<tr>
    <td height='21' colspan='2'></td>
</tr>
</table>


8.board_modify1_ok
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.oreilly.servlet.MultipartRequest" %>
<%@ page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy" %>
<%@page import="model1.BoardTO"%>
<%@page import="model1.BoardDAO"%>

<%
    //업로드
    String uploadPath = "C:\\Users\\user\\Documents\\AlbumEx01\\WebContent\\gallery";
    int maxFileSize = 1024 * 1024 * 20;
    String encoding = "utf-8";
    MultipartRequest multi = new MultipartRequest(request, uploadPath, maxFileSize, encoding, new DefaultFileRenamePolicy());
    
    request.setCharacterEncoding("utf-8");
    //데이터 클래스를 생성, 클라이언트 정보 넣음
    BoardTO to = new BoardTO();
    to.setSeq(multi.getParameter("seq"));
    to.setSubject(multi.getParameter("subject"));
    to.setPassword(multi.getParameter("password"));
    to.setPhoto1(multi.getFilesystemName("photo1") == null ? "" : multi.getFilesystemName("photo1"));
    to.setPhoto2(multi.getFilesystemName("photo2") == null ? "" : multi.getFilesystemName("photo2"));
    to.setTheme(multi.getParameter("theme"));
    to.setContent(multi.getParameter("content"));

    //DAO클래스에서 modify_ok에서 필요한 DB데이터를 처리해서 리턴
    BoardDAO dao = new BoardDAO();
    int flag = dao.boardModifyOk(to);
    
     //성공실패 메시지
    out.println("<script type='text/javascript'>");
    if(flag ==0){
        out.println("alert('글수정에 성공했습니다')");
        out.println("location.href='board_list1.jsp';");
    }else if(flag==1){
        out.println("alert('비밀번호가 잘못되었습니다.')");
        out.println("history.back();");
    }else{
        out.println("alert('글수정에 실패했습니다')");
        out.println("history.back();");
    }
    out.println("</script>");
    
%>


9.board_delete1
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="model1.BoardTO"%>
<%@page import="model1.BoardDAO"%>
<%
    request.setCharacterEncoding("utf-8");

    //선택글 번호 받아서 TO에 넣음
    BoardTO to = new BoardTO();
    to.setSeq(request.getParameter("seq"));
    
    //DAO delete에서 필요한 DB데이터를 처리해서 리턴
    BoardDAO dao = new BoardDAO();
    to = dao.boardDelete(to);
    
    String seq = to.getSeq();
    String subject =to.getSubject();
    String writer = to.getWriter();
%>
<link href='../css/board.css' rel='stylesheet' type='text/css'>
<script type="text/javascript">
    function ChkForm(form) {
        //필수 입력값 검사
        if(document.wfrm.password.value.trim() ==""){
            alert('암호를 입력하셔야 합니다.');
            return false;
        }
    }
</script>
<form action='board_delete1_ok.jsp' method='post' name='wfrm' onSubmit='return ChkForm(this)'>
<input type='hidden' name='seq' value='<%=seq%>'>  <%-- seq를 히든으로 보냄 --%>
<table width='808' border='0' cellspacing='0' cellpadding='0'>
<tr>
    <td height='34' colspan='7'></td>
</tr>
<tr bgcolor='#99ccff'>
    <td height='5' colspan='7'></td>
</tr>
<tr>
    <td width='117' height='36' align='left' valign='middle' style='padding-left:40px;'><img src='../images/bar_name03.gif' width='33' height='9'></td>
    <td width='3' align='center' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='2' height='14'></td>
    <td width='172' align='left' valign='middle' class='textlist' style='padding-left:5px;'>
        <input type='text' name='writer' size='20' maxlength='10' class='box_03' value='<%=writer%>' readonly>
    </td>
    <td width='3' align='left' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='1' height='14'></td>
    <td width='92' align='center' valign='middle' class='text'><img src='../images/text_password.gif' width='63' height='10'></td>
    <td width='3' align='left' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='2' height='14'></td>
    <td width='215' align='left' valign='middle' class='style2' style='padding-left:5px;'>
        <input type='password' name='password' size='20' maxlength='10' class='box_04'>
    </td>
</tr>
<tr>
    <td height='1' colspan='7' align='left' bgcolor='#d9d9e6'></td>
</tr>
<tr>
    <td width='139' height='36' align='left' valign='middle' style='padding-left:40px;'><img src='../images/bar_title02.gif' width='31' height='9'></td>
    <td width='3' align='center' valign='top' bgcolor='#fbfbf4' class='textlist'><img src='../../06/view_html/../images/bar-line.gif' width='2' height='14'></td>
    <td colspan='5' align='left' valign='middle' class='textlist' style='padding-left:5px;'>
        <input type='text' name='subject' size='50' maxlength='100' class='box_05' value='<%=subject%>' readonly>
    </td>
</tr>
<tr bgcolor='#99ccff'> 
    <td height='3' colspan='7'></td>
</tr>
</table>

<table width='808' border='0' cellspacing='0' cellpadding='0'>
<tr>
    <td width='80' height='50'>
        <a href='board_list1.jsp'><img src='../images/button_list.gif' width='70' height='23' border='0'></a>
    </td>
    <td align='right' class='text'>
        <input type='image' src='../images/button_ok.gif' width='70' height='23' border='0'>
    </td>
</tr>
<tr>
    <td height='21' colspan='2'></td>
</tr>
</table>


10.board_delete1_ok
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="model1.BoardTO"%>
<%@page import="model1.BoardDAO"%>

<%
    request.setCharacterEncoding("utf-8");
    //데이터 클래스를 생성, 클라이언트 정보 넣기
    BoardTO to = new BoardTO();
    to.setSeq(request.getParameter("seq"));
    to.setPassword(request.getParameter("password"));
    
    //DAO클래스에서 delete_ok에서 필요한 DB데이터를 처리해서 리턴
    BoardDAO dao = new BoardDAO();
    int flag = dao.boardDeleteOk(to);
    
    //성공실패 메시지
    out.println("<script type='text/javascript'>");
    if(flag ==0){
        out.println("alert('글삭제에 성공했습니다')");
        out.println("location.href='board_list1.jsp';");
    }else if(flag==1){
        out.println("alert('비밀번호가 잘못되었습니다.')");
        out.println("history.back();");
    }else{
        out.println("alert('글삭제에 실패했습니다')");
        out.println("history.back();");
    }
    out.println("</script>");
    
%>


댓글 없음:

댓글 쓰기