20220411 복습

2022 - 0411 - 복습

response.setContentType("text/html;charset=UTF-8");
response.getWriter().append("Served at: ").append(request.getContextPath());

[싱글톤]
ProductDAO pDao = ProductDAO.getInstance();

[연가보 (연결 > 가져오기 > 보내기)]
List<ProductVO>productList = pDao.selectAllProduct();
request.setAttribute("productList", productList);

[페이지 이동]
RequestDispatcher rd = request.getRequestDispatcher("product/productList.jsp");
rd.forward(request,response);

//doGet(request, response);
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
out.println("post 전송");

//업로드 코드
ServletContext context = getServletContext();
String path = context.getRealPath("img"); //Context로 서블릿이 이미지 실제 경로를 찾게 해줌.
String encType="UTF-8";
int sizeLimit=20*1024*1024; //20MB

MultipartRequest multi = new MultipartRequest(request, path, sizeLimit, encType, new DefaultFileRenamePolicy());

String productId = multi.getParameter("produtId");
String pname = multi.getParameter("pname");
int unitPrice = Integer.parseInt(multi.getParameter("unitPrice"));
String description = multi.getParameter("description");
String manufacturer = multi.getParameter("manufacturer");
String category = multi.getParameter("category");
int unitInStock = Integer.parseInt(multi.getParameter("unitInStock"));
String conditions = multi.getParameter("conditions");
String upfile = multi.getFilesystemName("upfile");
if(upfile == null) {
     upfile = "noImg.jpg";
}

//VO 객체
ProductVO pVO = new ProductVO();
pVO.setProductId(productId);
pVO.setPname(pname);
pVO.setUnitPrice(unitPrice);
pVO.setDescription(description);
pVO.setManufacturer(manufacturer);
pVO.setCategory(category);
pVO.setUnitInStock(unitInStock);
pVO.setConditions(conditions);
pVO.setUpfile(upfile);

     ProductDAO pDao=ProductDAO.getInstance();
     if( pDao.insertProduct() ) {
          System.out.println("등록 성공");
          //response.sendRedirect("productList.do");
     }else {
          System.out.println("등록 실패");
     }



static Connection conn = null;
static PreparedStatement pstmt = null;
static String jdbc_driver="com.mysql.cj.jdbc.Driver";
static String jdbc_url="jdbc:mysql://localhost:3306/db53";
static String id="root";
static String pw="123456";

     public static Connection connect() {
          try {
               Class.forName(jdbc_driver);
               conn = DriverManager.getConnection(jdbc_url,id,pw);
          }catch(ClassNotFoundException e){

          }catch(SQLException e) {

          }
          return conn;
     }

     public static void disconnect() {
          if(pstmt != null) {
               try {
                    pstmt.close();
               } catch (SQLException e) {
                    e.printStackTrace();
               }
          }
          if(conn != null) {
               try {
                    conn.close();
               } catch (SQLException e) {
                    e.printStackTrace();
               }
          }
     }



function checkKey(event){

     if (event.keyCode >= 48 && event.keyCode <= 57) { //숫자키만 입력
          return true;
     } else {
          event.returnValue = false;
          alert('숫자만 입력해주세요.');
     }
}

function productCheck(){

     if(document.myform.productId.value.length == 0){
          alert('상품번호를 입력해주세요.');
          myform.productId.focus();
          return false; //페이지 이동 x
     }
     if(document.myform.productId.value.length < 4 || document.myform.productId.value.length >= 5 ){
          alert('상품번호는 4자리로 입력해주세요.');
          myform.productId.focus();
          return false; //페이지 이동 x
     }
     if(document.myform.pname.value.length == 0){
          alert('상품명를 입력해주세요.');
          myform.pname.focus();
          return false; //페이지 이동 x
     }
     if(document.myform.unitPrice.value.length == 0){
          alert('상품가격을 입력해주세요.');
          myform.unitPrice.focus();
          return false; //페이지 이동 x
     }
     if( isNaN(document.myform.unitPrice.value) ){
          alert('상품가격을 숫자로 입력해주세요.');
          myform.unitPrice.focus();
          return false; //페이지 이동 x
     }
     if(document.myform.description.value.length == 0){
          alert('상품설명을 입력해주세요.');
          myform.description.focus();
          return false; //페이지 이동 x
     }
     if(document.myform.manufacturer.value.length == 0){
          alert('제조사를 입력해주세요.');
          myform.manufacturer.focus();
          return false; //페이지 이동 x
     }
     if(document.myform.category.value.length == 0){
          alert('카테고리를 입력해주세요.');
          myform.category.focus();
          return false; //페이지 이동 x
     }
     if(document.myform.unitInStock.value.length == 0){
          alert('상품수량을 입력해주세요.');
          myform.unitInStock.focus();
          return false; //페이지 이동 x
     }
     if( isNaN(document.myform.unitInStock.value) ){
          alert('상품수량을 숫자로 입력해주세요.');
          myform.unitInStock.focus();
          return false; //페이지 이동 x
     }
     if(document.myform.conditions.value.length == 0){
          alert('상품상태를 입력해주세요.');
          myform.conditions.focus();
          return false; //페이지 이동 x
     }
     if(document.myform.upfile.value.length == 0){
          alert('첨부파일을 등록해주세요.');
          myform.upfile.focus();
          return false; //페이지 이동 x
     }

     return true;
}


