webappํด๋ mainํด๋ ์์ฑ
main_page ์์ฑ
webappํด๋ memberํด๋ ์์ฑ
member_join.jsp ์์ฑ
member_login.jsp ์์ฑ
webappํด๋ productํด๋ ์์ฑ
product_list.jsp
webappํด๋ cartํด๋ ์์ฑ
cart_list.jsp
webappํด๋ orderํด๋ ์์ฑ
order_list.jsp
webappํด๋ boardํด๋ ์์ฑ
board_list.jsp
================================================
โ SQL Delope ์คํ
create table member(id varchar(20) primary key ,passwd varchar2(200),name varchar2(20),email varchar2(30) ,mobile varchar2(20),zipcode varchar2(10) ,address1 varchar(200), address2 varchar(50) ,join_data date,last_login date,status number(1));
โ xyz.itwill.dto ํจํค์ง์ MemberDTO ํด๋์ค ์์ฑ
๐MemberDTO.java
package xyz.itwill.dto; // /* ์ด๋ฆ ๋? ์ ํ ---------- -------- ------------- ID NOT NULL VARCHAR2(20) - ์์ด๋ PASSWD VARCHAR2(200) - ๋น๋ฐ๋ฒํธ NAME VARCHAR2(20) - ์ด๋ฆ EMAIL VARCHAR2(30) - ์ด๋ฉ์ผ MOBILE VARCHAR2(20) - ์ ํ๋ฒํธ ZIPCODE VARCHAR2(10) - ์ฐํธ๋ฒํธ ADDRESS1 VARCHAR2(200) - ๊ธฐ๋ณธ์ฃผ์ ADDRESS2 VARCHAR2(50) - ์์ธ์ฃผ์ JOIN_DATA DATE - ํ์๊ฐ์ ๋ ์ง LAST_LOGIN DATE - ๋ง์ง๋ง ๋ก๊ทธ์ธ ๋ ์ง STATUS NUMBER(1) - ํ์์ํ : 0(ํํดํ์), 1(์ผ๋ฐํ์), 9(๊ด๋ฆฌ์) */ // public class MemberDTO { private String id; private String passwd; private String name; private String email; private String mobile; private String zipcode; private String address1; private String address2; private String joinDate; private String lastLogin; private int status; // public MemberDTO() { // TODO Auto-generated constructor stub } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getPasswd() { return passwd; } public void setPasswd(String passwd) { this.passwd = passwd; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getMobile() { return mobile; } public void setMobile(String mobile) { this.mobile = mobile; } public String getZipcode() { return zipcode; } public void setZipcode(String zipcode) { this.zipcode = zipcode; } public String getAddress1() { return address1; } public void setAddress1(String address1) { this.address1 = address1; } public String getAddress2() { return address2; } public void setAddress2(String address2) { this.address2 = address2; } public String getJoinDate() { return joinDate; } public void setJoinDate(String joinDate) { this.joinDate = joinDate; } public String getLastLogin() { return lastLogin; } public void setLastLogin(String lastLogin) { this.lastLogin = lastLogin; } public int getStatus() { return status; } public void setStatus(int status) { this.status = status; } }
โ xyz.itwill.dao ํจํค์ง์ MemberDAO ํด๋์ค ์์ฑ
๐MemberDAO.java
์ฝ๋๋ฅผ ์ ๋ ฅํ์ธ์
================================================
ํ์๊ฐ์
๊ด๋ จ
1. member_join.jsp ์์
2. member_join_action.jsp ์์ฑ ๋ฐ ์์ฑ
================================================
1. xyz.itwill.util ํจํค์ง ์์ฑ
2. Uitility ํด๋์ค ์์ฑ
์ํธํ ์ฒ๋ฆฌ ์ ์๋ ๊ฐ์ธ์ ๋ณด๊ฐ ์ ๋ถ ํ์๋จ
โปtruncate table member;(ํ ์ด๋ธ ์ด๊ธฐํ ๋ช ๋ น์ด)
์ํธํ ์ฒ๋ฆฌ ํ
๐Uitility.java
package xyz.itwill.util; // import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; // //์นํ๋ก๊ทธ๋จ ์์ฑ์ ํ์ํ ๋ถ๊ฐ์ ์ธ ๊ธฐ๋ฅ์ ์ ๊ณตํ๊ธฐ ์ํ ํด๋์ค public class Utility { //๋ฌธ์์ด์ ์ ๋ฌ๋ฐ์ ์ํธํ ์ฒ๋ฆฌํ์ฌ ๋ฐํํ๋ ๋ฉ์๋ public static String encrypt(String source) { //์ํธํ ์ฒ๋ฆฌ๋ ๋ฌธ์์ด์ ์ ์ฅํ๊ธฐ ์ํ ๋ณ์ ์ ์ธ String password=""; try { //MessageDigest ๊ฐ์ฒด : ์ํธํ ์ฒ๋ฆฌ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ ๊ฐ์ฒด //MessageDigest.getInstance(String algorithm) : ๋งค๊ฐ๋ณ์์ ์ ์ฅ๋ ์ํธํ ์๊ณ ๋ฆฌ์ฆ์ด ์ ์ฅ๋ MessageDigest ๊ฐ์ฒด๋ฅผ ์์ฑํ์ฌ ๋ฐํํ๋ ๋ฉ์๋ //โ ๋งค๊ฐ๋ณ์์ ์๋ชป๋ ์ํธํ ์๊ณ ๋ฆฌ์ฆ์ ์ ๋ฌํ ๊ฒฝ์ฐ NoSuchAlgorithmException ๋ฐ์ //๋จ๋ฐฉํฅ ์ํธํ ์๊ณ ๋ฆฌ์ฆ : MD5, SHA-1, SHA-256(๊ถ์ฅ), SHA-512 ๋ฑ //์๋ฐฉํฅ ์ํธํ ์๊ณ ๋ฆฌ์ฆ : AES-123, RSA ๋ฑ MessageDigest messageDigest=MessageDigest.getInstance("SHA-256"); // //MessageDigest.update(byte[] input) : MessageDigest ๊ฐ์ฒด์ ์ํธํ ์ฒ๋ฆฌํ๊ธฐ ์ํ ๊ฐ(byte ๋ฐฐ์ด)์ ์ ๋ฌ๋ฐ์ ์ ์ฅํ๊ธฐ ์ํ ๋ฉ์๋ //String.getBytes() : String ๊ฐ์ฒด์ ์ ์ฅ๋ ๋ฌธ์์ด์ ์์๋ฐ์ดํฐ(byte ๋ฐฐ์ด)๋ก ๋ณํํ์ฌ ๋ฐํํ๋ ๋ฉ์๋ messageDigest.update(source.getBytes()); // //MessageDigest.digest() : MessageDigest ๊ฐ์ฒด์ ์ ์ฅ๋ ์ํธํ ์๊ณ ๋ฆฌ์ฆ์ผ๋ก ์์๋ฐ์ดํฐ๋ฅผ ์ํธํ ์ฒ๋ฆฌํ์ฌ byte ๋ฐฐ์ด๋ก ๋ฐํํ๋ ๋ฉ์๋ byte[] digest=messageDigest.digest(); // //์ํธํ ์ฒ๋ฆฌ๋ byte ๋ฐฐ์ด์ ๋ฌธ์์ด(String ๊ฐ์ฒด)๋ก ๋ณํํ์ฌ ์ ์ฅ for(int i=0;i<digest.length;i++) { //Integer.toHexString(int i) : ์ ์๊ฐ์ ์ ๋ฌ๋ฐ์ 16์ง์์ ๋ฌธ์์ด๋ก ๋ณํํ์ฌ ๋ฐํํ๋ ๋ฉ์๋ password+=Integer.toHexString(digest[i]&0xff); } } catch (NoSuchAlgorithmException e) { System.out.println("[์๋ฌ]์๋ชป๋ ์ํธํ ์๊ณ ๋ฆฌ์ฆ์ ์ฌ์ฉํ์์ต๋๋ค."); } return password; } }
================================================
1. member_join.jsp์ ์ฃผ์๋ฌธ ์ฃผ์ ํด์ ๋ฐ ์ฝ๋ ์์ฑ
2. member ํด๋์ id_check.jsp ํ์ผ ์์ฑ ๋ฐ ์์ฑ๐id_check.jsp
<%@page import="xyz.itwill.dao.MemberDAO"%> <%@page import="xyz.itwill.dto.MemberDTO"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%-- ์์ด๋ ์ ๋ฌ๋ฐ์ MEMBER ํ ์ด๋ธ์ ์ ์ฅ๋ ๊ธฐ์กด ํ์์ ๋ณด์ ์์ด๋์ ๋น๊ตํ์ฌ ์ค๋ณต ์ ๋ฌด๋ฅผ ํด๋ผ์ด์ธํธ์๊ฒ ์ ๋ฌํ๋ JSP ๋ฌธ์ --%> <%-- โ ์์ด๋ ๋ฏธ์ค๋ณต : ์์ด๋ ์ฌ์ฉ ๊ฐ๋ฅ ๋ฉ์ธ์ง - [์์ด๋ ์ฌ์ฉ]์ ํด๋ฆญํ ๊ฒฝ์ฐ ๋ถ๋ชจ์ฐฝ์ ์ ๋ ฅํ๊ทธ์ ์ ๋ ฅ๊ฐ ๋ณ๊ฒฝ --%> <%-- โ ์์ด๋ ์ค๋ณต : ์์ด๋ ์ฌ์ฉ ๋ถ๊ฐ๋ฅ ๋ฉ์ธ์ง - ์์ด๋๋ฅผ ์ ๋ ฅ๋ฐ์ ํ์ฌ JSP ๋ฌธ์๋ฅผ ์ฌ์์ฒญ --%> <% //๋น์ ์์ ์ธ ์์ฒญ์ ๋ํ ์๋ต ์ฒ๋ฆฌ if(request.getParameter("id")==null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } //์ ๋ฌ๊ฐ์ ๋ฐํ๋ฐ์ ์ ์ฅ String id=request.getParameter("id"); // //์์ด๋๋ฅผ ์ ๋ฌ๋ฐ์ MEMBER ํ ์ด๋ธ์ ์ ์ฅ๋ ํด๋น ์์ด๋์ ํ์์ ๋ณด๋ฅผ ๊ฒ์ํ์ฌ ๋ฐํํ๋ DAO ํด๋์ค์ ๋ฉ์๋ ํธ์ถ //โ null ๋ฐํ : ์ ๋ฌ๋ฐ์ ์์ด๋์ ํ์์ ๋ณด๊ฐ ๋ฏธ๊ฒ์ - ์์ด๋ ๋ฏธ์ค๋ณต(์์ด๋ ์ฌ์ฉ ๊ฐ๋ฅ) //โ MemberDTO ๊ฐ์ฒด ๋ฐํ : ์ ๋ฌ๋ฐ์ ์์ด๋์ ํ์์ ๋ณด ๊ฒ์ - ์์ด๋ ์ค๋ณต(์์ด๋ ์ฌ์ฉ ๋ถ๊ฐ๋ฅ) MemberDTO member=MemberDAO.getDAO().selectMember(id); %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <style type="text/css"> div { text-align: center; margin: 10px } .id { font-weight: bold; color: red; } </style> </head> <body> <% if(member==null) {//์ ๋ฌ๋ฐ์ ์์ด๋๊ฐ ์ค๋ณต๋์ง ์์ ๊ฒฝ์ฐ %> <div>์ ๋ ฅ๋ <span class="id">[<%=id %>]</span>๋ ์ฌ์ฉ ๊ฐ๋ฅํ ์์ด๋์ ๋๋ค.</div> <div> <button type="button" onclick="selectId();">์์ด๋ ์ฌ์ฉ</button> </div> // <script type="text/javascript"> function selectId() { //opener : ํ์ ์ฐฝ์ ์คํํ ๋ถ๋ชจ์ฐฝ์ ํํํ๋ ์๋ฐ์คํฌ๋ฆฝํธ ๊ฐ์ฒด opener.join.id.value="<%=id%>";//์ ๋ ฅํ๊ทธ(์์ด๋)์ ์ ๋ ฅ๊ฐ ๋ณ๊ฒฝ opener.join.idCheckResult.value="1";//์ ๋ ฅํ๊ทธ(๊ฒ์ฌ๊ฒฐ๊ณผ)์ ์ ๋ ฅ๊ฐ ๋ณ๊ฒฝ window.close();//์ฐฝ๋ซ๊ธฐ - ํ์ ์ฐฝ ์ข ๋ฃ } </script> <% } else {//์ ๋ฌ๋ฐ์ ์์ด๋๊ฐ ์ค๋ณต๋ ๊ฒฝ์ฐ %> <div>์ ๋ ฅ๋ <span class="id">[<%=id %>]</span>๋ ์ด๋ฏธ ์ฌ์ฉ์ค์ธ ์์ด๋์ ๋๋ค. <br>๋ค๋ฅธ ์์ด๋๋ฅผ ์ ๋ ฅํ๊ณ [ํ์ธ] ๋ฒํผ์ ๋๋ฌ์ฃผ์ธ์.</div> <div> <%-- form ํ๊ทธ์ action ์์ฑ์ด ์๋ต๋ ๊ฒฝ์ฐ ํ์ฌ ์์ฒญ JSP ๋ฌธ์๋ฅผ ์ฌ์์ฒญ --%> <%-- form ํ๊ทธ์ method ์์ฑ์ด ์๋ต๋ ๊ฒฝ์ฐ [GET] ๋ฐฉ์์ผ๋ก ์์ฒญ --%> <form name="checkForm"> <input type="text" name="id"> <button type="button" onclick="idCheck();">ํ์ธ</button> </form> </div> <div id="message" style="color: red;"></div> <script type="text/javascript"> function idCheck() { var id=checkForm.id.value; if(id=="") { document.getElementById("message").innerHTML="์์ด๋๋ฅผ ์ ๋ ฅํด ์ฃผ์ธ์."; return; } // var idReg=/^[a-zA-Z]\w{5,19}$/g; if(!idReg.test(id)) { document.getElementById("message").innerHTML="์์ด๋๋ฅผ ํ์์ ๋ง๊ฒ ์ ๋ ฅํด ์ฃผ์ธ์."; return; } // checkForm.submit(); } </script> <% } %> </body> </html>
================================================
1. member_join.jsp ์ฝ๋ ์์
2. member ํด๋์ post_search.jsp ์์ฑ ๋ฐ ์์ฑ๐post_search.jsp
<%@page import="java.util.ArrayList"%> <%@page import="xyz.itwill.dao.ZipDAO"%> <%@page import="xyz.itwill.dto.ZipDTO"%> <%@page import="java.util.List"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%-- ์ฌ์ฉ์๋ก๋ถํฐ ๋์ด๋ฆ์ ์ ๋ ฅ๋ฐ์ ZIP ํ ์ด๋ธ์ ์ ์ฅ๋ ํด๋น ๋์ด๋ฆ์ด ํฌํจ๋ ์ฐํธ๋ฒํธ ๊ด๋ จ ์ ๋ณด๋ฅผ ๊ฒ์ํ์ฌ ํด๋ผ์ด์ธํธ์๊ฒ ์ ๋ฌํ๋ JSP ๋ฌธ์ --%> <%-- โ [๊ธฐ๋ณธ์ฃผ์]๋ฅผ ํด๋ฆญํ ๊ฒฝ์ฐ ๋ถ๋ชจ์ฐฝ์ ์ ๋ ฅํ๊ทธ(์ฐํธ๋ฒํธ,๊ธฐ๋ณธ์ฃผ์)์ ์ ๋ ฅ๊ฐ ๋ณ๊ฒฝ --%> <% //์ ๋ฌ๊ฐ์ ๋ฐํ๋ฐ์ ์ ์ฅ String dong=request.getParameter("dong"); // //๋์ด๋ฆ์ ์ ๋ฌ๋ฐ์ ZIP ํ ์ด๋ธ์์ ํด๋น ๋์ด๋ฆ์ผ๋ก ์์๋๋ ์ฐํธ๋ฒํธ ๊ด๋ จ ์ ๋ณด๋ฅผ ๊ฒ์ํ์ฌ ๋ฐํํ๋ DAO ํด๋์ค์ ๋ฉ์๋ ํธ์ถ List<ZipDTO> zipList=new ArrayList<ZipDTO>(); if(dong!=null) {//์ ๋ฌ๊ฐ์ด ์๋ ๊ฒฝ์ฐ zipList=ZipDAO.getDAO().selectZipList(dong); } %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>JSP</title> <style type="text/css"> #search { width: 550px; margin: 0 auto; text-align: center; } table { border: 1px solid black; border-collapse: collapse; margin: 10px; font-size: 14px; } td { border: 1px solid black; text-align: center; } .zipcode { width: 100px; } .address { width: 400px; text-align: left; padding: 2px; } </style> </head> <body> <div id="search"> <form name="postForm"> ๋์ด๋ฆ : <input type="text" name="dong"> <button type="button" id="searchBtn">์ฃผ์๊ฒ์</button> </form> </div> <%-- ๊ฒ์๋ ์ฐํธ๋ฒํธ ๊ด๋ จ ์ ๋ณด๋ฅผ ํด๋ผ์ด์ธํธ์๊ฒ ์ ๋ฌ --%> <% if(!zipList.isEmpty()) { //๊ฒ์๋ ์ฐํธ๋ฒํธ ๊ด๋ จ ์ ๋ณด๊ฐ ์๋ ๊ฒฝ์ฐ%> <table> <tr> <td class="zipcode">์ฐํธ๋ฒํธ</td> <td class="address" style="text-align: center;">๊ธฐ๋ณธ์ฃผ์</td> </tr> <% for(ZipDTO zip:zipList) { %> <tr> <td class="zipcode"><%=zip.getZipcode() %></td> <%-- a ํ๊ทธ๋ฅผ ์ด์ฉํ์ฌ ์๋ฐ์คํฌ๋ฆฝํธ ๋ช ๋ น์ ์์ฑํ ๊ฒฝ์ฐ ๋ฐ๋์ javascript ์ ๋์ฌ๋ฅผ ์ฌ์ฉํด์ผ๋ง ์คํ ๊ฐ๋ฅ --%> <td class="address"> <a href="javascript:searchPost('<%=zip.getZipcode()%>','<%=zip.getAddress()%>');"><%=zip.getAddress() %> </td> </tr> <% } %> </table> <% } %> <script type="text/javascript"> postForm.dong.focus(); // document.getElementById("searchBtn").onclick=function() { if(postForm.dong.value=="") { postForm.dong.focus(); return; } // postForm.submit(); } function searchPost(code, addr) { opener.join.zipcode.value=code; opener.join.address1.value=addr; window.close(); } </script> </body> </html>
๐จ๋ฐฉ๋ฒ1)
โ ๊ณต๊ณต๋ฐ์ดํฐ ์ ์ฉ๋ฒ ํ ์ด๋ธ์ ์ฝ์ ,์ ์ฅํ๋๋ฒ
1.csv ํ์ผ ๋ค์ด๋ก๋(๊ฐ์ฌ๋ ํ์ผ ์ฐธ๊ณ )
2. SQL Delope์ ํ ์ด๋ธ ์์ฑcreate table zipcode(zipcode varchar2(40),sido varchar2(46) ,gugun varchar2(40),dong varchar2(40),ri varchar2(45) ,bldg varchar2(70),bunji varchar2(20),seq varchar2(15));
3. ๋ค์ด๋ก๋ ๋ฐ์ csv ํ์ผ ๋ฐ์ดํฐ ์ํฌํธ
4. SQL Develope ์๋์ฝ๋ ์์ฑcreate table zip(zipcode, dong, address) as select zipcode,DONG,SIDO||' '||GUGUN||' '||DONG||' '||RI||' '||BLDG||' '||BUNJI from zipcode;
5. SQL Develop ์๋์ฝ๋ ์์ฑdrop table zipcode purge;
6. ๋์ํ์ธ
7. DTO ๋ง๋ค๊ธฐ
1. xyz.itwill.dto ํจํค์ง์ ZipDTO ํด๋์ค ์์ฑ๐ZipDTO.java
package xyz.itwill.dto; // public class ZipDTO { private String zipcode; private String dong; private String address; // public ZipDTO() { // TODO Auto-generated constructor stub } public String getZipcode() { return zipcode; } public void setZipcode(String zipcode) { this.zipcode = zipcode; } public String getDong() { return dong; } public void setDong(String dong) { this.dong = dong; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } }
8. DAO ๋ง๋ค๊ธฐ
1. xyz.itwill.dao ํจํค์ง์ ZipDAO ํด๋์ค ์์ฑ๐ZipDAO.java
package xyz.itwill.dao; // import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; // import xyz.itwill.dto.ZipDTO; // public class ZipDAO extends JdbcDAO { private static ZipDAO _dao; // private ZipDAO() { // TODO Auto-generated constructor stub } // static { _dao=new ZipDAO(); } // public static ZipDAO getDAO() { return _dao; } // //๋์ด๋ฆ์ ์ ๋ฌ๋ฐ์ ZIP ํ ์ด๋ธ์์ ํด๋น ๋์ด๋ฆ์ผ๋ก ์์๋๋ ์ฐํธ๋ฒํธ ๊ด๋ จ ์ ๋ณด๋ฅผ ๊ฒ์ํ์ฌ ๋ฐํํ๋ ๋ฉ์๋ public List<ZipDTO> selectZipList(String dong) { Connection con=null; PreparedStatement pstmt=null; ResultSet rs=null; List<ZipDTO> zipList=new ArrayList<>(); try { con=getConnection(); // String sql="select * from zip where dong like ?||'%' order by zipcode"; pstmt=con.prepareStatement(sql); pstmt.setString(1, dong); // rs=pstmt.executeQuery(); // while(rs.next()) { ZipDTO zip=new ZipDTO(); zip.setZipcode(rs.getString("zipcode")); zip.setDong(rs.getString("dong")); zip.setAddress(rs.getString("address")); zipList.add(zip); } } catch (SQLException e) { System.out.println("[์๋ฌ]selectZipList() ๋ฉ์๋์ SQL ์ค๋ฅ = "+e.getMessage()); } finally { close(con, pstmt, rs); } return zipList; } }
๐จ๋ฐฉ๋ฒ2)
๋ค์์์ ์ ๊ณตํ๋ ์ฐํธ๋ฒํธ ๊ฒ์ ๊ธฐ๋ฅ(๊ถ์ฅ)
1. ์ฌ์ดํธ ์ ์
2. ์๋์ฝ๋ Member_join.jsp์ ๋ณต์ฌ ๋ถ์ฌ๋ฃ๊ธฐ<script src="//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"></script> <script> $("#postSearch").click(function() { new daum.Postcode({ oncomplete: function(data) { $("#zipcode").val(data.zonecode); $("#address1").val(data.address); } }).open(); }); </script>