---- login.html --------
로고인화면
ID : [ ]
암호 : [ ]
[로고인] [취소]
-등록을 하신후 사용가능
-사용자계정삭제
-등록된 사용자 모두보기
-----------------------
---- loginCheck.jsp----------
[id존재].................no-에러
Y :
[비밀번호일치]........no-에러
Y :
[welcome.jsp이동]
----------------------------
--- registration.html---------
사용자등록화면
이름 : [ ] ///name
ID : [ ] ///id
E - mail : [ ] ///email
암 호: [ ] ///pass1
암호확인: [ ] ///pass2
드디어완성 Login 2004 12 03 아휴
▩ jsp로 로그인 작성하기 - 아휴 드디어완성 **************** 남이 방명록완성할 때, 겨우 로고인을 완성하였도다 아휴~
▶MYsql에서 테입블명보기 -user 테이블명--------------- Microsoft Windows 2000 [Version 5.00.2195] (C) Copyright 1985-2000 Microsoft Corp.
C:\Documents and Settings\Administrator>mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 to server version: 4.0.22-nt
Type help; or \h for help. Type \c to clear the buffer.
mysql> exit Bye
C:\Documents and Settings\Administrator> C:\Documents and Settings\Administrator>cd mysql -u root 지정된 경로를 찾을 수 없습니다.
C:\Documents and Settings\Administrator>cd mysql -u root -p 지정된 경로를 찾을 수 없습니다.
C:\Documents and Settings\Administrator>cd ..
C:\Documents and Settings>cd ..
C:\>cd \mysql -u root -p 지정된 경로를 찾을 수 없습니다.
C:\>cd \mysql\bin
C:\mysql\bin>mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 43 to server version: 4.0.22-nt
Type help; or \h for help. Type \c to clear the buffer.
mysql> use mysql Database changed mysql> show tables; +-----------------+ | Tables_in_mysql | +-----------------+ | bbs | | bbs1 | | bbs2 | | columns_priv | | customer | | db | | func | | host | | orders | | procuct | | settest | | tables_priv | | test5 | | test6 | | test7 | | test8 | | ttt | | user | +-----------------+ 18 rows in set (0.04 sec)
mysql> use JspTestDB; Database changed mysql> \s -------------- mysql Ver 12.22 Distrib 4.0.22, for Win95/Win98 (i32)
Connection id: 43 Current database: jsptestdb Current user: root@localhost SSL: Not in use Server version: 4.0.22-nt Protocol version: 10 Connection: localhost via TCP/IP Client characterset: latin1 Server characterset: latin1 TCP port: 3306 Uptime: 2 hours 51 min 38 sec
Threads: 2 Questions: 2262 Slow queries: 0 Opens: 13 Flush tables: 1 Open tables: 0 Queries per second vg: 0.220 --------------
mysql> create table guestreply(replynum int(10) auto_increment primary key, seg int(10), replyname varchar(20 , erplycontet text, replydate varchar(10), peplypassword varchar(10)); Query OK, 0 rows affected (0.06 sec)
mysql> desk user -> ; ERROR 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server ver ion for the right syntax to use near desk user at line 1 mysql> desk user; ERROR 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server ver ion for the right syntax to use near desk user at line 1 mysql> show tables; +---------------------+ | Tables_in_jsptestdb | +---------------------+ | guestbook | | guestreply | | memo | | starcraft | | user | +---------------------+ 5 rows in set (0.04 sec)
mysql> show user; ERROR 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server ver ion for the right syntax to use near user at line 1 mysql> show table user; ERROR 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server ver ion for the right syntax to use near user at line 1
********************************************************* mysql> select * from user; +---------+-----------+-------------+----------+--------------+ | user_id | user_name | user_email | user_psw | user_regdate | +---------+-----------+-------------+----------+--------------+ | dd | dd | dd@. | 11 | 2004/12/03 | | anne | 한글 | abc@abc.com | 1 | 2004/12/03 | +---------+-----------+-------------+----------+--------------+ 2 rows in set (0.00 sec) ***********************************************************
mysql>
111111111111111111111111111111111111111 ***파일명 : user.sql*** create table user ( user_id varchar(10) primary key, user_name varchar(20), user_email varchar(50), user_psw varchar(10), user_regdate varchar(10) ); 222222222222222222222222222222222222222 ***파일명 : db.jsp*** <% String drivers=org.gjt.mm.mysql.Driver; String dbhost=jdbc:mysql://localhost:3306/JspTestDB; String dbuser=
oot; String dbpassword=\; try { Class.forName(drivers).newInstance(); }catch (ClassNotFoundException e){out.println(e);} %> 333333333333333333333333333333333333333 파일명 :login.html <html> <head> <!-- header - edit Data/yourHtmlHeader to customize --> <!-- contents - edit EventHandlers/Html file/onCreate to customize --> <title>login.html </title>
</head> <body> <center> <h1>로고인 화면</h1> <p> <hr> <form method=post action=loginCheck.jsp> <table> <tr> <td>id:</td> <td><input type=text name=id></td> </tr> <tr> <td>암호:</td> <td><input type=password name=pass></td> </tr> <tr> <td colspan=2><center> <input type=submit value=로고인> <input type=reset value=취소></center></td> </tr> </table> </form> <p> <hr> <table> <tr bgcolor=silver><td><font color=white>:<a href=registration.html>등록</a>을 하신후 사용 할 수 있습니다.</font></td></tr> <tr bgcolor=silver><td><font color=white>:사용자 계정<a href=delete.html>삭재</a></font></td></tr> <tr bgcolor=silver><td><font color=white>:등록된 사용자<a href=show.jsp>모두보기</a></font></td></tr> </table> </center> </body> </html>
444444444444444444444444444444444444444 ***파일명 :loginCheck.jsp*** <!--logoinCheck.jsp--> <%@ include file=db.jsp\%> <%@ page language=java import=java.sql.*,java.io.*,java.text.*,java.util.* contentType= ext/html; charset=EUC-KR\%>
<html> <head><title>loginCheck.jsp</title></head> 테스트 <body> <center> <h2>로그인 체크</h2> <p> <hr> <p> <% Connection con=null; Statement stmt=null; ResultSet rs=null;
String id=request.getParameter(id).trim(); String pass = request.getParameter(pass).trim(); if(id.length()==0){ out.println(<font color=red>ID를 입력해 주새요!</font>); out.println(<p><hr><p>); out.println(<a href=login.html><font color=blue>로그인 화면으로 돌아가기</font></a>); return; } if(pass.length()==0){ out.println(<font color=red>password를 입력해 주새요!</font>); out.println(<br>); out.println(<p><hr><p>); out.println(<a href=login.html><font color=blue>로그인 화면으로 돌아가기</font></a>); return; } try{ con=DriverManager.getConnection(dbhost, dbuser, dbpassword); stmt=con.createStatement(); rs=stmt.executeQuery(select user_id, user_psw from User where user_id=\+id+\); if(rs.next()) { String db_id=rs.getString(1); String db_psw=rs.getString(2); //out.println(DB:+db_id+,+db_psw); if(db_psw.equals(pass)) { response.sendRedirect(welcome.jsp?id=+id); } else { out.println(<font color=red>password가 틀립니다. 다시확인해주십시요.!!</font>); out.println(<a href=login.html>로그인하기</a>); out.println(<p><hr><p>); return; } } else { out.println(<font color=red>Password가 틀립니다. 다시 확인해 주십시요!</font>); out.println(<p><hr><p>); out.println(<a href=registration.html>사용자 등록하기</a>); } } catch(Exception e) { System.out.println(e); //System.생략가능 } %> </body> </html> 555555555555555555555555555555555555555 ***파일명 : registration.html
<html> <head> <title>registration.html</title>
</head> <body> <center> <h1>사용자 등록화면</h1><p> <hr> <form method=post action=regConform.jsp> <table> <tr> <td>*이름:</td> <td><input type=text name=
ame></td> </tr> <tr> <td>*ID(최대10):</td> <td><input type=text name=id size=10></td> </tr> <tr> <td>*E-mail:</td> <td><input type=text name=email size=30></td> </tr> <tr> <td>*암호(최대10):</td> <td><input type=password name=pass1 size=10></td> </tr> <tr> <td>*암호확인(최대10):</td> <td><input type=password name=pass2 size=10></td> </tr> <tr> <td colspan=2><center> <input type=submit value=등록하기> <input type=reset value=취소></center></td> </tr> </table> </from> <p> <hr> <a href=show.jsp><font color=blue>내용저장확인</font></a> </center>
</body> </html>
666666666666666666666666666666666666666 ***파일명 : welcome.jsp <!--welcome.jsp-->
<%@ page contentType= ext/html;charset=EUC-KR\%>
<html> <head> <title>Welcome.jsp</title> </head> <body bgcolor=white text=lack link=lue vlink=purple alink=
ed> <center> <h2>환영합니다.</h2> <p><hr><%=request.getParameter(id)%>님의 로그인을 환영합니다.</hr></p> </center> </body> </html> 777777777777777777777777777777777777777 파일명 : show.jsp <!--show.jsp--> <%@ include file=db.jsp\%> <%@ page language=java import=java.sql.*,java.io.*,java.text.*,java.util.* contentType= ext/html;charset = EUC-KR\%>
<html> <head><title>전체보기</title></head> <body> <center><h2>등록 사용자 명단</h2></center> <% Connection con=null; Statement stmt=null; ResultSet rs=null; try{ con=DriverManager.getConnection(dbhost, dbuser, dbpassword); stmt=con.createStatement(); rs=stmt.executeQuery(select user_id, user_name, user_email, user_regdate from User); %> <center> <table width=70%> <tr bgcolor=gray><th>순서</th><th>ID</th><th>이름</th><th>이메일</th><th>등록일</th></tr> <% int cnt=0; while(rs.next()) { String id=rs.getString(1); String name=rs.getString(2); String email=rs.getString(3); String regdate=rs.getString(4); %> <tr> <td align=center><%=Integer.toString(++cnt)%></td> <td><font color=blue><%=id %></font></td> <td><font color=blue><%=name %></font></td> <td><font color=blue><%=email %></font></td> <td><font color=blue><%=regdate %></font></td> </tr> <%}%> </table> <table width=70%> <tr bgcolor=gray> <td align=right><font color=white>검색건수: 총 <b><%=cnt%></b>건</font> </td> </tr> </table> </center> <% }catch(Exception e) { System.out.println(e); } %> </body> </html> 888888888888888888888888888888888888888 ***파일명 : regConform.jsp*** <!--regConform.jsp--> <%@ include file=db.jsp\%> <%@ page language=java import=java.sql.*,java.io.*,java.text.*,java.util.* contentType= ext/html;charset = EUC-KR\%>
<html> <head><title>regConform.jsp</title></head> <body>
<center> <h1>사용자 등록확인 화면</h1> <p> <hr>
<% Connection con=null; Statement stmt=null; ResultSet rs=null;
String name=new String(request.getParameter(
ame)); String id=new String(request.getParameter(id)); String email=request.getParameter(email); String pass1=request.getParameter(pass1).trim(); String pass2=request.getParameter(pass2).trim(); java.util.Date now=new java.util.Date(); SimpleDateFormat date=new SimpleDateFormat(yyyy/MM/dd); String regdate=date.format(now);
if(name.trim().length()==0){ out.println(<p>); out.println(<font color=red>이름을 입력해 주세요!</font>); out.println(<p><hr><p>); out.println(<a href=registration.html><font color=blue>사용자등록 화면으로 돌아가기</font></a>); return; } if(id.length()==0){ out.println(<P>); out.println(<font color=red>ID를 입력해 주새요!</font>); out.println(<p><hr><p>); out.println(<a href=registration.html><font color=blue>사용자 등록화면으로 돌아가기</font></a>); return; } if(email.trim().length()==0){ out.println(<P>); out.println(<font color=red>메일주소를 입력해 주새요!</font>); out.println(<p><hr><p>); out.println(<a href=registration.html><font color=blue>사용자 등록화면으로 돌아가기</font></a>); return; } if(pass1.length()==0){ out.println(<P>); out.println(<font color=red>암호를 입력해 주새요!</font>); out.println(<p><hr><p>); out.println(<a href=registration.html><font color=blue>사용자 등록화면으로 돌아가기</font></a>); return; } if(pass2.length()==0){ out.println(<P>); out.println(<font color=red>암호확인을 입력해 주새요!</font>); out.println(<p><hr><p>); out.println(<a href=registration.html><font color=blue>사용자 등록화면으로 돌아가기</font></a>); return; } if(!pass1.equals(pass2)){ out.println(<P>); out.println(<font color=red>암호가 일치하지 않습니다!</font>); out.println(<p><hr><p>); out.println(<a href=registration.html><font color=blue>사용자 등록화면으로 돌아가기</font></a>); return; } if(email.indexOf(@)<0 || email.indexOf(.)<0){ out.println(<P>); out.println(<font color=red>전자메일을 입력해 주새요!</font>); out.println(<p><hr><p>); out.println(<a href=registration.html><font color=blue>사용자 등록화면으로 돌아가기</font></a>); return; } try{ con=DriverManager.getConnection(dbhost,dbuser, dbpassword); stmt=con.createStatement(); rs=stmt.executeQuery(select user_id from User where user_id=\+id+\); if(rs.next()) { out.println(<p>); out.println(<font color=red>이미 사용중인 ID입니다.!</font>); out.println(<p><hr><p>); out.println(<a href=registration.html><font color=blue>사용자 등록화면으로 돌아가기</font></a>); return; } else { String query=insert into user (user_id, user_name, user_email, user_psw, user_regdate) values (\+id+\,\ +name+\, \ +email+\, \ +pass1+\, \ +regdate+\);;/////////////////////////////////////////////////////////////////////// //out.println(query); stmt.executeUpdate(query); %> <table border=1> <tr><td>이름:</td> <td><%=name%></td> </tr> <tr><td>ID:</td> <td><%=id%></td> </tr> <tr><td>E-mail:</td> <td><%=email%></td> </tr> <tr><td>암호:</td> <td><%=pass1%></td> </tr> <tr><td>등록일:</td> <td><%=regdate%></td> </tr> </table> <% } } catch(Exception e){ e.printStackTrace(new PrintWriter(out)); return; } %> <p> <hr> <p> <a href=login.html><font color=blue>로그인 화면으로</font></a> </center> </body> </html> 9999999999999999999999999999999999999999 ***파일명 : delete.html*** <html> <head> <title>사용자 삭제화면</title>
</head> <body> <h1>사용자 삭제 화면</h1> <p> <hr> <form method=post action=delete.jsp> <table> <tr><td>ID:</td> <td><input type=text name=id></td> </tr> <tr><td>PASSWORD:</td> <td><input type=password name=pass></td> </tr> <tr><td colspan=2><center> <input type=submit value=삭제하기> <input type=reset value=취소></center></td></tr> </table> </form> <p> <hr> <a href=show.jsp><font color=blue>내용저장 확인</font></a> </center> </body> </html>
10101010101010101010101010101010101010 ***파일명 : delete.jsp*** <!--delete.jsp--> <%@ include file=db.jsp\%> <%@ page language=java import=java.sql.*,java.io.*,java.text.*,java.util.* contentType= ext/html;charset=EUC-KR\%>
<html> <head><title>사용자 정보 삭제</title></head> <body> <center><h2>사용자 정보 삭제</h2> <p> <hr> <p> <% Connection con=null; Statement stmt=null; ResultSet rs=null; String id=request.getParameter(id).trim(); String pass=request.getParameter(pass).trim(); if(id.length()==0){ out.println(<font color=red> ID를 입력해 주세요!</font>); out.println(<p><hr><p>); out.println(<a href=delete.html><font colort=blue>삭제화면으로 돌아기</font></a>); return; } if(pass.length()==0){ out.println(<font color=red>Password를 입력해 주세요!</font>); out.println(<br>); out.println(<p><hr><p>); out.println(<a href=delete.html><font color=blue>삭제화면으로 돌아가기</font></a>); return; } try{ con=DriverManager.getConnection(dbhost, dbuser, dbpassword); stmt=con.createStatement(); rs=stmt.executeQuery(select user_id, user_psw from User where user_id=\+id+\); if(rs.next()) { String db_id=rs.getString(1); String db_psw=rs.getString(2); //out.println(DB:+db_id+,+db_psw); if(db_psw.equals(pass)) { stmt.executeUpdate(delete from User where user_id=\+id+\); response.sendRedirect(show.jsp); } else { out.println(<font color=red>Password가 틀립니다. 다시한번해 주십시요!!</font><br>); out.println(<a href=delete.html>사용자 삭제하기</a>); out.println(<p><hr><p>); return; } } else { out.println(<font color=red>존재하지 않는 ID입니다. 가입하신적 음나봥염..</font><br>); } } catch(Exception e) { System.out.println(e); } %> <p> <hr> <p> <font color=blue> 사용자삭제화면으로<a href=delete.html>돌아가기</a></font><br> <font color=blue> 사용자 로그인 화면으로 <a href=login.html>돌아가기</a></font> </body> </html>
JSP스터디 2004 12 3 일에 완성 남들은 방명록완성해슴미다
소스 자세히 정확하게 보기 http://www.6VJ.com/jsp/jsp1129.txt
|