오늘이라도

[Web] 26. 회원 관리 & 게시판 만들기 ① : 웹 프로젝트 생성 및 페이지 작성 전 환경 준비 본문

취업성공패키지 SW 개발자 교육/Web

[Web] 26. 회원 관리 & 게시판 만들기 ① : 웹 프로젝트 생성 및 페이지 작성 전 환경 준비

upcake_ 2020. 6. 15. 14:11
반응형

https://github.com/upcake/Class_Examples

교육 중에 작성한 예제들은 깃허브에 올려두고 있습니다. 

gif 파일은 클릭해서 보는 것이 정확합니다.


 - 회원 관리 & 게시판 만들기 ① : 웹 프로젝트 생성 및 페이지 작성 전 환경 준비 -

▲작업지시서

 

 

○ 클래스 폴더 설정

 

 

○ Package 생성 : member(회원 관리), board(게시판 관리)

▲패키지 목록

회원
관리
com.member.action 회원 관리의 Action Class
com.member.study 회원 관리의 DTO, DAO, SQL(JDBC)
com.member.mybatis (myBatis 사용할 경우 생성) 회원 관리의 DB FrameWork
게시판관리 com.board.action 게시판의 Action Class
com.board.study 게시판의 DTO, DAO, SQL(JDBC)
com.board.mybatis (myBatis 사용할 경우 생성) 게시판의 DB Framework
공용 com.commons.action Action Interface, ActionForward Class

 

 

○ View 폴더 생성

 - board : 게시판의 JSP

 - boardupload : 게시판에서 첨부한 파일이 저장되는 폴더

 - member : 회원 관리의 JSP

 

 

○ DataBase Table 생성

--테이블 생성
CREATE TABLE boardMember(
    Member_id VARCHAR2(15) PRIMARY KEY NOT NULL,
    Member_pw VARCHAR2(15),
    Member_name VARCHAR2(15),
    Member_age NUMBER,
    Member_gender VARCHAR2(5),
    Member_email VARCHAR2(30)
);

--테이블 조회
SELECT * FROM boardMember;

▲Member.sql

 - boardMember Table : 회원 관리

 

--테이블 생성
CREATE TABLE memberBoard(
    Board_num NUMBER PRIMARY KEY NOT NULL,
    Board_id VARCHAR2(15),
    Board_subject VARCHAR2(50),
    Board_content VARCHAR2(2000),
    Board_file VARCHAR2(20),
    Board_re_ref NUMBER,
    Board_re_lev NUMBER,
    Board_re_seq NUMBER,
    Board_readcount NUMBER,
    Board_date DATE
);

--제약조건 추가
ALTER TABLE memberBoard
ADD CONSTRAINT pk_board_id FOREIGN KEY(Board_id)
REFERENCES boardMember(Member_id);

--테이블 조회
SELECT * FROM memberBoard;

▲Board.sql

 - memberBoard Table : 게시판

 

 

○ FrontController Servlet 생성

package com.member.action;
import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.commons.action.Action;
import com.commons.action.ActionForward;

@WebServlet("/MemberFrontController.me")
public class MemberFrontController extends HttpServlet {
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String uri = request.getRequestURI();
		String context = request.getContextPath();
		String command = uri.substring(context.length());
		//System.out.println(command);	//콘솔 창에 /memberLogin.me 등이 출력된다.
		
		Action action = null;
		ActionForward forward = null;
		
		if(command.equals("/memberLogin.me")) {
			forward = new ActionForward();
			forward.setPath("member/loginForm.jsp");
			forward.setRedirect(false);
		} else if(command.equals("/memberLoginAction.me")) {
			
		} else if(command.equals("/memberJoin.me")) {
			forward = new ActionForward();
			forward.setPath("member/joinForm.jsp");
			forward.setRedirect(false);
		} else if(command.equals("/memberJoinAction.me")) {
			
		}
		
		if(forward != null) {
			if(forward.isRedirect()) {	//true : sendRedirect() 전환
				response.sendRedirect(forward.getPath());
			} else {					//false : forward() 전환
				RequestDispatcher rd = request.getRequestDispatcher(forward.getPath());
				rd.forward(request, response);
			}
		}
	}
}

▲MemberFrontController.java

 - URL Mapping : /MemberFrontController.me

 

package com.board.action;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/BoardFrontController.bo")
public class BoardFrontController extends HttpServlet {
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}
}

▲BoardFrontController.java

 - URL Mapping : /BoardFrontController.bo

 

 

○ Servlet Mapping : web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>09.Member_Board</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
  	<display-name>MemberFrontController</display-name>
  	<servlet-name>MemberFrontController</servlet-name>
  	<servlet-class>com.member.action.MemberFrontController</servlet-class>
  </servlet>
  <servlet-mapping>
  	<servlet-name>MemberFrontController</servlet-name>
  	<url-pattern>*.me</url-pattern>
  </servlet-mapping>
  <servlet>
  	<display-name>BoardFrontController</display-name>
  	<servlet-name>BoardFrontController</servlet-name>
  	<servlet-class>com.board.action.BoardFrontController</servlet-class>
  </servlet>
  <servlet-mapping>
  	<servlet-name>BoardFrontController</servlet-name>
  	<url-pattern>*.bo</url-pattern>
  </servlet-mapping>
</web-app>

▲web.xml

 - MemberFrontController url-pattern : *.me

 - BoardFrontController url-pattern : *.bo

 

 

