WEB-INF에서 모델 2 실행해보기
위와 같이 WEB-INF안에 model2를 복사해서 붙이고 board_write1만 브라우저로 열면 당연히 404 에러가 뜬다. servlet으로 가서 BoardController를 아래와 같이 수정하면
package servlet;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
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 model2.Action;
import model2.DeleteAction;
import model2.DeleteOkAction;
import model2.ListAction;
import model2.ModifyAction;
import model2.ModifyOkAction;
import model2.ViewAction;
import model2.WriteAction;
import model2.WriteOkAction;
/**
* Servlet implementation class BoardController
*/
@WebServlet("/controller")
public class BoardController extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doProcess(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doProcess(request, response);
}
protected void doProcess(HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
try {
request.setCharacterEncoding("utf-8");
String action = request.getParameter("action");
String url = "/model2/error.jsp";
Action baction = null;
if(action == null || action.equals("") || action.equals("list")) {
baction = new ListAction();
baction.execute(request, response);
url = "/WEB-INF/model2/board_list1.jsp";
} else if(action.equals("view")) {
baction = new ViewAction();
baction.execute(request, response);
url = "/WEB-INF/model2/board_view1.jsp";
} else if(action.equals("write")) {
baction = new WriteAction();
baction.execute(request, response);
url = "/WEB-INF/model2/board_write1.jsp";
} else if(action.equals("write_ok")) {
baction = new WriteOkAction();
baction.execute(request, response);
url = "/WEB-INF/model2/board_write1_ok.jsp";
} else if(action.equals("modify")) {
baction = new ModifyAction();
baction.execute(request, response);
url = "/WEB-INF/model2/board_modify1.jsp";
} else if(action.equals("modify_ok")) {
baction = new ModifyOkAction();
baction.execute(request, response);
url = "/WEB-INF/model2/board_modify1_ok.jsp";
} else if(action.equals("delete")) {
baction = new DeleteAction();
baction.execute(request, response);
url = "/WEB-INF/model2/board_delete1.jsp";
} else if(action.equals("delete_ok")) {
baction = new DeleteOkAction();
baction.execute(request, response);
url = "/WEB-INF/model2/board_delete1_ok.jsp";
}
RequestDispatcher dispatcher = request.getRequestDispatcher(url);
dispatcher.forward(request, response);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
url = "/WEB-INF/model2/board_delete1_ok.jsp";을 이런식으로 작성하면 웹사이트는 WEB-INF안에 있게 하는 방식으로 사용한다.
이제 TOMCAT을 분리해주는 작업을 해보자!!
index.html
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8" />
<title>Insert title here</title>
</head>
<body>
Hello Tomcat
</body>
</html>
<?xml version="1.0" encoding="utf-8"?>
<Context path="/website3" docBase="c:\jQuery\website3" reloadable="true"></Context>
<?xml version="1.0" encoding="utf-8"?>
<Context path="/website3" docBase="c:\jQuery\website3" reloadable="true">
<Resource
name="jdbc/oracle1"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:orcl"
username="project"
password="project"
maxTotal="20"
maxWaitMillis="5000"/>
</Context>
index.html
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="./controller?action=list">게시판</a>
</body>
</html>
ControllerEx02
ControllerEx02.view1
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<title>Insert title here</title>
</head>
<body>
view1.jsp
</body>
</html>
ControllerEx02.view2
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<title>Insert title here</title>
</head>
<body>
view2.jsp
</body>
</html>
ControleerEx02.servlet.ControllerEx01
package servlet;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class ControllerEx01
*/
@WebServlet("*.do")
public class ControllerEx01 extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doProcess(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doProcess(request, response);
}
protected void doProcess(HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
try {
request.setCharacterEncoding("utf-8");
System.out.println(request.getRequestURI());
System.out.println(request.getContextPath());
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
list.do
ControllerEx02.servlet.ControllerEx01
package servlet;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
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;
/**
* Servlet implementation class ControllerEx01
*/
@WebServlet("*.do")
public class ControllerEx01 extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doProcess(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doProcess(request, response);
}
protected void doProcess(HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
try {
request.setCharacterEncoding("utf-8");
//System.out.println(request.getRequestURI());
//System.out.println(request.getContextPath());
String path = request.getRequestURI().replaceAll(request.getContextPath(), "");
String url = "/error.jsp";
if(path.equals("/*.do") || path.equals("/view1.do")) {
url = "/view1.jsp";
} else if(path.equals("/view2.do")) {
url = "/view2.jsp";
}
RequestDispatcher dispatcher = request.getRequestDispatcher(url);
dispatcher.forward(request, response);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
ControllerEx02.servlet.ControllerEx01
package servlet;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
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;
/**
* Servlet implementation class ControllerEx01
*/
@WebServlet("*.do")
public class ControllerEx01 extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doProcess(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doProcess(request, response);
}
protected void doProcess(HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
try {
request.setCharacterEncoding("utf-8");
//System.out.println(request.getRequestURI());
//System.out.println(request.getContextPath());
String path = request.getRequestURI().replaceAll(request.getContextPath(), "");
String url = "/error.jsp";
if(path.equals("/*.do") || path.equals("/board/view1.do")) {
url = "/view1.jsp";
} else if(path.equals("/board/view2.do")) {
url = "/view2.jsp";
}
RequestDispatcher dispatcher = request.getRequestDispatcher(url);
dispatcher.forward(request, response);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Model2Ex03
Model2Ex03.model1.BoardTO
package model1;
// 데이터
public class BoardTO {
// data - table / select(list + view)
private String seq;
private String subject;
private String writer;
private String mail;
private String[] email;
private String password;
private String content;
private String hit;
private String wip;
private String wdate;
private int wgap;
public String getSeq() {
return seq;
}
public void setSeq(String seq) {
this.seq = seq;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getWriter() {
return writer;
}
public void setWriter(String writer) {
this.writer = writer;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getHit() {
return hit;
}
public void setHit(String hit) {
this.hit = hit;
}
public String getWip() {
return wip;
}
public void setWip(String wip) {
this.wip = wip;
}
public String getWdate() {
return wdate;
}
public void setWdate(String wdate) {
this.wdate = wdate;
}
public int getWgap() {
return wgap;
}
public void setWgap(int wgap) {
this.wgap = wgap;
}
}
Model2Ex03.model1.BoardDAO
package model1;
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 {
// jsp 처리할 일을 메소드화
// jsp 페이지와 1 : 1
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/oracle1");
} 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();
String sql = "insert into board1 values (board_seq.nextval, ?, ?, ?, ?, ?, 0, ?, sysdate)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSubject());
pstmt.setString(2, to.getWriter());
pstmt.setString(3, to.getMail());
pstmt.setString(4, to.getPassword());
pstmt.setString(5, to.getContent());
pstmt.setString(6, to.getWip());
int result = pstmt.executeUpdate();
if(result == 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 ArrayList<BoardTO> boardList() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int totalRecord = 0;
ArrayList<BoardTO> lists = new ArrayList<>();
try {
conn = datasource.getConnection();
String sql = "select seq, subject, writer, to_char(wdate, 'YYYY/MM/DD') wdate, hit, trunc(sysdate-wdate) wgap from board1 order by seq desc";
pstmt = conn.prepareStatement(sql);
pstmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = pstmt.executeQuery();
// 커서를 맨 마지막행으로 이동
rs.last();
// 데이터 개수가 나옴
totalRecord = rs.getRow();
rs.beforeFirst();
while(rs.next()) {
BoardTO to = new BoardTO();
to.setSeq(rs.getString("seq"));
to.setSubject(rs.getString("subject"));
to.setWriter(rs.getString("writer"));
to.setWdate(rs.getString("wdate"));
to.setHit(rs.getString("hit"));
to.setWgap(rs.getInt("wgap"));
lists.add(to);
}
} 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 lists;
}
public BoardTO boardView(BoardTO to) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = datasource.getConnection();
// 조회수
String sql = "update board1 set hit = hit + 1 where seq=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSeq());
pstmt.executeUpdate();
// 조회
sql = "select subject, writer, wdate, hit, content, mail from board1 where seq = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSeq());
rs = pstmt.executeQuery();
if(rs.next()) {
to.setSubject(rs.getString("subjec = null;
try {
conn = datasource.getConnection();
String sql = "select subject, writer from board1 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 { pstmt.close(); } catch(SQLException e) {}
}
return to;
}
public int boardDeleteOk(BoardTO to) {
Connection conn = null;
PreparedStatement pstmt = null;
int flag = 2;
try {
conn = datasource.getConnection();
String sql = "delete from board1 where seq = ? and password = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, to.getSeq());
pstmt.setString(2, to.getPassword());
int result = pstmt.executeUpdate();
if(result == 1) {
// 정상
flag = 0;
} else if (result == 0) {
// 비밀번호 오류
flag = 1;
}
} 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;
}
}
Model2Ex03.model2.Action
package model2;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public interface Action {
public abstract void execute(HttpServletRequest request, HttpServletResponse response);
}
Model2Ex03.model2.ListAction
package model2;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model1.BoardDAO;
import model1.BoardTO;
public class ListAction implements Action {
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
BoardDAO dao = new BoardDAO();
ArrayList<BoardTO> lists = dao.boardList();
request.setAttribute("lists", lists);
}
}
Model2Ex03.model2.WriteAction
package model2;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class WriteAction implements Action {
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
System.out.println("WriteAction 호출");
}
}
Model2Ex03.model2.WriteOkAction
package model2;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model1.BoardDAO;
import model1.BoardTO;
public class WriteOkAction implements Action {
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
//request.setCharacterEncoding("utf-8");
String subject = request.getParameter("subject");
String writer = request.getParameter("writer");
String mail = request.getParameter("mail1") + "@" + request.getParameter("mail2");
String password = request.getParameter("password");
String content = request.getParameter("content");
String wip = request.getRemoteAddr();
BoardTO to = new BoardTO();
to.setSubject(subject);
to.setWriter(writer);
to.setMail(mail);
to.setPassword(password);
to.setContent(content);
to.setWip(wip);
BoardDAO dao = new BoardDAO();
int flag = dao.boardWriteOk(to);
request.setAttribute("flag", flag);
}
}
Model2Ex03.model2.ViewAction
package model2;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model1.BoardDAO;
import model1.BoardTO;
public class ViewAction implements Action {
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
String seq = request.getParameter("seq");
BoardTO to = new BoardTO();
to.setSeq(seq);
BoardDAO dao = new BoardDAO();
to = dao.boardView(to);
request.setAttribute("to", to);
}
}
Model2Ex03.model2.DeleteAction
package model2;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model1.BoardDAO;
import model1.BoardTO;
public class DeleteAction implements Action {
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
BoardTO to = new BoardTO();
to.setSeq(request.getParameter("seq"));
BoardDAO dao = new BoardDAO();
//to = dao.boardView(to);
to = dao.boardDelete(to);
//to = dao.boardDeleteOk(to);
request.setAttribute("to", to);
}
}
Model2Ex03.model2.DeleteOkAction
package model2;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model1.BoardDAO;
import model1.BoardTO;
public class DeleteAction implements Action {
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
BoardTO to = new BoardTO();
to.setSeq(request.getParameter("seq"));
BoardDAO dao = new BoardDAO();
//to = dao.boardView(to);
to = dao.boardDelete(to);
//to = dao.boardDeleteOk(to);
request.setAttribute("to", to);
}
}
Model2Ex03.model2.ModifyAction
package model2;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model1.BoardDAO;
import model1.BoardTO;
public class ModifyAction implements Action {
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
BoardTO to = new BoardTO();
to.setSeq(request.getParameter("seq"));
BoardDAO dao = new BoardDAO();
to = dao.boardView(to);
request.setAttribute("to", to);
}
}
Model2Ex03.model2.ModifyOkAction
package model2;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model1.BoardDAO;
import model1.BoardTO;
public class ModifyOkAction implements Action {
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
String seq = request.getParameter("seq");
String subject = request.getParameter("subject");
String mail = request.getParameter("mail1") + "@" + request.getParameter("mail2");
String password = request.getParameter("password");
String content = request.getParameter("content");
String wip = request.getRemoteAddr();
BoardTO to = new BoardTO();
to.setSubject(subject);
to.setMail(mail);
to.setPassword(password);
to.setContent(content);
to.setSeq(seq);
BoardDAO dao = new BoardDAO();
int flag = dao.boardModifyOk(to);
request.setAttribute("seq", to.getSeq());
request.setAttribute("flag", flag);
}
}
Model2Ex03.WebContent.model2.board_list1
<%@page import="model1.BoardTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!-- Java 전처리 -->
<%@ page import="java.util.ArrayList" %>
<%
ArrayList<BoardTO> lists = (ArrayList)request.getAttribute("lists");
int totalRecord = lists.size();
StringBuffer sb = new StringBuffer();
for(BoardTO to : lists) {
String seq = to.getSeq();
String subject = to.getSubject();
String writer = to.getWriter();
String wdate = to.getWdate();
String hit = to.getHit();
int wgap = to.getWgap();
sb.append("<tr>");
sb.append(" <td> </td>");
sb.append(" <td>" + seq + "</td>");
if(wgap == 0 ) {
sb.append(" <td class='left'><a href='./view.do?seq=" + seq + "'>" + subject + "</a> <img src='../images/icon_hot.gif' alt='HOT'></td>");
} else {
sb.append(" <td class='left'><a href='./view.do?seq=" + seq + "'>" + subject + "</a></td>");
}
sb.append(" <td>" + writer + "</td>");
sb.append(" <td>" + wdate + "</td>");
sb.append(" <td>" + hit + "</td>");
sb.append(" <td> </td>");
sb.append("</tr>");
}
%>
<!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_list.css">
</head>
<body>
<!-- 상단 디자인 -->
<div class="con_title">
<h3>게시판</h3>
<p>HOME > 게시판 > <strong>게시판</strong></p>
</div>
<div class="con_txt">
<div class="contents_sub">
<div class="board_top">
<div class="bold">총 <span class="txt_orange"><%=totalRecord %></span>건</div>
</div>
<!--게시판-->
<div class="board">
<table>
<tr>
<th width="3%"> </th>
<th width="5%">번호</th>
<th>제목</th>
<th width="10%">글쓴이</th>
<th width="17%">등록일</th>
<th width="5%">조회</th>
<th width="3%"> </th>
</tr>
<tr>
<!-- 시작 -->
<%= sb %>
<!-- 끝 -->
</tr>
</table>
</div>
<!--//게시판-->
<div class="align_right">
<button type="button" class="btn_write btn_txt01" style="cursor: pointer;" onclick="location.href='./write.do'">쓰기</button>
</div>
</div>
</div>
<!--//하단 디자인 -->
</body>
</html>
Model2Ex03.WebContent.model2.board_write1
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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_write.css">
<script type="text/javascript">
window.onload = function() {
document.getElementById('submit1').onclick = function() {
//alert('click');
if(document.frm.info.checked == false) {
alert('동의하셔야 합니다.');
return;
}
if(document.frm.writer.value.trim() == "") {
alert('이름을 입력하셔야 합니다.');
return;
}
if(document.frm.password.value.trim() == "") {
alert('비밀번호를 입력하셔야 합니다.');
return;
}
if(document.frm.subject.value.trim() == "") {
alert('제목을 입력하셔야 합니다.');
return;
}
document.frm.submit();
};
};
</script>
</head>
<body>
<!-- 상단 디자인 -->
<div class="con_title">
<h3>게시판</h3>
<p>HOME > 게시판 > <strong>게시판</strong></p>
</div>
<div class="con_txt">
<form action="./write_ok.do" method="post" name="frm">
<div class="contents_sub">
<!--게시판-->
<div class="board_write">
<table>
<tr>
<th class="top">글쓴이</th>
<td class="top" colspan="3"><input type="text" name="writer" value="" class="board_view_input_mail" maxlength="5" /></td>
</tr>
<tr>
<th>제목</th>
<td colspan="3"><input type="text" name="subject" value="" class="board_view_input" /></td>
</tr>
<tr>
<th>비밀번호</th>
<td colspan="3"><input type="password" name="password" value="" class="board_view_input_mail"/></td>
</tr>
<tr>
<th>내용</th>
<td colspan="3"><textarea name="content" class="board_editor_area"></textarea></td>
</tr>
<tr>
<th>이메일</th>
<td colspan="3"><input type="text" name="mail1" value="" class="board_view_input_mail"/> @ <input type="text" name="mail2" value="" class="board_view_input_mail"/></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">
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='./list.do'">목록</button>
</div>
<div class="align_right">
<button type="button" id="submit1" class="btn_write btn_txt01" style="cursor: pointer;">등록</button>
</div>
</div>
<!--//게시판-->
</div>
</form>
</div>
<!-- 하단 디자인 -->
</body>
</html>
Model2Ex03.WebContent.model2.board_write1_ok
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
int flag = (Integer)request.getAttribute("flag");
out.println("<script type='text/javascript'>");
if(flag == 0) {
out.println("alert('글쓰기에 성공했습니다.');");
out.println("location.href='./list.do';");
} else if(flag == 1) {
out.println("alert('글쓰기에 실패했습니다.');");
out.println("history.back();");
}
out.println("</script>");
%>
Model2Ex03.WebContent.model2.board_view1
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="model1.BoardTO" %>
<%
BoardTO to = (BoardTO)request.getAttribute("to");
String seq = to.getSeq();
String subject = to.getSubject();
String writer = to.getWriter();
String wdate = to.getWdate();
String hit = to.getHit();
String content = to.getContent();
String mail = to.getMail();
%>
<!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_view.css">
</head>
<body>
<!-- 상단 디자인 -->
<div class="con_title">
<h3>게시판</h3>
<p>HOME > 게시판 > <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%"><%= subject %></td>
<th width="10%">등록일</th>
<td width="20%"><%= wdate %></td>
</tr>
<tr>
<th>글쓴이</th>
<td><%= writer %><%= '(' + mail + ')' %></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">
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='./list.do'">목록</button>
</div>
<div class="align_right">
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='./modify.do?seq=<%= seq %>'">수정</button>
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='./delete.do?seq=<%= seq %>'">삭제</button>
<button type="button" class="btn_write btn_txt01" style="cursor: pointer;" onclick="location.href='./write.do'">쓰기</button>
</div>
</div>
<!--//게시판-->
</div>
</div>
<!-- 하단 디자인 -->
</body>
</html>
Model2Ex03.WebContent.model2.board_delete1
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="model1.BoardTO" %>
<%@ page import="model1.BoardDAO" %>
<%
BoardTO to = (BoardTO)request.getAttribute("to");
String seq = to.getSeq();
String subject = to.getSubject();
String writer = to.getWriter();
%>
<!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_write.css">
<script type="text/javascript">
window.onload = function() {
document.getElementById('submit1').onclick = function() {
if(document.frm.password.value.trim() == "") {
alert('비밀번호를 입력하셔야 합니다.');
return;
}
document.frm.submit();
};
};
</script>
</head>
<body>
<!-- 상단 디자인 -->
<div class="con_title">
<h3>게시판</h3>
<p>HOME > 게시판 > <strong>게시판</strong></p>
</div>
<div class="con_txt">
<form action="./delete_ok.do" method="post" name="frm">
<input type="hidden" name="seq" value="<%=seq %>" /> <!-- delete할 때 seq를 받아오기 위해 hidden으로해서 작성 / 브라우저에서 소스보기 하면 값 확인가능 -->
<div class="contents_sub">
<!--게시판-->
<div class="board_write">
<table>
<tr>
<th class="top">글쓴이</th>
<td class="top" colspan="3"><input type="text" name="writer" value="<%= writer %>" class="board_view_input_mail" maxlength="5" readonly/></td>
</tr>
<tr>
<th>제목</th>
<td colspan="3"><input type="text" name="subject" value="<%= subject %>" class="board_view_input" readonly/></td>
</tr>
<tr>
<th>비밀번호</th>
<td colspan="3"><input type="password" name="password" value="" class="board_view_input_mail"/></td>
</tr>
</table>
</div>
<div class="btn_area">
<div class="align_left">
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='./list.do'">목록</button>
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='./view.do?seq=<%=seq %>'">보기</button>
</div>
<div class="align_right">
<button type="button" id="submit1" class="btn_write btn_txt01" style="cursor: pointer;">삭제</button>
</div>
</div>
<!--//게시판-->
</div>
</form>
</div>
<!-- 하단 디자인 -->
</body>
</html>
Model2Ex03.WebContent.model2.board_delete1_ok
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
int flag = (Integer)request.getAttribute("flag");
out.println("<script type='text/javascript'>");
if(flag == 0) {
out.println("alert('글 삭제에 성공했습니다.');");
out.println("location.href='./list.do';");
} 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>");
%>
Model2Ex03.WebContent.model2.board_modify1
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="model1.BoardTO" %>
<%
BoardTO to = (BoardTO)request.getAttribute("to");
String seq = to.getSeq();
String subject = to.getSubject();
String writer = to.getWriter();
String content = to.getContent();
String mail[] = to.getMail().split("@");
if(mail.length == 0) {
mail = new String[] {"", ""};
}
%>
<!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_write.css">
<script type="text/javascript">
window.onload = function() {
document.getElementById('submit1').onclick = function() {
if(document.frm.writer.value.trim() == "") {
alert('이름을 입력하셔야 합니다.');
return;
}
if(document.frm.password.value.trim() == "") {
alert('비밀번호를 입력하셔야 합니다.');
return;
}
if(document.frm.subject.value.trim() == "") {
alert('제목을 입력하셔야 합니다.');
return;
}
document.frm.submit();
};
};
</script>
</head>
<body>
<!-- 상단 디자인 -->
<div class="con_title">
<h3>게시판</h3>
<p>HOME > 게시판 > <strong>게시판</strong></p>
</div>
<div class="con_txt">
<form action="./modify_ok.do" method="post" name="frm">
<input type="hidden" name="seq" value="<%=seq %>" />
<div class="contents_sub">
<!--게시판-->
<div class="board_write">
<table>
<tr>
<th class="top">글쓴이</th>
<td class="top" colspan="3"><input type="text" name="writer" value="<%=writer %>" class="board_view_input_mail" maxlength="5" readonly/></td>
</tr>
<tr>
<th>제목</th>
<td colspan="3"><input type="text" name="subject" value="<%=subject %>" class="board_view_input" /></td>
</tr>
<tr>
<th>비밀번호</th>
<td colspan="3"><input type="password" name="password" value="" class="board_view_input_mail"/></td>
</tr>
<tr>
<th>내용</th>
<td colspan="3"><textarea name="content" class="board_editor_area"><%=content %></textarea></td>
</tr>
<tr>
<th>이메일</th>
<td colspan="3"><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>
</table>
</div>
<div class="btn_area">
<div class="align_left">
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='./list.do'">목록</button>
<button type="button" class="btn_list btn_txt02" style="cursor: pointer;" onclick="location.href='./view.do?seq=<%=seq %>'">보기</button>
</div>
<div class="align_right">
<button type="button" id="submit1" class="btn_write btn_txt01" style="cursor: pointer;">수정</button>
</div>
</div>
<!--//게시판-->
</div>
</form>
</div>
<!-- 하단 디자인 -->
</body>
</html>
Model2Ex03.WebContent.model2.board_modify1_ok
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="model1.BoardTO" %>
<%
String seq = (String)request.getAttribute("seq");
int flag = (Integer)request.getAttribute("flag");
out.println("<script type='text/javascript'>");
if(flag == 0) {
out.println("alert('글 수정에 성공했습니다.');");
out.println("location.href='./view.do?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>");
%>
댓글