package com.jslhrd.minishop.dao;

import util.DBManager;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.jslhrd.minishop.dto.ProductVO;

public class ProductDAO {

     // 싱글톤 ----------------------------------------------
     private ProductDAO() {

     }

     private static ProductDAO instance = new ProductDAO();

     public static ProductDAO getInstance(){

          return instance;
     }
     // 싱글톤 ----------------------------------------------

     public List<ProductVO> selectAllProduct(){ // 데이터 select * 가져오기
          Connection conn=null;
          PreparedStatement pstmt = null;
          ResultSet rs = null;

          String sql="select * from product order by idx desc";
          List<ProductVO> list = new ArrayList<ProductVO>();
          try {
               conn = DBManager.connect();
               pstmt = conn.prepareStatement(sql);
               rs = pstmt.executeQuery();
               while(rs.next()) {
                    ProductVO pVO = new ProductVO();
                    pVO.setIdx(rs.getInt("idx"));
                    pVO.setProductId(rs.getString("productId"));
                    pVO.setPname(rs.getString("pname"));
                    pVO.setUnitPrice(rs.getInt("unitPrice"));
                    pVO.setDescription(rs.getString("description"));
                    pVO.setManufacturer(rs.getString("manufacturer"));
                    pVO.setCategory(rs.getString("category"));
                    pVO.setUnitInStock(rs.getInt("unitInStock"));
                    pVO.setConditions(rs.getString("conditions"));
                    pVO.setUpfile(rs.getString("upfile"));
                    list.add(pVO);                }
          } catch (Exception e) {
               e.printStackTrace();
          } finally {
               DBManager.disconnect();
          }

          return list;
     }

     public ProductVO getProduct(String idx){

          Connection conn=null;
          PreparedStatement pstmt = null;
          ResultSet rs = null;

          ProductVO pVO = new ProductVO();

          try {
               conn = DBManager.connect();
               pstmt = conn.prepareStatement("select * from product where idx=?");
               pstmt.setString(1, idx);
               rs = pstmt.executeQuery();
               while(rs.next()) {
                    pVO.setIdx(rs.getInt("idx"));
                    pVO.setProductId(rs.getString("productId"));
                    pVO.setPname(rs.getString("pname"));
                    pVO.setUnitPrice(rs.getInt("unitPrice"));
                    pVO.setDescription(rs.getString("description"));
                    pVO.setManufacturer(rs.getString("manufacturer"));
                    pVO.setCategory(rs.getString("category"));
                    pVO.setUnitInStock(rs.getInt("unitInStock"));
                    pVO.setConditions(rs.getString("conditions"));
                    pVO.setUpfile(rs.getString("upfile"));
               }
          } catch (Exception e) {
               e.printStackTrace();
          } finally {
               DBManager.disconnect();
          }

          return pVO;
     }

     public boolean insertProduct(ProductVO pVO){
          Connection conn=null;
          PreparedStatement pstmt = null;

          String sql="insert into product (productId,pname,unitPrice,description,manufacturer,category,unitInStock,conditions,upfile) "
                    + "values(?,?,?,?,?,?,?,?,?)";
          boolean result = false;

          try {
               conn = DBManager.connect();
               pstmt = conn.prepareStatement(sql);
               pstmt.setString(1, pVO.getProductId());
               pstmt.setString(2, pVO.getPname());
               pstmt.setInt(3, pVO.getUnitPrice());
               pstmt.setString(4, pVO.getDescription());
               pstmt.setString(5, pVO.getManufacturer());
               pstmt.setString(6, pVO.getCategory());
               pstmt.setInt(7, pVO.getUnitInStock());
               pstmt.setString(8, pVO.getConditions());
               pstmt.setString(9, pVO.getUpfile());
               pstmt.executeUpdate();
               result = true;
          } catch (Exception e) {
               e.printStackTrace();
               return result;
          } finally {
               DBManager.disconnect();
          }

          return result;
     }