○ DTO Class, DAO Class

  - com.member.study : MemberDTO.java, MemberDAO.java

package com.member.study;

import java.io.Serializable;

public class MemberDTO implements Serializable {
	private String member_id, member_pw, member_name;
	private int member_age;
	private String member_gender, member_email;
	
	public MemberDTO() {}
	
	public MemberDTO(String member_id, String member_pw, String member_name, int member_age, String member_gender,
			String member_email) {
		super();
		this.member_id = member_id;
		this.member_pw = member_pw;
		this.member_name = member_name;
		this.member_age = member_age;
		this.member_gender = member_gender;
		this.member_email = member_email;
	}

	public String getMember_id() {
		return member_id;
	}

	public void setMember_id(String member_id) {
		this.member_id = member_id;
	}

	public String getMember_pw() {
		return member_pw;
	}

	public void setMember_pw(String member_pw) {
		this.member_pw = member_pw;
	}

	public String getMember_name() {
		return member_name;
	}

	public void setMember_name(String member_name) {
		this.member_name = member_name;
	}

	public int getMember_age() {
		return member_age;
	}

	public void setMember_age(int member_age) {
		this.member_age = member_age;
	}

	public String getMember_gender() {
		return member_gender;
	}

	public void setMember_gender(String member_gender) {
		this.member_gender = member_gender;
	}

	public String getMember_email() {
		return member_email;
	}

	public void setMember_email(String member_email) {
		this.member_email = member_email;
	}
}

▲MemberDTO.java

 

package com.member.study;

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

public class MemberDAO {
	private Connection conn;
	private PreparedStatement ps;
	private ResultSet rs;
	
	public Connection getConn() {
		String url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
		String user = "hanul";
		String password = "0000";
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			conn = DriverManager.getConnection(url, user, password);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("getConn() Exception!!!");
		}
		return conn;
	} //getConn()
} //class

▲MemberDAO.java

 

  - com.board.study : BoardDTO.java, BoardDAO.java

package com.board.study;

import java.io.Serializable;

public class BoardDTO implements Serializable {
	private int board_num;
	private String board_id, board_subject, board_content, board_file;
	private int board_re_ref, board_re_lev, board_re_seq, board_readcount;
	private String board_date;
	
	public BoardDTO() {}

	public BoardDTO(int board_num, String board_id, String board_subject, String board_content, String board_file,
			int board_re_ref, int board_re_lev, int board_re_seq, int board_readcount, String board_date) {
		super();
		this.board_num = board_num;
		this.board_id = board_id;
		this.board_subject = board_subject;
		this.board_content = board_content;
		this.board_file = board_file;
		this.board_re_ref = board_re_ref;
		this.board_re_lev = board_re_lev;
		this.board_re_seq = board_re_seq;
		this.board_readcount = board_readcount;
		this.board_date = board_date;
	}

	public int getBoard_num() {
		return board_num;
	}

	public void setBoard_num(int board_num) {
		this.board_num = board_num;
	}

	public String getBoard_id() {
		return board_id;
	}

	public void setBoard_id(String board_id) {
		this.board_id = board_id;
	}

	public String getBoard_subject() {
		return board_subject;
	}

	public void setBoard_subject(String board_subject) {
		this.board_subject = board_subject;
	}

	public String getBoard_content() {
		return board_content;
	}

	public void setBoard_content(String board_content) {
		this.board_content = board_content;
	}

	public String getBoard_file() {
		return board_file;
	}

	public void setBoard_file(String board_file) {
		this.board_file = board_file;
	}

	public int getBoard_re_ref() {
		return board_re_ref;
	}

	public void setBoard_re_ref(int board_re_ref) {
		this.board_re_ref = board_re_ref;
	}

	public int getBoard_re_lev() {
		return board_re_lev;
	}

	public void setBoard_re_lev(int board_re_lev) {
		this.board_re_lev = board_re_lev;
	}

	public int getBoard_re_seq() {
		return board_re_seq;
	}

	public void setBoard_re_seq(int board_re_seq) {
		this.board_re_seq = board_re_seq;
	}

	public int getBoard_readcount() {
		return board_readcount;
	}

	public void setBoard_readcount(int board_readcount) {
		this.board_readcount = board_readcount;
	}

	public String getBoard_date() {
		return board_date;
	}

	public void setBoard_date(String board_date) {
		this.board_date = board_date;
	}
	
	
}

▲BoardDTO.java

 

package com.board.study;

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

public class BoardDAO {
	private Connection conn;
	private PreparedStatement ps;
	private ResultSet rs;
	
	public Connection getConn() {
		String url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
		String user = "hanul";
		String password = "0000";
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			conn = DriverManager.getConnection(url, user, password);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("getConn() Exception!!!");
		}
		return conn;
	} //getConn()
} //class

▲BoardDAO.java

 

○ Action Interface, ActionForward Class

package com.commons.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public interface Action {
	public ActionForward execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException;	
}

▲Action.java

 

package com.commons.action;

public class ActionForward {
	private String path;			//View 페이지 경로와 파일명
	private boolean isRedirect;		//전환 방식
	
	public String getPath() {
		return path;
	}
	public void setPath(String path) {
		this.path = path;
	}
	public boolean isRedirect() {
		return isRedirect;
	}
	public void setRedirect(boolean isRedirect) {
		this.isRedirect = isRedirect;
	}
}

▲ActionForward.java

 

○ Library 추가

 

반응형