웹프로그램이란 무엇인가/
한마디로 홈페이지가 연동할수있게 만들어주는것을 말한다/
홈페이지란 /
하나의 책으로 간주하면 이해하기 쉽다/
책도 한장씩 넘어가듯이 홈페이지도 로그인페이지 또는 회원가입페이지 또는 글목록을 보는 페이지로 나는것과같다 그러니 어느사이트를 즉 견적낼데 홈페이지가 어느어느 기능에따라 얼마인가고 물어본다/
그럼 우리 모두 다함께 홈페이지를 만들어 보다
우리가 여기 사이트에 처음들어오와 처음보이는것이 첫메인이다
그럼 첫메인에는 좌우에는 소메뉴 상하에도 소메뉴 그리고 중요한것이 회원로그인창이 보인다/
그럼 우리 다함께 이해하면서 여기처럼 멋진 홈페이지를 구측해보자/
------------------------------------------------------------------------------
로그인 페이지
확장자는 JSP입니다 //보안이 잘되여있으며 서버로는 톱캐과 자바로 운영됨
탈동네확장자는 ASP
새터민 확장자는 PHP
---------------------------------------------------------------
JSP 회원가입 데이터베이스 작업
----------------------------------------
1. 회원에 정보가 들어갈 테이블을 생성한다.
create table members( id varchar2(12) not null primary key, passwd varchar2(12) not null, name varchar2(10) not null, jumin1 varchar2(6) not null, jumin2 varchar2(7) not null, email varchar2(30), blog varchar2(50), reg_date date not null, zipcode varchar2(7), address varchar2(30) );
2. 우편번호 테이블을 생성한다.
create table zipcode( zipcode char(7) not null, area1 char(10) null, area2 char(20) null, area3 char(40) null, area4 char(20) null );
----------------------------------------------------------------
데이터 베이스란?
우리가 흔이 북한에서의 햑교에서 출석부란것이 있을것이다 또는 학적부가 있다/
그렇게 생각하면 된다/
즛 회원정보를 저장하는 칼럼이다
--------------------------------------
JSP 회원가입 JavaBean 생성 1
-------------------------------------
LogonDataBean.java Ex )
package fourleaf.logon;
import java.sql.Timestamp;
public class LogonDataBean { private String id; private String passwd; private String name; private String jumin1; private String jumin2; private String email; private String blog; private Timestamp reg_date; private String zipcode; private String address;
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 getJumin1() { return jumin1; } public void setJumin1(String jumin1) { this.jumin1 = jumin1; } public String getJumin2() { return jumin2; } public void setJumin2(String jumin2) { this.jumin2 = jumin2; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getBlog() { return blog; } public void setBlog(String blog) { this.blog = blog; } public Timestamp getReg_date() { return reg_date; } public void setReg_date(Timestamp reg_date) { this.reg_date = reg_date; } public String getZipcode() { return zipcode; }
public void setZipcode(String zipcode) { this.zipcode = zipcode; }
public String getAddress() { return address; }
public void setAddress(String address) { this.address = address; } }
------------------------------------------------------------------------------------------
ZipcodeBean.java Ex )
package fourleaf.logon;
public class ZipcodeBean { private String zipcode; private String area1; private String area2; private String area3; private String area4; public String getZipcode() { return zipcode; } public void setZipcode(String zipcode) { this.zipcode = zipcode; } public String getArea1() { return area1; } public void setArea1(String area1) { this.area1 = area1; } public String getArea2() { return area2; } public void setArea2(String area2) { this.area2 = area2; } public String getArea3() { return area3; } public void setArea3(String area3) { this.area3 = area3; } public String getArea4() { return area4; } public void setArea4(String area4) { this.area4 = area4; } }
---------------------------------------------
JSP 회원가입 JavaBean 생성 2
---------------------------------------------
LogonDBBean.java Ex )
package fourleaf.logon;
import java.sql.*; import java.util.Vector;
public class LogonDBBean { private static LogonDBBean instance = new LogonDBBean(); public static LogonDBBean getInstance() { return instance; } private LogonDBBean() {} private Connection getConnection() throws Exception { String jdbcDriver = "jdbc:apache:commons:dbcp:/pool"; return DriverManager.getConnection(jdbcDriver); } // 데이터 입력 메서드 public void insertMember(LogonDataBean member) throws Exception { Connection conn = null; PreparedStatement pstmt = null; try { conn = getConnection(); pstmt = conn.prepareStatement ("insert into MEMBERS values(?,?,?,?,?,?,?,?,?,?)"); pstmt.setString(1, member.getId()); pstmt.setString(2, member.getPasswd()); pstmt.setString(3, member.getName()); pstmt.setString(4, member.getJumin1()); pstmt.setString(5, member.getJumin2()); pstmt.setString(6, member.getEmail()); pstmt.setString(7, member.getBlog()); pstmt.setTimestamp(8, member.getReg_date()); pstmt.setString(9, member.getZipcode()); pstmt.setString(10, member.getAddress()); pstmt.executeUpdate(); }catch(Exception ex){ ex.printStackTrace(); }finally{ if(pstmt != null) try { pstmt.close(); } catch(SQLException ex) {} if(conn != null) try { conn.close(); } catch(SQLException ex) {} } } // 로그인 로직에서 사용할 메서드 public int userCheck(String id, String passwd) throws Exception { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; String dbpasswd = ""; int x = -1; try { conn = getConnection(); pstmt = conn.prepareStatement("select passwd from MEMBERS where id = ?"); pstmt.setString(1, id); rs = pstmt.executeQuery(); if(rs.next()) { dbpasswd = rs.getString("passwd"); if(dbpasswd.equals(passwd)) x = 1; // 인증 성공 else x = 0; // 비밀번호 틀림 } else x = -1; // 해당 아이디 없음 }catch(Exception ex){ ex.printStackTrace(); }finally{ if(rs != null) try { rs.close(); } catch(SQLException ex) {} if(pstmt != null) try { pstmt.close(); } catch(SQLException ex) {} if(conn != null) try { conn.close(); } catch(SQLException ex) {} } return x; } // 회원가입시 ID를 체크할 때 호출하는 메서드 public int confirmId(String id) throws Exception { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; int x = -1; try { conn = getConnection(); pstmt = conn.prepareStatement("select id from MEMBERS where id = ?"); pstmt.setString(1, id); rs = pstmt.executeQuery(); if(rs.next()) x = 1; // 해당 아이디 있음 else x = -1; // 해당 아이디 없음 }catch(Exception ex){ ex.printStackTrace(); }finally{ if(rs != null) try { rs.close(); } catch(SQLException ex) {} if(pstmt != null) try { pstmt.close(); } catch(SQLException ex) {} if(conn != null) try { conn.close(); } catch(SQLException ex) {} } return x; } // 업데이트시 입력된 데이터를 보여줄 때 사용하는 메서드 public LogonDataBean getMember(String id) throws Exception { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; LogonDataBean member = null; try { conn = getConnection(); pstmt = conn.prepareStatement("select * from MEMBERS where id = ?"); pstmt.setString(1, id); rs = pstmt.executeQuery(); if(rs.next()) { member = new LogonDataBean(); member.setId(rs.getString("id")); member.setPasswd(rs.getString("passwd")); member.setName(rs.getString("name")); member.setJumin1(rs.getString("jumin1")); member.setJumin2(rs.getString("jumin2")); member.setEmail(rs.getString("email")); member.setBlog(rs.getString("blog")); member.setReg_date(rs.getTimestamp("reg_date")); member.setZipcode(rs.getString("zipcode")); member.setAddress(rs.getString("address")); } }catch(Exception ex){ ex.printStackTrace(); }finally{ if(rs != null) try { rs.close(); } catch(SQLException ex) {} if(pstmt != null) try { pstmt.close(); } catch(SQLException ex) {} if(conn != null) try { conn.close(); } catch(SQLException ex) {} } return member; } // 회원정보를 수정할 때 사용하는 메서드 public void updateMember(LogonDataBean member) throws Exception { Connection conn = null; PreparedStatement pstmt = null; try { conn = getConnection(); pstmt = conn.prepareStatement ("update MEMBERS set passwd = ?, name = ?, " + "email = ?, blog = ?, zipcode = ?, address = ? where id = ?"); pstmt.setString(1, member.getPasswd()); pstmt.setString(2, member.getName()); pstmt.setString(3, member.getEmail()); pstmt.setString(4, member.getBlog()); pstmt.setString(5, member.getZipcode()); pstmt.setString(6, member.getAddress()); pstmt.setString(7, member.getId()); pstmt.executeUpdate(); }catch(Exception ex){ ex.printStackTrace(); }finally{ if(pstmt != null) try { pstmt.close(); } catch(SQLException ex) {} if(conn != null) try { conn.close(); } catch(SQLException ex) {} } } // 회원정보를 삭제할 때 사용하는 메서드 public int deleteMember(String id, String passwd) throws Exception { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; String dbpasswd = ""; int x = -1; try { conn = getConnection(); pstmt = conn.prepareStatement("select passwd from MEMBERS where id = ?"); pstmt.setString(1, id); rs = pstmt.executeQuery(); if(rs.next()) { dbpasswd = rs.getString("passwd"); if(dbpasswd.equals(passwd)) { pstmt = conn.prepareStatement("delete from MEMBERS where id = ?"); pstmt.setString(1, id); pstmt.executeUpdate(); x = 1; // 회원탈퇴 성공 } else x = 0; // 비밀번호 틀림 } }catch(Exception ex){ ex.printStackTrace(); }finally{ if(rs != null) try { rs.close(); } catch(SQLException ex) {} if(pstmt != null) try { pstmt.close(); } catch(SQLException ex) {} if(conn != null) try { conn.close(); } catch(SQLException ex) {} } return x; } // 우편번호 검색 메서드 public Vector zipcodeRead(String area3) { Connection con = null; PreparedStatement pstmt = null; ResultSet rs = null; Vector vecList = new Vector(); try { con = getConnection(); String sql = "select * from zipcode where area3 like '"+area3+"%'"; pstmt = con.prepareStatement(sql); rs = pstmt.executeQuery(); while(rs.next()) { ZipcodeBean tempZipcode = new ZipcodeBean(); tempZipcode.setZipcode(rs.getString("zipcode")); tempZipcode.setArea1(rs.getString("area1")); tempZipcode.setArea2(rs.getString("area2")); tempZipcode.setArea3(rs.getString("area3")); tempZipcode.setArea4(rs.getString("area4")); vecList.addElement(tempZipcode); } }catch(Exception ex) { System.out.println("Exception" + ex); }finally{ if (rs != null) try { rs.close(); } catch(SQLException ex) {} if (pstmt != null) try { pstmt.close(); } catch(SQLException ex) {} if (con != null) try { con.close(); } catch(SQLException ex) {} } return vecList; }
// 아이디 찾기 public LogonDataBean searchId(String name, String jumin1, String jumin2)
throws Exception { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; LogonDataBean sid = null; try { conn = getConnection(); pstmt = conn.prepareStatement("select id from MEMBERS where name = ? " + "and jumin1 =? and jumin2 = ?"); pstmt.setString(1, name); pstmt.setString(2, jumin1); pstmt.setString(3, jumin2); rs = pstmt.executeQuery(); if(rs.next()) { sid = new LogonDataBean(); sid.setId(rs.getString("id")); } }catch(Exception ex){ ex.printStackTrace(); }finally{ if(rs != null) try { rs.close(); } catch(SQLException ex) {} if(pstmt != null) try { pstmt.close(); } catch(SQLException ex) {} if(conn != null) try { conn.close(); } catch(SQLException ex) {} } return sid; } // 비밀번호 찾기 public LogonDataBean searchPw(String id, String jumin1, String jumin2) throws Exception { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; LogonDataBean spw = null; try { conn = getConnection(); pstmt = conn.prepareStatement("select passwd from MEMBERS where id = ? " + "and jumin1 =? and jumin2 = ?"); pstmt.setString(1, id); pstmt.setString(2, jumin1); pstmt.setString(3, jumin2); rs = pstmt.executeQuery(); if(rs.next()) { spw = new LogonDataBean(); spw.setPasswd(rs.getString("passwd")); } }catch(Exception ex){ ex.printStackTrace(); }finally{ if(rs != null) try { rs.close(); } catch(SQLException ex) {} if(pstmt != null) try { pstmt.close(); } catch(SQLException ex) {} if(conn != null) try { conn.close(); } catch(SQLException ex) {} } return spw; } } ===============================================
오늘은 요기까지
|