     public boolean updateProduct(ProductVO pVO){

          Connection conn=null;
          PreparedStatement pstmt = null;
          ResultSet rs = null;

          boolean result = false;

          try {
               conn = DBManager.connect();
               pstmt = conn.prepareStatement("update product set"
               + " productId=?,pname=?,unitPrice=?,description=?,"
               + "manufacturer=?,category=?,unitInStock=?,conditions=?,upfile=? where idx=?");

               pstmt.setString(1, pVO.getProductId());
               pstmt.setString(2, pVO.getPname());
               pstmt.setInt(3, pVO.getUnitPrice());
               pstmt.setString(4, pVO.getDescription());
               pstmt.setString(5, pVO.getManufacturer());
               pstmt.setString(6, pVO.getCategory());
               pstmt.setInt(7, pVO.getUnitInStock());
               pstmt.setString(8, pVO.getConditions());
               pstmt.setString(9, pVO.getUpfile());
               pstmt.setInt(10, pVO.getIdx());

               pstmt.executeUpdate();
               result = true;

          } catch (Exception e) {
               e.printStackTrace();
          } finally {
               DBManager.disconnect();
          }

          return result;
     }

     public void deleteProduct(){

     }

     public void confirmID(){

     }

     public void userCheck(){

     }

}


package com.jslhrd.minishop.dao;

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

import com.jslhrd.minishop.dto.MemberVO;

import util.DBManager;

public class MemberDAO {

