<Main.jsp>
<%@page import="com.smhrd.model.MemberVO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Forty by HTML5 UP</title>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="assets/css/main.css" />
</head>
<body>
<%
// 2. session에 저장된 로그인 정보 가져오기
MemberVO vo = (MemberVO)session.getAttribute("member");
%>
<!-- Wrapper -->
<div id="wrapper">
<!-- Header -->
<header id="header" class="alt">
<a href="index.html" class="logo"><strong>Forty</strong> <span>by HTML5 UP</span></a>
<nav>
<% if(vo == null) {%>
<a href="#menu">로그인</a>
<%}else{%>
<% if(vo.getEmail().equals("admin")){ %>
<a href="select.jsp">회원정보관리</a>
<%} %>
<a href="update.jsp">개인정보수정</a>
<a href = "logoutService.do">로그아웃</a>
<%} %>
</nav>
</header>
<!-- Menu -->
<nav id="menu">
<ul class="links">
<li><h5>로그인</h5></li>
<form action = "LoginService.do" method = "post">
<li><input type="text" placeholder="Email을 입력하세요" name="email"></li>
<li><input type="password" placeholder="PW를 입력하세요" name="pw"></li>
<li><input type="submit" value="LogIn" class="button fit"></li>
</form>
</ul>
<ul class="actions vertical">
<li><h5>회원가입</h5></li>
<form action = "JoinService.do" method = "post">
<li><input type="text" placeholder="Email을 입력하세요" name="email"></li>
<li><input type="password" placeholder="PW를 입력하세요" name="pw"></li>
<li><input type="text" placeholder="전화번호를 입력하세요" name="phone"></li>
<li><input type="text" placeholder="집주소를 입력하세요" name ="address" ></li>
<li><input type="submit" value="JoinUs" class="button fit"></li>
</form>
</ul>
</nav>
<!-- Banner -->
<section id="banner" class="major">
<div class="inner">
<header class="major">
<% if(vo != null) {%>
<h1><%=vo.getEmail()%>님 환영합니다. </h1>
<%}else{%>
<h1>로그인 해주세요.</h1>
<%} %>
</header>
<div class="content">
<p> 게시판으로 이동! <br></p>
<ul class="actions">
<li><a href="boardMain.jsp" class="button next scrolly">게시판</a></li>
</ul>
</div>
</div>
</section>
<!-- Main -->
<div id="main">
<!-- One -->
<section id="one" class="tiles">
<article>
<span class="image">
<img src="images/pic01.jpg" alt="" />
</span>
<header class="major">
<h3><a href="#" class="link">HTML</a></h3>
<p>홈페이지를 만드는 기초 언어</p>
</header>
</article>
<article>
<span class="image">
<img src="images/pic02.jpg" alt="" />
</span>
<header class="major">
<h3><a href="#" class="link">CSS</a></h3>
<p>HTML을 디자인해주는 언어</p>
</header>
</article>
<article>
<span class="image">
<img src="images/pic03.jpg" alt="" />
</span>
<header class="major">
<h3><a href="#" class="link">Servlet/JSP</a></h3>
<p>Java를 기본으로 한 웹 프로그래밍 언어/스크립트 언어</p>
</header>
</article>
<article>
<span class="image">
<img src="images/pic04.jpg" alt="" />
</span>
<header class="major">
<h3><a href="#" class="link">JavaScript</a></h3>
<p>HTML에 기본적인 로직을 정의할 수 있는 언어</p>
</header>
</article>
<article>
<span class="image">
<img src="images/pic05.jpg" alt="" />
</span>
<header class="major">
<h3><a href="#" class="link">MVC</a></h3>
<p>웹 프로젝트 중 가장 많이 사용하는 디자인패턴</p>
</header>
</article>
<article>
<span class="image">
<img src="images/pic06.jpg" alt="" />
</span>
<header class="major">
<h3><a href="#" class="link">Web Project</a></h3>
<p>여러분의 최종프로젝트에 웹 기술을 활용하세요!</p>
</header>
</article>
</section>
<!-- Two -->
<section id="two">
<div class="inner">
<header class="major">
<h2>나에게 온 메세지 확인하기</h2>
</header>
<p></p>
<ul class="actions">
<li>로그인을 하세요.</li>
<li><a href="#" class="button next scrolly">전체삭제하기</a></li>
</ul>
</div>
</section>
</div>
<!-- Contact -->
<section id="contact">
<div class="inner">
<section>
<form>
<div class="field half first">
<label for="name">Name</label>
<input type="text" id="name" placeholder="보내는 사람 이름" />
</div>
<div class="field half">
<label for="email">Email</label>
<input type="text" id="email" placeholder="보낼 사람 이메일"/>
</div>
<div class="field">
<label for="message">Message</label>
<textarea id="message" rows="6"></textarea>
</div>
<ul class="actions">
<li><input type="submit" value="Send Message" class="special" /></li>
<li><input type="reset" value="Clear" /></li>
</ul>
</form>
</section>
<section class="split">
<section>
<div class="contact-method">
<span class="icon alt fa-envelope"></span>
<h3>Email</h3>
<% if(vo != null) {%>
<a><%=vo.getEmail()%></a>
<%}else{%>
<a href="#">로그인 한 사람의 이메일을 출력</a>
<%} %>
<!-- 로그인 한 사용자의 이메일을 출력하시오 -->
</div>
</section>
<section>
<div class="contact-method">
<span class="icon alt fa-phone"></span>
<h3>Phone</h3>
<% if(vo != null) {%>
<a><%=vo.getPhone()%></a>
<%}else{%>
<span>로그인 한 사람의 전화번호를 출력</span>
<%} %>
<!-- 로그인 한 사용자의 전화번호를 출력하시오 -->
</div>
</section>
<section>
<div class="contact-method">
<span class="icon alt fa-home"></span>
<h3>Address</h3>
<% if(vo != null) {%>
<a><%=vo.getAddress()%></a>
<%}else{%>
<span>로그인 한 사람의 집주소를 출력</span>
<%} %>
<!-- 로그인 한 사용자의 집주소를 출력하시오 -->
</div>
</section>
</section>
</div>
</section>
<!-- Footer -->
<footer id="footer">
<div class="inner">
<ul class="icons">
<li><a href="#" class="icon alt fa-twitter"><span class="label">Twitter</span></a></li>
<li><a href="#" class="icon alt fa-facebook"><span class="label">Facebook</span></a></li>
<li><a href="#" class="icon alt fa-instagram"><span class="label">Instagram</span></a></li>
<li><a href="#" class="icon alt fa-github"><span class="label">GitHub</span></a></li>
<li><a href="#" class="icon alt fa-linkedin"><span class="label">LinkedIn</span></a></li>
</ul>
<ul class="copyright">
<li>© Untitled</li><li>Design: <a href="https://html5up.net">HTML5 UP</a></li>
</ul>
</div>
</footer>
</div>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.scrolly.min.js"></script>
<script src="assets/js/jquery.scrollex.min.js"></script>
<script src="assets/js/skel.min.js"></script>
<script src="assets/js/util.js"></script>
<!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
<script src="assets/js/main.js"></script>
</body>
</html>
<Command.java>
package com.smhrd.command;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public interface Command {
// 객체 생성해서 메소드 만드는 과정을 단순화 하기 위해서 interface생성
// 추상메소드 : 값이 없고 메소드의 기본값을 설정해줌
// 우리는 인터페이스를 상속 받아서 메소드를 강제적으로 구현할 것
// 메소드의 이름은 다 같게 만들어 오버라이딩(재정의)해서 기능 구현 할 것
public abstract String execute(HttpServletRequest request, HttpServletResponse response);
}
<FrontController.java>
package com.smhrd.frontcontroller;
import java.io.IOException;
import java.net.URLEncoder;
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 javax.servlet.http.HttpSession;
import com.oreilly.servlet.MultipartRequest;
import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;
import com.smhrd.command.Command;
import com.smhrd.controller_class.DeleteBoardService;
import com.smhrd.controller_class.DeleteService;
import com.smhrd.controller_class.JoinService;
import com.smhrd.controller_class.LoginService;
import com.smhrd.controller_class.LogoutService;
import com.smhrd.controller_class.UpdateService;
import com.smhrd.controller_class.WriteBoardService;
import com.smhrd.model.BoardDAO;
import com.smhrd.model.BoardVO;
import com.smhrd.model.DAO;
import com.smhrd.model.MemberVO;
@WebServlet("*.do") // .do라는 확장자를 갖고있다면 frontController로 오게 만드는 것.
public class Frontcontroller extends HttpServlet {
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("[Frontcontroller]");
// 어느 서블릿으로 요청이 들어왔는지 확인
String uri = request.getRequestURI();
// System.out.println(uri);
// 프로젝트 이름
String path = request.getContextPath();
// System.out.println(path);
// 요청들어온 servlet 이름만 확인
// substring : 문자열 자르는 함수
// substring(start) : start위치부터 끝까지 문자열 자르기
String reqURL = uri.substring(path.length() + 1);
System.out.println(reqURL);
request.setCharacterEncoding("UTF-8");
String moveURL = "";
// 업캐스팅
Command sc = null;
if (reqURL.equals("JoinService.do")) {
sc = new JoinService();
} else if (reqURL.equals("LoginService.do")) {
sc = new LoginService();
} else if (reqURL.equals("LogoutService.do")) {
sc = new LogoutService();
} else if (reqURL.equals("UpdateService.do")) {
sc = new UpdateService();
} else if (reqURL.equals("DeleteService.do")) {
sc = new DeleteService();
} else if (reqURL.equals("WriteBoardService.do")) {
sc = new WriteBoardService();
} else if (reqURL.equals("DeleteBoardService.do")) {
sc = new DeleteBoardService();
}
moveURL = sc.execute(request, response);
RequestDispatcher rd = request.getRequestDispatcher(moveURL);
rd.forward(request, response);
}
}
<JoinService.java>
package com.smhrd.controller_class;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.smhrd.command.Command;
import com.smhrd.model.DAO;
import com.smhrd.model.MemberVO;
public class JoinService implements Command {
public String execute(HttpServletRequest request, HttpServletResponse response) {
String email = request.getParameter("email");
String pw = request.getParameter("pw");
String phone = request.getParameter("phone");
String address = request.getParameter("address");
MemberVO vo = new MemberVO(email, pw, phone, address);
DAO dao = new DAO();
int row = dao.join(vo);
String moveURL = "";
if(row > 0) {
request.setAttribute("email", email);
moveURL = "join_success.jsp";
}else {
moveURL = "main.jsp";
}
return moveURL;
}
}
<LoginService.java>
package com.smhrd.controller_class;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.smhrd.command.Command;
import com.smhrd.model.DAO;
import com.smhrd.model.MemberVO;
public class LoginService implements Command {
@Override
public String execute(HttpServletRequest request, HttpServletResponse response) {
String email = request.getParameter("email");
String pw = request.getParameter("pw");
MemberVO vo = new MemberVO(email, pw, null, null);
DAO dao = new DAO();
MemberVO result = dao.login(vo);
if(result != null) {
HttpSession session = request.getSession();
session.setAttribute("member", result);
}
return "main.jsp";
}
}
<LogoutService.java>
package com.smhrd.controller_class;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.smhrd.command.Command;
public class LogoutService implements Command {
@Override
public String execute(HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession();
session.invalidate();
return "main.jsp";
}
}
<UpdateService.java>
package com.smhrd.controller_class;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.smhrd.command.Command;
import com.smhrd.model.DAO;
import com.smhrd.model.MemberVO;
public class UpdateService implements Command {
@Override
public String execute(HttpServletRequest request, HttpServletResponse response) {
String email= request.getParameter("email");
String pw= request.getParameter("pw");
String phone= request.getParameter("phone");
String address= request.getParameter("address");
MemberVO vo = new MemberVO(email, pw, phone, address);
DAO dao = new DAO();
int row = dao.update(vo);
if(row>0) {
System.out.println("회원정보 수정 성공");
HttpSession session = request.getSession();
session.setAttribute("member", vo);
}
return "main.jsp";
}
}
<DeleteService.java>
package com.smhrd.controller_class;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.smhrd.command.Command;
import com.smhrd.model.DAO;
public class DeleteService implements Command {
@Override
public String execute(HttpServletRequest request, HttpServletResponse response) {
String email = request.getParameter("email");
System.out.println(email);
DAO dao = new DAO();
int row = dao.delete(email);
if(row>0) {
System.out.println("회원 삭제 성공");
}
return "select.jsp";
}
}
<WriteBoardService.java>
package com.smhrd.controller_class;
import java.io.IOException;
import java.net.URLEncoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.oreilly.servlet.MultipartRequest;
import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;
import com.smhrd.command.Command;
import com.smhrd.model.BoardDAO;
import com.smhrd.model.BoardVO;
public class WriteBoardService implements Command {
@Override
public String execute(HttpServletRequest request, HttpServletResponse response) {
String file = request.getServletContext().getRealPath("file");
System.out.println(file);
int maxSize = 10*1024*1024;
String encoding = "UTF-8";
DefaultFileRenamePolicy rename = new DefaultFileRenamePolicy();
try {
MultipartRequest multi;
multi = new MultipartRequest(request, file, maxSize, encoding, rename);
String title = multi.getParameter("title");
String writer = multi.getParameter("writer");
String fileName = multi.getFilesystemName("fileName");
fileName = URLEncoder.encode(fileName, "UTF-8");
String content = multi.getParameter("content");
BoardVO vo = new BoardVO(title, writer, fileName, content);
BoardDAO dao = new BoardDAO();
int row = dao.upload(vo);
if(row > 0) {
System.out.println("업로드 성공!");
}
} catch (IOException e) {
e.printStackTrace();
}
return "boardMain.jsp";
}
}
<DeleteBoardService.java>
'Maven Project' 카테고리의 다른 글
HandlerMapping (0) | 2022.05.31 |
---|---|
게시판 FrontController-command 방식 (0) | 2022.05.30 |
MVC Framework 게시판 (0) | 2022.05.27 |
게시판 글 삭제 (0) | 2022.05.27 |
게시판 세부내용 (0) | 2022.05.27 |