728x90
create table mvc_board(
bId NUMBER(4) PRIMARY KEY,
bName VARCHAR2(20),
bTitle VARCHAR2(100),
bContent VARCHAR2(300),
bDate DATE DEFAULT SYSDATE,
bHit NUMBER(4) DEFAULT 0,
bGroup NUMBER(4),
bStep NUMBER(4),
bIndent NUMBER(4)
);
create sequence mvc_board_seq;
insert into mvc_board(bId, bName, bTitle, bContent,
bHit, bGroup, bStep, bIndent)
values (mvc_board_seq.nextval, 'abcd', 'is title', 'is content',
0, mvc_board_seq.currval, 0, 0);
select * from mvc_board;
commit; //★ 커밋 이 부분 해줘야 서블렛 실행됨
insert into mvc_board(bId, bName, bTitle, bContent,
bHit, bGroup, bStep, bIndent)
values (mvc_board_seq.nextval, 'abcd', 'is title', 'is content',
0, mvc_board_seq.currval, 0, 0); 이거 실행 한번 더해주면 bid에 알아서 1행이 더 삽입된다.
[list.jsp]
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<table width="500" cellpadding="0" cellspacing="0" border="1">
<tr>
<td>번호</td>
<td>이름</td>
<td>제목</td>
<td>날짜</td>
<td>히트</td>
</tr>
<c:forEach items="${list}" var="dto">
<%-- list는 request객체 안에 있기 때문에 그냥 forward시킨쪽에서는 그냥 ${list}라고 쓰면된다.
list는 BListCommand.java에있다. --%>
<tr>
<td>${dto.bId}</td>
<!-- dto안에있는 bId꺼내오는것 -->
<td>${dto.bName}</td>
<td>
<c:forEach begin="1" end="${dto.bIndent}">-</c:forEach>
<a href="content_view.do?bId=${dto.bId}">${dto.bTitle}</a></td>
<td>${dto.bDate}</td>
<td>${dto.bHit}</td>
</tr>
</c:forEach>
<tr>
<td colspan="5"> <a href="write_view.do">글작성</a> </td>
</tr>
</table>
</body>
</html>
[BFrontController.java]
[BFrontController.java]
package edu.bit.ex.controller;
//패키지명 반드시 이렇게 쓰기
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 edu.bit.ex.command.BCommand;
import edu.bit.ex.command.BContentCommand;
import edu.bit.ex.command.BDeleteCommand;
import edu.bit.ex.command.BListCommand;
import edu.bit.ex.command.BModifyCommand;
import edu.bit.ex.command.BReplyCommand;
import edu.bit.ex.command.BReplyViewCommand;
import edu.bit.ex.command.BWriteCommand;
@WebServlet("*.do")
// 유저가 url치고들어오는데 뭘치고 들어오든 .do(controll로 들어오는거)면 다 받겠다.
public class BFrontController extends HttpServlet {
private static final long serialVersionUID = 1L;
public BFrontController() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("doGet");
actionDo(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
private void actionDo(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { // 한글처리했을때 에러나서 throws 추가
System.out.println("actionDo"); // .do로 들어오면 actionDo로 표시하겠다.
//doGet, doPost 둘 중 하나의 요청을 받으면 actionDo 메서드로 넘겨준다.
request.setCharacterEncoding("EUC-KR");
String viewPage = null; // FrontController에서 view들을 결정하는것.
BCommand command = null; // 그림에 command command 객체가 바로 이거.
// Command가 인터페이스(자손구현하는것)이다.
String uri = request.getRequestURI();//uri를 얻어옴
String conPath = request.getContextPath(); //contextPath를 얻어옴
String com = uri.substring(conPath.length());//요청받은 파일명을 얻기위한 작업?
System.out.println(uri);
System.out.println(conPath);
System.out.println(com);
if (com.equals("/list.do")) {
// .list.do 이렇게 치고 들어오게 링크주는것.
command = new BListCommand();
// ↑다형성 적용. BCommand는 부모
command.execute(request, response);
viewPage = "list.jsp";
} else if (com.equals("/content_view.do")) {
// .list.do 이렇게 치고 들어오게 링크주는것.
command = new BContentCommand();
// ↑다형성 적용. BCommand는 부모
command.execute(request, response);
viewPage = "content_view.jsp";
// 얘로 받아와야하니까 수정.
} else if (com.equals("/write_view.do")) {
//글 작성화면을 요청받으면
viewPage = "write_view.jsp";
//viewPage에 파일명이 담겨서 dispatcher로 포워딩 해줌
} else if (com.equals("/write.do")) {
// write.do에서 넘어오는거만듦
command = new BWriteCommand();
command.execute(request, response);
viewPage = "list.do";
// write가끝났으면 list.do로 돌아가야하니까
} else if (com.equals("/delete.do")) {
// write.do에서 넘어오는거만듦
command = new BDeleteCommand();
command.execute(request, response);
viewPage = "list.do";
// write가끝났으면 list.do로 돌아가야하니까
} else if (com.equals("/modify.do")) {
// write.do에서 넘어오는거만듦
command = new BModifyCommand();
command.execute(request, response);
viewPage = "list.do";
// write가끝났으면 list.do로 돌아가야하니까
} else if (com.equals("/reply_view.do")) {
// write.do에서 넘어오는거만듦
command = new BReplyViewCommand();
command.execute(request, response);
viewPage = "/reply_view.jsp";
} else if (com.equals("/reply.do")) {
command = new BReplyCommand();
command.execute(request, response);
viewPage = "list.do";
}
//viewPage의 값이 jsp로 끝나면 UI화면을 띄워주고
//do로 끝나면 커맨드를 생성하여 적절한 로직을 실행 후 list.do로 포워딩한다
RequestDispatcher dispatcher = request.getRequestDispatcher(viewPage);
dispatcher.forward(request, response); // 위치헷갈리지말기...
}
}
[BDao.java]
[BDao.java] src- edu.bit.ex.dao-BDao.java
package edu.bit.ex.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import edu.bit.ex.dto.BDto;
public class BDao {
DataSource dataSource;
// 이게 바로 커넥션풀객체 = 데이터소스
public BDao() {
try {
Context context = new InitialContext();
//context는 해당서버안에있는 context.xml에서 만든 Resource 읽어오는것이다.
dataSource = (DataSource) context.lookup("java:comp/env/jdbc/oracle");
// java:~~은 고슬링아저씨가 만들어놓은것.
// context에서 뭘찾냐? env(환경설정)에서 jdbc(Resource에 name에 있는걸 불러옴. 따라서 jdbc/뒤에있는거랑 똑같이
// 써야함
// 정리 : /jdbc/oracle은 커넥션풀에있는 name에있는거랑 똑같이 적어줘야한다.
} catch (Exception e) {
e.printStackTrace();
}
}
public ArrayList<BDto> list() {
// BDto는 게시판
ArrayList<BDto> dtos = new ArrayList<BDto>();
Connection connection = null;
PreparedStatement preparedStatement = null;
//preparedStatement가 속도, 사용법, 보안 전부 좋음.
ResultSet resultSet = null;
try {
connection = dataSource.getConnection();
// 예전엔 drivermanager.으로 가져왔는데 getConnection해서 바로 꺼내옴. 한줄로끝
String query = "select bId, bName, bTitle, bContent, bDate, bHit, bGroup, bStep, bIndent from mvc_board order by bGroup desc, bStep asc";
// order by bGroup desc, bStep asc 이부분안해주면 댓글 정렬이 안된다. 이거까지 해야 댓글순서대로 제대로 끌고 오는
// 것임. 반드시 외울것!★
preparedStatement = connection.prepareStatement(query);
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
int bId = resultSet.getInt("bId");
String bName = resultSet.getString("bName");
String bTitle = resultSet.getString("bTitle");
String bContent = resultSet.getString("bContent");
Timestamp bDate = resultSet.getTimestamp("bDate");
//timestamp는 java sql로 임포트
int bHit = resultSet.getInt("bHit");
int bGroup = resultSet.getInt("bGroup");
int bStep = resultSet.getInt("bStep");
int bIndent = resultSet.getInt("bIndent");
BDto dto = new BDto(bId, bName, bTitle, bContent, bDate, bHit, bGroup, bStep, bIndent);
dtos.add(dto);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (resultSet != null)
resultSet.close();
if (preparedStatement != null)
preparedStatement.close();
if (connection != null)
connection.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
return dtos;
}
public BDto contentView(String bId) {
BDto dtos = null;// 위에Array소스 복붙하고 얘는 배열받을필요없으니까 수정
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
connection = dataSource.getConnection();
String query = "select * from mvc_board where bId =?";
// ?로 받기.이건 prepareStatement의 자바문법이니 외우기\
// ?는 함수에서 변수로 넘어올때 쓴다.
preparedStatement = connection.prepareStatement(query);
preparedStatement.setInt(1, Integer.parseInt(bId)); // bId가 int여서 1로주고 파싱하기
// 이렇게 쓰면 위에 ?에 자동으로 1이 들어간다.
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
int id = resultSet.getInt("bId");
// 위에 bid있으니까 id로 수정
String bName = resultSet.getString("bName");
String bTitle = resultSet.getString("bTitle");
String bContent = resultSet.getString("bContent");
Timestamp bDate = resultSet.getTimestamp("bDate");
int bHit = resultSet.getInt("bHit");
int bGroup = resultSet.getInt("bGroup");
int bStep = resultSet.getInt("bStep");
int bIndent = resultSet.getInt("bIndent");
dtos = new BDto(id, bName, bTitle, bContent, bDate, bHit, bGroup, bStep, bIndent);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (resultSet != null)
resultSet.close();
if (preparedStatement != null)
preparedStatement.close();
if (connection != null)
connection.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
return dtos;
}
public void write(String bName, String bTitle, String bContent) {
// 위에contentView소스 복붙.
Connection connection = null;
PreparedStatement preparedStatement = null;
// ResultSet resultSet = null; - 얘는 필요없다.
try {
connection = dataSource.getConnection();
String query = "insert into mvc_board (bId, bName, bTitle, bContent, bHit, bGroup, bStep, bIndent) values (mvc_board_seq.nextval, ?, ?, ?, 0, mvc_board_seq.currval, 0, 0 )";
// ?로 받기.이건 prepareStatement의 자바문법이니 외우기
// ?는 함수에서 변수로 넘어올때 쓴다.
preparedStatement = connection.prepareStatement(query);
preparedStatement.setString(1, bName);
preparedStatement.setString(2, bTitle);
preparedStatement.setString(3, bContent);
int rn = preparedStatement.executeUpdate();
// insert는 update로 들어가줘야함
System.out.println("insert 결과" + rn);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (preparedStatement != null)
preparedStatement.close();
if (connection != null)
connection.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
public void delete(int bId) {
// 위에 write 소스 복붙.
Connection connection = null;
PreparedStatement preparedStatement = null;
try {
connection = dataSource.getConnection();
String query = "delete from mvc_board where bId=?";
preparedStatement = connection.prepareStatement(query);
preparedStatement.setInt(1, bId);
int rn = preparedStatement.executeUpdate();
//
System.out.println("delete 결과" + rn);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (preparedStatement != null)
preparedStatement.close();
if (connection != null)
connection.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
public void modify(int bId, String bName, String bTitle, String bContent) {
// 위에 write 소스 복붙.
Connection connection = null;
PreparedStatement preparedStatement = null;
try {
connection = dataSource.getConnection();
String query = "update mvc_board set bName = ?, bTitle = ?, bContent = ? where bId = ?";
preparedStatement = connection.prepareStatement(query);
preparedStatement.setString(1, bName);
preparedStatement.setString(2, bTitle);
preparedStatement.setString(3, bContent);
preparedStatement.setInt(4, bId);
int rn = preparedStatement.executeUpdate();
System.out.println("modify 결과" + rn);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (preparedStatement != null)
preparedStatement.close();
if (connection != null)
connection.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
public BDto reply_view(String bId) {
// 글 받아오는거라 contentview랑 똑같다.
BDto dtos = null;
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
connection = dataSource.getConnection();
String query = "select * from mvc_board where bId =?";
// 쿼리도 contentview랑 똑같.
preparedStatement = connection.prepareStatement(query);
preparedStatement.setInt(1, Integer.parseInt(bId)); // bId가 int여서 1로주고 파싱하기
// 이렇게 쓰면 위에 ?에 자동으로 1이 들어간다.
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
int id = resultSet.getInt("bId");
// 위에 bid있으니까 id로 수정
String bName = resultSet.getString("bName");
String bTitle = resultSet.getString("bTitle");
String bContent = resultSet.getString("bContent");
Timestamp bDate = resultSet.getTimestamp("bDate");
int bHit = resultSet.getInt("bHit");
int bGroup = resultSet.getInt("bGroup");
int bStep = resultSet.getInt("bStep");
int bIndent = resultSet.getInt("bIndent");
dtos = new BDto(id, bName, bTitle, bContent, bDate, bHit, bGroup, bStep, bIndent);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (resultSet != null)
resultSet.close();
if (preparedStatement != null)
preparedStatement.close();
if (connection != null)
connection.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
return dtos;
}
public void reply(String bId, String bName, String bTitle, String bContent, String bGroup, String bStep,
String bIndent) {
replyShape(bGroup, bStep);
Connection connection = null;
PreparedStatement preparedStatement = null;// result필요없이 insert다.
try {
connection = dataSource.getConnection();
String query = "insert into mvc_board (bId, bName, bTitle, bContent, bGroup, bStep, bIndent) values (mvc_board_seq.nextval, ?, ?, ?, ?, ?, ?)";
preparedStatement = connection.prepareStatement(query);
preparedStatement.setString(1, bName);
preparedStatement.setString(2, bTitle);
preparedStatement.setString(3, bContent);
// ↓bGroup, bStep, bIndent를 어떻게 구현할것인지????
// 댓글달땐 원본글기준, 그 대댓달땐 댓글기준.-기준을 그대로 끌고온다.(bGroup)
// 댓글달땐 원본글기준으로 밑에 달리고, 그 대댓달땐 댓글기준 밑에달림.(bStep=세로) +1해준다
// 댓글달땐 원본글기준으로 가로로 한칸 밀림, 그 대댓달땐 댓글기준으로 가로로 한칸 밀린다.(bIndent=가로) +1해준다
preparedStatement.setInt(4, Integer.parseInt(bGroup));
preparedStatement.setInt(5, Integer.parseInt(bStep) + 1);
preparedStatement.setInt(6, Integer.parseInt(bIndent) + 1);
int rn = preparedStatement.executeUpdate();
System.out.println("reply 결과" + rn);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (preparedStatement != null)
preparedStatement.close();
if (connection != null)
connection.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
private void replyShape(String bGroup, String bStep) {
// TODO Auto-generated method stub
Connection connection = null;
PreparedStatement preparedStatement = null;
try {
connection = dataSource.getConnection();
String query = "update mvc_board set bStep = bStep + 1 where bGroup = ? and bStep > ?";
preparedStatement = connection.prepareStatement(query);
preparedStatement.setInt(1, Integer.parseInt(bGroup));
preparedStatement.setInt(2, Integer.parseInt(bStep));
int rn = preparedStatement.executeUpdate();
System.out.println("reply 결과" + rn);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
} finally {
try {
if (preparedStatement != null)
preparedStatement.close();
if (connection != null)
connection.close();
} catch (Exception e2) {
// TODO: handle exception
e2.printStackTrace();
}
}
}
public void upHit(String bId) {
Connection connection = null;
PreparedStatement preparedStatement = null;
//제목을 클릭하게되면 bHit+1이 된다. content_view눌렀는데 bid랑 같은숫자이면 bHit+1
//그럼 content_view쪽에 이 부분을 넣어줘야한다.
try {
connection = dataSource.getConnection();
String query = "update mvc_board set bHit = bHit + 1 where bId=?";
preparedStatement = connection.prepareStatement(query);
preparedStatement.setString(1, bId);//이걸넣어야 실행이 된다!!!!
int rn = preparedStatement.executeUpdate();
System.out.println("hit 결과" + rn);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (preparedStatement != null)
preparedStatement.close();
if (connection != null)
connection.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}
[BDto.java]
[BDto.java]
package edu.bit.ex.dto;
import java.sql.Timestamp;
public class BDto {
int bId;
String bName;
String bTitle;
String bContent;
Timestamp bDate;
int bHit;
int bGroup;
int bStep;
int bIndent;
public BDto() {
//디폴트 생성자 반드시 만든다.
}
public BDto(int bId, String bName, String bTitle,
String bContent, Timestamp bDate, int bHit,
int bGroup, int bStep, int bIndent) {
//나중에 arrays로 갖고 끌고올거임
this.bId = bId;
this.bName = bName;
this.bTitle = bTitle;
this.bContent = bContent;
this.bDate = bDate;
this.bHit = bHit;
this.bGroup = bGroup;
this.bStep = bStep;
this.bIndent = bIndent;
}
public int getbId() {
return bId;
}
public void setbId(int bId) {
this.bId = bId;
}
public String getbName() {
return bName;
}
public void setbName(String bName) {
this.bName = bName;
}
public String getbTitle() {
return bTitle;
}
public void setbTitle(String bTitle) {
this.bTitle = bTitle;
}
public String getbContent() {
return bContent;
}
public void setbContent(String bContent) {
this.bContent = bContent;
}
public Timestamp getbDate() {
return bDate;
}
public void setbDate(Timestamp bDate) {
this.bDate = bDate;
}
public int getbHit() {
return bHit;
}
public void setbHit(int bHit) {
this.bHit = bHit;
}
public int getbGroup() {
return bGroup;
}
public void setbGroup(int bGroup) {
this.bGroup = bGroup;
}
public int getbStep() {
return bStep;
}
public void setbStep(int bStep) {
this.bStep = bStep;
}
public int getbIndent() {
return bIndent;
}
public void setbIndent(int bIndent) {
this.bIndent = bIndent;
}
}
==============<model단>==========
8개 : BCommand, BListCommand, BDeleteCommand, BListCommand, BModifyCommand, BReplyCommand, BReplyViewCommand, BWriteCommand
[BCommand.java]
[BCommand.java]
package edu.bit.ex.command;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public interface BCommand {
//인터페이스안에 추상함수가 들어감
abstract void execute(HttpServletRequest request,
HttpServletResponse response);
//지금하고있는것은 list갖고와서 list뿌리는것.
//list갖고오기 - BListCommand 자손만들기
}
[BListCommand.java]
package edu.bit.ex.command;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import edu.bit.ex.dao.BDao;
import edu.bit.ex.dto.BDto;
//지금하고있는것은 list갖고와서 list뿌리는것. 중
//list갖고오기
public class BListCommand implements BCommand {
// implements 자손이 구현하라
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
BDao dao = new BDao(); // 그림에서 Dao가 command 호출하고 있는부분
// package edu.bit.ex.dao;
// class BDao 생성
ArrayList<BDto> dtos = dao.list();
request.setAttribute("list", dtos);
//session.setAttribute("list", dtos); 로 써도 가능!
}
}
[BContentCommand.java]
[BContentCommand.java]
package edu.bit.ex.command;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import edu.bit.ex.dao.BDao;
import edu.bit.ex.dto.BDto;
public class BContentCommand implements BCommand {
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
String bId= request.getParameter("bId");
BDao dao = new BDao();
BDto dto = dao.contentView(bId); //BDao.java 에 생성
//array에 ctrl+c,v
request.setAttribute("content_view", dto);
}
}
[Bwritecommand.java]
[BWritecommand.java]
package edu.bit.ex.command;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import edu.bit.ex.dao.BDao;
public class BWriteCommand implements BCommand {
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
String bName = request.getParameter("bName");
String bTitle = request.getParameter("bTitle");
String bContent = request.getParameter("bContent");
BDao dao = new BDao();
dao.write(bName, bTitle, bContent);
}
}
[BDeleteCommand.java]
[BDeleteCommand.java]
package edu.bit.ex.command;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import edu.bit.ex.dao.BDao;
public class BDeleteCommand implements BCommand {
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
int bId = Integer.parseInt(request.getParameter("bId"));
BDao dao = new BDao();
dao.delete(bId);
}
}
[BModifyCommand.java]
[BModifyCommand.java]
package edu.bit.ex.command;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import edu.bit.ex.dao.BDao;
public class BModifyCommand implements BCommand {
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
int bId = Integer.parseInt(request.getParameter("bId"));
String bName = request.getParameter("bName");
String bTitle = request.getParameter("bTitle");
String bContent = request.getParameter("bContent");
BDao dao = new BDao();
dao.modify(bId, bName, bTitle, bContent);
}
}
[BReplyCommand.java]
[BReplyCommand.java]
package edu.bit.ex.command;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import edu.bit.ex.dao.BDao;
public class BReplyCommand implements BCommand {
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
// 원본글작성할땐 bId, bName, bTitle 세개만 필요했음.
// bName,bTitle, bContent는 원본글/ bGroup, bStep, bIndent는 답변관련
String bId = request.getParameter("bId");
String bName = request.getParameter("bName");
String bTitle = request.getParameter("bTitle");
String bContent = request.getParameter("bContent");
String bGroup = request.getParameter("bGroup");
String bStep = request.getParameter("bStep");
String bIndent = request.getParameter("bIndent");
BDao dao = new BDao();
dao.reply(bId, bName, bTitle, bContent, bGroup, bStep, bIndent);
}
}
[BReplyViewCommand.java]
[BReplyViewCommand.java]
package edu.bit.ex.command;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import edu.bit.ex.dao.BDao;
import edu.bit.ex.dto.BDto;
public class BReplyViewCommand implements BCommand {
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) {
//원본글을 먼저 뿌린다음에 수정
String bId = request.getParameter("bId");
//원본글 수정해야하니까 가져오기
BDao dao = new BDao();
BDto dto = dao.reply_view(bId);
request.setAttribute("reply_view",dto);
}
}
==================<view단>==================
[list.jsp]
[list.jsp] WebContent-list.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<table width="500" cellpadding="0" cellspacing="0" border="1">
<tr>
<td>번호</td>
<td>이름</td>
<td>제목</td>
<td>날짜</td>
<td>히트</td>
</tr>
<c:forEach items="${list}" var="dto">
<%-- list는 request객체 안에 있기 때문에 그냥 forward시킨쪽에서는 그냥 ${list}라고 쓰면된다.
list는 BListCommand.java에있다. --%>
<tr>
<td>${dto.bId}</td>
<!-- dto안에있는 bId꺼내오는것 -->
<td>${dto.bName}</td>
<td>
<c:forEach begin="1" end="${dto.bIndent}">-</c:forEach>
<a href="content_view.do?bId=${dto.bId}">${dto.bTitle}</a></td>
<td>${dto.bDate}</td>
<td>${dto.bHit}</td>
</tr>
</c:forEach>
<tr>
<td colspan="5"> <a href="write_view.do">글작성</a> </td>
</tr>
</table>
</body>
</html>
[content_view.jsp]
[content_view.jsp]
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<table width="500" cellpadding="0" cellspacing="0" border="1">
<form action="modify.do" method="post">
<input type="hidden" name="bId" value="${content_view.bId}">
<tr>
<td> 번호 </td>
<td> ${content_view.bId} </td>
</tr>
<tr>
<td> 히트 </td>
<td> ${content_view.bHit} </td>
</tr>
<tr>
<td> 이름 </td>
<td> <input type="text" name="bName" value="${content_view.bName}"></td>
</tr>
<tr>
<td> 제목 </td>
<td> <input type="text" name="bTitle" value="${content_view.bTitle}"></td>
</tr>
<tr>
<td> 내용 </td>
<td> <textarea rows="10" name="bContent" >${content_view.bContent}</textarea></td>
</tr>
<tr >
<td colspan="2"> <input type="submit" value="수정"> <a href="list.do">목록보기</a> <a href="delete.do?bId=${content_view.bId}">삭제</a> <a href="reply_view.do?bId=${content_view.bId}">답변</a></td>
</tr>
</form>
</table>
</body>
</html>
[reply_view.jsp]
[reply_view.jsp]
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<table width="500" cellpadding="0" cellspacing="0" border="1">
<form action="reply.do" method="post">
<!-- 이렇게 hidden하게 되면 안보임. 유저한테 안보이게 숨기려면 이렇게 해야함. -->
<input type="hidden" name="bId" value="${reply_view.bId}">
<input type="hidden" name="bGroup" value="${reply_view.bGroup}">
<input type="hidden" name="bStep" value="${reply_view.bStep}">
<input type="hidden" name="bIndent" value="${reply_view.bIndent}">
<tr>
<td> 번호 </td>
<td> ${reply_view.bId} </td>
</tr>
<tr>
<td> 히트 </td>
<td> ${reply_view.bHit} </td>
</tr>
<tr>
<td> 이름 </td>
<td> <input type="text" name="bName" value="${reply_view.bName}"></td>
</tr>
<tr>
<td> 제목 </td>
<td> <input type="text" name="bTitle" value="${reply_view.bTitle}"></td>
</tr>
<tr>
<td> 내용 </td>
<td> <textarea rows="10" name="bContent">${reply_view.bContent}</textarea></td>
</tr>
<tr >
<td colspan="2"><input type="submit" value="답변"> <a href="list.do" >목록</a></td>
</tr>
</form>
</table>
</body>
</html>
[write_view.jsp]
[write_view.jsp]
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<table width="500" cellpadding="0" cellspacing="0" border="1">
<form action="write.do" method="post">
<tr>
<td> 이름 </td>
<td> <input type="text" name="bName" size = "50"> </td>
</tr>
<tr>
<td> 제목 </td>
<td> <input type="text" name="bTitle" size = "50"> </td>
</tr>
<tr>
<td> 내용 </td>
<td> <textarea name="bContent" rows="10" ></textarea> </td>
</tr>
<tr >
<td colspan="2"> <input type="submit" value="입력"> <a href="list.do">목록보기</a></td>
</tr>
</form>
</table>
</body>
</html>
728x90
댓글