     // 싱글톤 시작 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     private MemberDAO() {

     }

     private static MemberDAO instance = new MemberDAO();

     public static MemberDAO getInstance() {
          return instance;
     }
     // 싱글톤 끝 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

     public int userCheck(String userid, String pwd) {

          int result= -1;
          Connection conn = null;
          PreparedStatement pstmt = null;
          ResultSet rs = null;

          try {
               conn = DBManager.connect();
               pstmt = conn.prepareStatement("select pwd from member where userid=?");
               pstmt.setString(1, userid);
               rs = pstmt.executeQuery();
               if(rs.next()) {
                    if( rs.getString("pwd")!=null && rs.getString("pwd").equals(pwd) ) {

                         result= 1;
                    }else {
                         /*
                          * 접근횟수의 임계값
                          * 1번은 틀릴 수 있다.
                          * 3번 이상은 공격으로 간주. (15분간 로그인 못함)
                          */

                         result= 0;
                    }

               }else {
                    result= -1;
               }

          } catch (Exception e) {
               e.printStackTrace();
          }finally {
               DBManager.disconnect();
          }

          return result;
     }

     public MemberVO getMember(String userid) {

          Connection conn = null;
          PreparedStatement pstmt = null;
          ResultSet rs = null;

          MemberVO mVO = new MemberVO();

          try {
               conn = DBManager.connect();
               pstmt = conn.prepareStatement("select * from member where userid=?");
               pstmt.setString(1, userid);
               rs = pstmt.executeQuery();
               rs.next();
               mVO.setName(rs.getString("name"));
               mVO.setUserid(rs.getString("userid"));
               mVO.setPwd(rs.getString("pwd"));
               mVO.setEmail(rs.getString("email"));
               mVO.setPhone(rs.getString("phone"));
               mVO.setAdmin(rs.getString("admin"));
               mVO.setAvatar(rs.getString("avatar"));
               mVO.setLast_login(rs.getString("last_login"));

          } catch (Exception e) {
               e.printStackTrace();
          }finally {
               DBManager.disconnect();
          }

          return mVO;
     }


}


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

     response.setContentType("text/html;charset=UTF-8");
     request.setCharacterEncoding("UTF-8");

     //response.getWriter().append("Served at: ").append(request.getContextPath());

     //idx값 가져오기
     String idx = request.getParameter("idx");

     ProductDAO pDAO = ProductDAO.getInstance();
     ProductVO pVO = pDAO.getProduct(idx);

     request.setAttribute("product", pVO);

     RequestDispatcher rd = request.getRequestDispatcher("product/productUpdate.jsp");
     rd.forward(request,response);
}


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

     //doGet(request, response);
     response.setContentType("text/html;charset=UTF-8");
     request.setCharacterEncoding("UTF-8");
     PrintWriter out = response.getWriter();
     out.println("doPost - 상품 수정");

     //업로드 코드
     ServletContext context = getServletContext();
     String path = context.getRealPath("img"); //Context로 서블릿이 이미지 실제 경로를 찾게 해줌.
     String encType="UTF-8";
     int sizeLimit=20*1024*1024; //20MB

     MultipartRequest multi = new MultipartRequest(request, path, sizeLimit, encType, new DefaultFileRenamePolicy());

     String idx = multi.getParameter("idx");
     String productId = multi.getParameter("productId");
     String pname = multi.getParameter("pname");
     int unitPrice = Integer.parseInt(multi.getParameter("unitPrice"));
     String description = multi.getParameter("description");
     String manufacturer = multi.getParameter("manufacturer");
     String category = multi.getParameter("category");
     int unitInStock = Integer.parseInt(multi.getParameter("unitInStock"));
     String conditions = multi.getParameter("conditions");
     String upfile = multi.getFilesystemName("upfile");
     if(upfile==null) {
          upfile = multi.getParameter("nonmakeImg");
     }

     System.out.println(productId); //Console에 찍어보기 Test (값 잘 넘어오나?)
     System.out.println(pname);
     System.out.println(unitPrice);
     System.out.println(description);
     System.out.println(manufacturer);
     System.out.println(category);
     System.out.println(unitInStock);
     System.out.println(conditions);
     System.out.println(upfile);

     //VO객체
     ProductVO pVO = new ProductVO();
     pVO.setIdx(Integer.parseInt(idx));
     pVO.setProductId(productId);
     pVO.setPname(pname);
     pVO.setUnitPrice(unitPrice);
     pVO.setDescription(description);
     pVO.setManufacturer(manufacturer);
     pVO.setCategory(category);
     pVO.setUnitInStock(unitInStock);
     pVO.setConditions(conditions);
     pVO.setUpfile(upfile);

     ProductDAO pDao=ProductDAO.getInstance(); //싱글톤
     if( pDao.updateProduct(pVO) ) {
          System.out.println("수정 성공");
          response.sendRedirect("productList.do");
     }else {
          System.out.println("수정 실패");
          response.sendRedirect("productUpdate.do?idx="+idx);
     }

}


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

     response.setContentType("text/html;charset=UTF-8");
     request.setCharacterEncoding("UTF-8");

     //response.getWriter().append("Served at: ").append(request.getContextPath());

     RequestDispatcher rd = request.getRequestDispatcher("member/login.jsp");
     rd.forward(request, response);
}


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

     //doGet(request, response);
     response.setContentType("text/html;charset=UTF-8");
     request.setCharacterEncoding("UTF-8");

     PrintWriter out = response.getWriter();
     out.println("Login doPost<br><br>");

     //로그인창에서 입력한 id,pwd 파라미터 받기
     String userid = request.getParameter("userid");
     String pwd = request.getParameter("pwd");

     out.println(" ID : "+userid);
     out.println("/ PW : "+pwd);

     //싱글톤
     MemberDAO mDao = MemberDAO.getInstance();
     int result = mDao.userCheck(userid, pwd);
     if(result == 1) {
          //세션 만들기
          MemberVO mVO = mDao.getMember(userid);
          HttpSession session = request.getSession();
          session.setAttribute("loginUser", mVO);
          session.setAttribute("message", "로그인 성공");

          //projectList.do로 페이지 이동
          response.sendRedirect("/DWP_0405_03/productList.do");
          /*RequestDispatcher rd = request.getRequestDispatcher("productList.do");
          rd.forward(request,response);*/
     } else if(result==0) {
          HttpSession session = request.getSession();
          session.setAttribute("message", "비밀번호가 옳바르지 않습니다.");
          //response.sendRedirect("/DWP_0405_03/login.do");
     } else {
          response.sendRedirect("/DWP_0405_03/login.do");
     }

}


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

     response.setContentType("text/html;charset=UTF-8");
     request.setCharacterEncoding("UTF-8");

     //response.getWriter().append("Served at: ").append(request.getContextPath());
     //교제 p.506
     HttpSession session = request.getSession();
     session.invalidate();

     //세션 파괴 후 이동
     response.sendRedirect("/DWP_0405_03/member/login.jsp");
     //RequestDispatcher rd = request.getRequestDispatcher("/DWP_0405_03/member/login.jsp");
     //rd.forward(request,response);

}


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

     response.setContentType("text/html;charset=UTF-8");
     request.setCharacterEncoding("UTF-8");

     //response.getWriter().append("Served at: ").append(request.getContextPath());

     RequestDispatcher rd = request.getRequestDispatcher("member/join.jsp");
     rd.forward(request, response);
}


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

     //doGet(request, response);

     response.setContentType("text/html;charset=UTF-8");
     request.setCharacterEncoding("UTF-8");

     PrintWriter out = response.getWriter();
     out.println("Join doPost<br><br>");

     //회원가입창에서 입력한 name,userid,pwd,email,phone 파라미터 받기
     String name = request.getParameter("name");
     String userid = request.getParameter("userid");
     String pwd = request.getParameter("pwd");
     String email = request.getParameter("email");
     String phone = request.getParameter("phone");

     out.println(" ID : "+userid);
     out.println(" / PW : "+pwd+"<br>");
     out.println("name : "+name+"<br>");
     out.println("email : "+email+"<br>");
     out.println("phone : "+phone+"<br>");
}


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

     response.setContentType("text/html;charset=UTF-8");
     request.setCharacterEncoding("UTF-8");
     //response.getWriter().append("Served at: ").append(request.getContextPath());

     String command = request.getParameter("command");

     //싱글톤
     ActionFactory af = ActionFactory.getInstance();
     Action action = af.getAction(command); // p.637 select,update,delete,insert

     if(action != null) {
          action.execute(request, response);
     }

}


package com.jslhrd.minishop.controller;

import com.jslhrd.minishop.controller.action.Action;
import com.jslhrd.minishop.controller.action.BoardCheckPassAction;
import com.jslhrd.minishop.controller.action.BoardCheckPassFormAction;
import com.jslhrd.minishop.controller.action.BoardDeleteAction;
import com.jslhrd.minishop.controller.action.BoardListAction;
import com.jslhrd.minishop.controller.action.BoardUpdateAction;
import com.jslhrd.minishop.controller.action.BoardUpdateFormAction;
import com.jslhrd.minishop.controller.action.BoardViewAction;
import com.jslhrd.minishop.controller.action.BoardWriteAction;
import com.jslhrd.minishop.controller.action.BoardWriteFormAction;

public class ActionFactory {

     //싱글톤
     private static ActionFactory instance = new ActionFactory();
     
     public ActionFactory() {
          super();
     }
     
     public static ActionFactory getInstance() {
          
          return instance;
     }
     //싱글톤 끝
     
     //p.640
     public Action getAction(String command) {

          Action action = null;
          
          switch(command) {
          
               case "board_list" :
                    action = new BoardListAction();
                    break;

               case "board_write_form" :
                    action = new BoardWriteFormAction();
                    break;

               case "board_write" :
                    action = new BoardWriteAction();
                    break;

               case "board_view" :
                    action = new BoardViewAction();
                    break;

               case "board_check_pass_form" :
                    action = new BoardCheckPassFormAction();
                    break;

               case "board_check_pass" :
                    action = new BoardCheckPassAction();
                    break;

               case "board_update_form" :
                    action = new BoardUpdateFormAction();
                    break;

               case "board_update" :
                    action = new BoardUpdateAction();
                    break;

               case "board_delete" :
                    action = new BoardDeleteAction();
                    break;

               default :
                    break;
          }

          return action;
     }

}


package com.jslhrd.minishop.controller.action;

import java.io.IOException;

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

public interface Action {

     public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException;


}


package com.jslhrd.minishop.controller.action;

import java.io.IOException;

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

public class BoardListAction implements Action{

     @Override
     public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{

          System.out.println("^^");
          RequestDispatcher rd = request.getRequestDispatcher("/board/boardList.jsp");
          rd.forward(request, response);
     }

}


< 서블릿 기초 >

Servlet이 컨트롤러 역할을 한다.
URL Mappings에서 서블릿 이름 수정 가능.
(보통 서블릿의 이름을 노출시키지 않는다)

- 인코딩 & out

PrintWriter out = response.getWriter();
out.println("jsp와 달리 객체를 생성해서 사용해야함.");

response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");

- MultipartRequest

ServletContext context = getServletContext();
String path = context.getRealPath("img"); //실제경로 찾기
String encType="UTF-8";
int sizeLimit=20*1024*1024; //20MB

MultipartRequest multi = new MultipartRequest(request, path, sizeLimit, encType, new DefaultFileRenamePolicy());
String productId = multi.getParameter("productId");
String pname = multi.getParameter("pname"); //업로드를 포함해서 전달 받을 때는 request.getParameter로 못 받는다 !

- JSTL(Jsp Standard Tag Library)

main -> webapp -> WEB-INF -> lib 폴더 안에
cos.jar / jstl.jar / standard.jar 넣어주기

     <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
     <c:forEach var="product" items="${productList}">
          ${product.idx }
     </c:forEach>
(for반복문을 태그로 사용. 향상된 for문 X )

     <c:if test="${empty loginUser}">
          <jsp:forward page='/login.do'/>
     </c:if>
(loginUser라는 세션이 없을 때, 페이지 이동)

- 기타 코드

<a href="/DWP_0405_03/productWrite.do">상품 등록</a> --- 링크
<img src=./img/ style="width:100px;height:100px;"></img> --- 이미지
<form method="post" name="myform" enctype="multipart/form-data"> --- 업로드 폼
</form>
<label for="formGroupExampleInput" class="form-label">상품번호</label> --- LABEL
<input type="text" class="form-control" id="productId" name="productId"> --- input TEXT
<button class="btn btn-success" type="submit" onclick="return productCheck()">등록</button> --- 버튼(유효성)
<button class="btn btn-danger" type="reset" >리셋</button> --- 버튼(리셋)
<button class="btn btn-dark" type="button" onclick="location.href='productList.do'">목록</button> --- 버튼(링크)

HttpSession session = request.getSession(); --- 세션 생성
session.setAttribute("loginUser", mVO);
session.setAttribute("message", "로그인 성공");
session.invalidate(); --- 모든 세션 파괴



패키지 클래스 설명


com.jslhrd.minishop.controller

ProductListServlet.java
ProductWriteServlet.java
ProductUpdateServlet.java
ProductDeleteServlet.java
(ctl.jsp역할의 컨트롤러)
- URL Mapping -
productList.do
productWrite.do
productUpdate.do
productDelete.do


com.jslhrd.member.controller

LoginServlet.java
JoinServlet.java
LogoutServlet.java
MemberUpdateServlet.java
(ctl.jsp역할의 컨트롤러)
- URL Mapping -
login.do
join.do
logout.do
memberUpdate.do
com.jslhrd.minishop.DAO ProductDAO.java
MemberDAO.java
(조회,추가,갱신,삭제 등)
(로그인, 중복확인 등)





com.jslhrd.minishop.DTO
ProductVO.java
(상품 정보 저장)
private int idx;
private String productId;
private String pname;
private int unitPrice;
private String description;
private String manufacturer;
private String category;
private int unitInStock;
private String conditions;
private String upfile;
MemberVO.java
(회원 정보 저장)
private int idx;
private String name;
private String userid;
private String pwd;
private String email;
private String phone;
private String admin;
// 교과서에 없지만 추가.
private String avatar;
private String last_login;
private int failed_login;
util DBManager.java
(DB연결/ 연결해제)

Webapp / product

Webapp / member
product 폴더

productList.jsp
productWrite.jsp
productUpdate.jsp
productDelete.jsp
member 폴더

login.jsp
join.jsp
main.jsp
memberUpdate.jsp


Webapp / script

Webapp / css


product.js
member.js
shopping.css
(스크립트 사용)
유효성 검사.
onKeyPress=""
alert('');
event.keyCord
isNaN();

(css로 스타일 꾸미기)

Board
패키지 클래스 설명
com.jslhrd.minishop.controller ActionFactory.java
BoardServlet.java
-> Action인터페이스 + 자식클래스 연결
-> command 받아 af(ActionFactory) 실행




com.jslhrd.minishop.controller.action
Action.java
BoardListAction.java
BoardWriteFormAction.java
BoardWriteAction.java
BoardViewAction.java
BoardCheckPassFormAction.java
BoardCheckPassAction.java
BoardUpdateFormAction.java
BoardUpdateAction.java
BoardDeleteAction.java
-> 슈퍼클래스로 사용할 인터페이스
-> 게시글 전체 정보 얻어오기
-> 새로운 게시글 작성페이지 이동
-> 입력한 게시글을 DB에 입력
-> 번호에 해당하는 글의 상세정보
-> 수정 권한을 확인하는 페이지
-> 게시글 비밀번호의 일치 비교
-> 게시글 수정페이지로 이동
-> 수정한 정보로 DB내용 수정
-> DB의 해당 게시글을 삭제