???? DB ?? 1 - PowerPoint PPT Presentation

1 / 78
About This Presentation
Title:

???? DB ?? 1

Description:

9. – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 79
Provided by: marv46
Category:
Tags:

less

Transcript and Presenter's Notes

Title: ???? DB ?? 1


1
9. ??????
2
???? DB ?? 1
  • MS-ACCESS? ???? ??
  • ??? ???? ??? ??.
  • ?? ???? ? ??
  • num ??? ID? ??? ????
  • ???? ?? ? ????.
  • ??? ?????? ????? ??? ??.
  • Num? ??? ??? ??? ?? ?
  • ? ??? ??? ?? ??.

3
???? DB ?? 2
  • ??? ??? member ?? ??.
  • ??? ?? member???? ?????.

4
ID ?? ?? 1
  • ? ??? ???? ???? ??? ? ? ?? ID??? ???? ????.
  • ? ??? ???? ???? ????? ??. ???? Member.jsp??.
  • ACCESS??? ??? ?? ??? JDBC?? ????? ???? ????.

5
ID ?? ?? 2
function idcheck() if(document.member.id.value
'') // ID control? ?? ????? ?? alert("ID?
?????.") return window.open("idcheck.jsp?id
"document.member.id.value,"idcheck",
"width320,
height200,menubarno,scrollbarsno")
??? ?? ???? ??? ???? ? ??????? ????. Id ????
????? ???? ???? ???? ????? ??? ? ???. idcheck.jsp
??? id???? ???? ?? ??? ??? ??. ???? ? ??? ??? ??
??? ??? ?? ??? ? ? ?? ??.
6
ID ?? ?? 3
idcheck.jsp ? ??? ????.
lt try // Member.jsp ??? ??ID? ???. String id
request.getParameter("id") // JDBC?????
????. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver
") // ??? ????? DBMS? ????. String
url"jdbcodbcdsn_create21" Connection dbCon
DriverManager.getConnection(url,"","")
//SQL??? DBMS? ????. // ID? ?? ?? ???? ??? ??
??? ????. String sql "SELECT COUNT(id) FROM
member WHERE id'" id "'" Statement stmt
dbCon.createStatement() // ??? SQL??? ????.
ResultSet rs stmt.executeQuery(sql)
rs.next() gt
7
ID ?? ?? 4
??? ID? ?? DB? ???? ???? ??? ?? rs? ?? 0 ? ???.
? ??? ??? ??? ?? ???? ????. ??? ?? ID?
????? ??? ?? ???? ????.
lt if(rs.getInt(1)0) gt
ltfont size3 color"000000"gtltidgtlt/Bgt?(?) ???
? ?? ID???.lt/fontgt ltinput type"button"
name"confirm1" value" ? ? "
onclick"javascriptself.close()"gt
ltelse gt
ltfont size3 color"000000" align"center"gtltid
gt lt/Bgt?(?) ?? ???? ID???.lt/fontgt ltinput
type"button" name"confirm1" value" ? ? "
onclick"javascriptconfirm()"gt
8
ID ?? ?? 5
??? ???? ? ???? ?????? ????. ???? ???
???? ???? ??? ??? ? ??.
ltscript language"JavaScript"gt lt!-- function
confirm() // ?? ???. opener.document.member.id.
value"" self.close() // ?? ???. opener.docum
ent.member.id.focus() // ???? ID?????
???. //--gt lt/scriptgt
9
ID ?? ?? 6
??? ??? ?? ??? ID? ?? ???? ??? ????.
?? O
?? X
10
?????? ???? 1
  • ????? ?? ??CD? POST.mdb ?????? ???? ????? ???
  • ???? ???? ???? Create21.mdb ??? ????.
  • Ch9 ? ?????? POST.mdb ??? ??.
  • ??? ?? Post ?? ??? ?? ???? ? ?? ??.
  • ??? ??? ??? ?? ?? ? ????.

11
?????? ???? 2
2. ??? ???? ??? ??? Create21 ??????? ??. ????
??? ??? ??? ?????? ???? ????? ????. ????? ???
??? ?? ???.
12
???? ?? 1
ID ????? ????? ?????? ???? ???? ??? ??
????. ?? ??? JDBC-ODBC Bridge
Driver????? ???? ????? ??. ?? ??? ???? ?
Member.jsp??. ?? ???? ???? ?? ?? ??? ??? ??
?? ?? ??
13
???? ?? 2
ID ????? ????? ?????? ???? ???? ??? ?? ????. ??
??? ???? ? ????. Member.jsp
// ???? ??? ?? ? ?336 ??300 ??? ?? ????? ??
function officeaddr() window.open("office.jsp",
"addrsearch","width336,height300,menubarno,scro
llbarsyes") . . . // this.blur()??? ? ????
???? ?????? ??? ????? ?? ?????. ltinput
type"text" name"officezip1" size"3"
maxlength"3" onFocus"this.blur()"gt - ltinput
type"text" name"officezip2" size"3"
maxlength"3" onFocus"this.blur()"gt // ???? ???
??? officeaddr()? ?????? ??? ????. lta
href"javascriptofficeaddr()"gt ltimg
src"images/free_52.gif" width70 height22
border"0"gtlt/agt
14
???? ?? 3
?? Member.jsp?? ???? ??? ???? ????office.jsp?
????. ??? ???? ????? ??? ?? serchofficezip.jsp?
?? ??? ??. Member.jsp

serchofficezip.jsp
15
???? ?? 4
?? Member.jsp ?? ???? ??? ?? ?
????office.jsp? ????.
// ??? ? ??? ????. ?? Member.html? ??? ????. lt_at_
page contentType"text/htmlcharseteuc-kr"gt .
ltscript language"JavaScript"gt lt!-- function
searchzip() // ???? ?? ???? 2?? ????
????. if((document.search.dong.value'')
(document.search.dong.value.lengthlt2))
alert("?/? ?? ?????? 2??? ?????.")
return
document.search.submit() //--gt lt/scriptgt ....
// ? ??? search ????? post ????
searchofficezip.jsp? ??? ???. ltform name"search"
method"post" action"searchofficezip.jsp"gt //
?? ?? ??? searchzip() ????????? ????. ltinput
type"button" value"??"OnClick"searchzip()"gt
16
???? ?? 5
?? ?? ???? ?? ?? ????? ???? ?? ????
searchofficezip.jsp ? ????. ? ???
??? ????? ??.
17
???? ?? 6
searchofficezip.jsp????
lt // dong???? ?? ???. String
dongmakeKor(request.getParameter("dong")) try
//JDBC-ODBC????? ????.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
// ??? ????? DBMS? ????. String url
"jdbcodbcdsn_create21" Connection dbCon
DriverManager.getConnection(url, "", "")
//SQL??? DBMS? ????. String sql
"SELECT FROM post where Dong like '" dong
"'" Statement stmt dbCon.createStatement()
// ??? SQL??? ????. gt
18
???? ?? 7
Searchofficezip.jsp

ltscript language"JavaScriptgt //
p_zip1,p_zip2,p_addrl??? ??? ??? p_zip1 new
makeArray() p_zip2 new makeArray() p_addr1
new makeArray() lt/scriptgt lt // ???? ???
???? ResultSet? ???. ResultSet rs
stmt.executeQuery(sql) int i 0 // ?? i?
0? ???. while(rs.next()) //???????? ?,
?, ??? ????. String sirs.getString("Si") String
gurs.getString("Gu") String real_dongrs.getStri
ng("Dong") //??? ?, ?, ? ?? ??? ????. String
addrsigureal_dong
19
???? ?? 8
Searchofficezip.jsp

/?????? ???? ??????? ??? ????? ???./ String
ziprs.getString("zip") String
leftzipzip.substring(0,3) String
rightzipzip.substring(4,7) gt lttrgt lttdgt
ltscriptgt // ??? ???? 0???? ?? ??????.
p_zip1'ltigt''ltleftzipgt'
p_zip2'ltigt''ltrightzipgt'
p_addr1'ltigt''ltaddrgt' lt/scriptgt
20
???? ?? 9
Searchofficezip.jsp

ltfont size"-1" face"??"gt // ??? ????? ???
????. lta href"javascriptReturnAddr(ltigt)"gt
ltleftzipgt-ltrightzipgt nbspnbspnbsp
nbspnbsp ltaddrgtlt/agtlt/fontgtlt/tdgt
lt/trgt
? ??? ?? ??? ????? ltagt??? ??? ?????? ??? ??? ??
???(????)? ?? ??????? ??? ????.
function ReturnAddr(n)
opener.document.member.officezip1.valuep_zip1n
opener.document.member.officezip2.valuep_zip2
n opener.document.member.officeaddr1.valuep_a
ddr1n self.close() // ??? ??(n)? ???? ? ??
??? ?????? ????. // opener ?? ???? ??? ?? ???
????? ???.
21
???? 1
?????? ??? ID?? ????? ?????? ??? ?????. ???? ??
?? ?? ???? ???? ??? ???? ????? ??. ltform
name"member" method"post"gt ?? ??? member
??. ltinput type"text" name"id" size"15"
maxlength"20" class"input"gt ??ID???? ??? id
??. lta href"javascriptidcheck()"gtltimg
src"images/free_08.gif" border"0"gtlt/agt ??? ???
ID?? ?????????. ltinput type"password"
name"passwd" size"15" maxlength"8"
class"input"gt ????? ??? ??? passwd??.
22
???? 2
ltinput type"password" name"passwd2" size"15"
maxlength"8" class"input"gt ???? ?????? ???
passwd2??. ltinput type"text" name"name"
size"15" class"input"gt ?????? ???
name??. ltinput type"radio" name"sex"
value"M" checkedgt ltbgtltfont size"2"
color"000000"gt? ltinput type"radio"
name"sex" value"F"gt?lt/fontgtlt/bgt ?????? ???
sex ??. ? ??? ???? ??? ???? ????? M ?? ???
F? ??????? ??? ??. ltinput type"text"
name"ssn1" size"6" class"input"gt -ltinput
type"text" name"ssn2" size"7" class"input"gt
???????? 2?? ??? ssn1 ? ??? ssn2 ??.
23
???? 3
ltselect name"job"gt ?????? ????? ??? job??.
ltinput type"text" name"email" size"25"
maxlegth"50" class"input"gt Email? ???? ???
email??. ltinput type"text" name"company"
size"25" maxlegth"50" class"input"gt ?? ? ???
???? ??? company ??. ltinput type"text"
name"depart" size"25" maxlegth"50"
class"input"gt ?? ? ?????? ??? depart ??.
ltinput type"text" name"tel1" size"4"
maxlegth"4" class"input"gt -ltinput
type"text" name"tel2" size"4" maxlegth"4"
class"input"gt -ltinput type"text" name"tel3"
size"4" maxlegth"4" class"input"gt ????????
3?? ??? ?? tel1 tel2 tel3 ??.
24
???? 4
ltinput type"radio" name"mailing" value"Y"
checked ltbgtnbspnbspltfont color"000000"gt?
lt/fontgtltfont size"2"gt ltinput type"radio"
name"mailing" value"N" gt nbspnbspltfont
color"000000"gt???lt/fontgtlt/bgtlt/fontgt Mailing??
???? ??? mailing??. ? ?? ? ???? Y? ????, ?
?? ? Y ??? ?? ? N ? DB? ?? ltinput type"text"
name"circle" size"25" maxlegth"50"
class"input"gt ??????? ??? circle??. ltinput
type"text"name"officezip1 size"3
maxlength"3 onFocus"this.blur()"gt -ltinput
type"text" name"officezip2" size"3"
maxlength"3" onFocus"this.blur()"gt ???????? 2??
???? ???? officezip1 ???? officezip2 ??.
???? ? ??? ?? ???? ??? ??? ??? ?????
onFocusthis.blur() ??? ????.
25
???? 5
lta href"javascriptofficeaddr()"gt ltimg
src"images/free_52.gif" width70 height22
border"0"gtlt/agt ??? ??? ???? ??????. ltinput
type"text" name"officeaddr1" size"20"
maxlength"50"onFocus"this.blur()"gt ltinput
type"text" name"officeaddr2" size"20"
maxlength"50"gt ?? ???? 2 ?? ???? ???????? ????
??? ???? ?? ??? officeaddr1 ? ??? ???? ????
???? officeaddr2 ??. ltinput type"button"
value" ? ? " onclick"javascriptconfirmation(
)"gt ?????? ??? ?? ???? ?? confirmation() ??? ????.
26
???? 6
??????
function confirmation() if (document.member.id
.value'') alert("ID? ??????.") document.memb
er.id.focus() return
. document.member.action"MemberSave.jsp" doc
ument.member.submit() ? ????? ??? ??? ??????
???? ??????????. ???? ??? ?????? ?????
MemberSave.jsp ? ??? ?? ? ??? ???.
27
???? 7
  • if(document.member.ssn1.value.length!6)
  • alert ("??????? ?? ???????.")
  • document.member.ssn1.focus()
  • return
  • .
  • if(!allnum(document.member.ssn1.value))
  • alert("??????? ??? ??? ?????.")
  • document.member.ssn1.focus()
  • return
  • - ??????? ???? ???? ????.
  • - ??? ?? allnum() ??? ??? ??? ??? ?? ???????
    ????.
  • function allnum(input)
  • for(var ii0iiltinput.lengthii)
  • if(isNaN(input.charAt(ii)))
  • return false
  • return true

28
???? 8
if((document.member.ssn1.value.length6)
(document.member.ssn2.value.length7)) var
ssn1 document.member.ssn1.value var ssn2
document.member.ssn2.value var
juminNumssn1ssn2 a new Array(13) for (var
i0 i lt 13 i) ai parseInt(juminNum.cha
rAt(i)) var j a02a13a24a3
5a46a57 a68a79a82a9
3a104a115 var j j 11 var k 11
- j if (k gt 9) k k 10 ??????? ????
????. 13??? ???????? ?? 12??? ???? ???? ????? ??
13?? ??? ??? ???.
29
???? 9
if (k ! a12) alert ("??????? ??
???????.") document.member.ssn1.focus() retu
rn ?? ??? k? ??????? 13?? ???? ??? ??????
???? ???. allemaildocument.member.email.value
count0 for (i0iltallemail.len
gthi) if (allemail.charAt(i)
"_at_") count
Email? ?? ???? count?? ??? ???
???? ??? email?? ? ??? ?? for?? ?????. ? ??
??_at_? ??? ???? ? _at_? ??? count ? ??? count?? ?
?? ?????.
30
???? 10
if (count!"1") alert("E-mail? ??
???????.") document.member.email
.value"" document.member.email.
focus() return false
Email? ??? ????? _at_ ? 1? ??? ??? if?? ???? _at_ ?
1??? ???? ???? ??. document.member.action"Memb
erSave.jsp" document.member.submit() ??? ??
?? ? ???? ?? ??? MemberSave.jsp ? ??? ?? ??
??? ? ??? ???.
31
?? ?? ?? 1
lt_at_ page contentType"text/htmlcharseteuc-kr"
import"java.sql., java.util." gt lt try
String id makeKor(request.getParameter("id
")) String passwd makeKor(request.getParame
ter("passwd")) String name
makeKor(request.getParameter("name")) String
sex makeKor(request.getParameter("sex"))
String ssn1 makeKor(request.getParameter("ssn1")
) String ssn2 makeKor(request.getParameter(
"ssn2")) String job makeKor(request.getPara
meter("job")) String email
makeKor(request.getParameter("email")) .
ID? ??? ???? ??? ???? ??? ?? ?? ??? ???.
32
?? ?? ?? 2
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
// ?????? ?????. String url
"jdbcodbcdsn_create21" // ??????? ?????.
Connection dbCon DriverManager.getCo
nnection(url, "", "") // ??? ???
PreparedStatement??? ?????. PreparedStatement
pstmt null JDBC-ODBC ????? ????? ??????? ????
??. ??? ??? ?? PreparedStatement ??? ??? ?? ??.
33
?? ?? ?? 3
if (k ! a12) alert ("??????? ??
???????.") document.member.ssn1.focus() retu
rn ?? ??? k? ??????? 13?? ?? ?? ???
?????? ???? ???. allemaildocument.member.email.
value count0 for
(i0iltallemail.lengthi) if
(allemail.charAt(i)"_at_")
count Email? ??
???? count?? ??? ??? ???? ??? email?? ? ??? ??
for?? ?????. ? ?? ??_at_? ??? ???? ? _at_? ???
count ? ??? count?? ? ?? ?????.
34
?? ?? ?? 4
Calendar calendar Calendar.getInstance()
String wdate Integer.toString(calendar.get(Calen
dar.YEAR)) "-" wdate wdate
Integer.toString(calendar.get(Calendar.MONTH))
"-" wdate wdate Integer.toString(calendar
.get(Calendar.DATE)) " " wdate wdate
Integer.toString(calendar.get(Calendar.HOUR_OF_DAY
)) "" wdate wdate Integer.toString(cal
endar.get(Calendar.MINUTE)) "" wdate
wdate Integer.toString(calendar.get(Calendar.SEC
OND)) Canlendar ??? ??? ??? ??? ???? ??.
String sql "INSERT INTO member(id, passwd,
name, ssn1, ssn2, job," sql sql "
email, company, depart, tel1, tel2, tel3,
mailing," sql sql " circle, officezip1,
officezip2, officeaddr1, officeaddr2, wdate,
sex)" sql sql " VALUES
(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" Prepa
redStatement??? ??? ????? ? ??? ??? ??.
35
?? ?? ?? 5
// ??? ???? ?????. pstmt.setString(1, id)
pstmt.setString(2, passwd)
pstmt.setString(3, name) pstmt.setString(4,
ssn1) pstmt.setString(5, ssn2) .. ..
pstmt.setString(19, wdate)
pstmt.setString(20, sex) // ??? ?????.
pstmt.executeUpdate() ??? ???? ??. ? ??? ???
?? ??? ???? ??? ????? ???.
36
?? ?? ?? 6
response.sendRedirect("congratulation.html") ??
? ????? ????? ???? ???? ????.
pstmt.close() dbCon.close() ??? ???
?????. ?? ??? ?? ??? congratulation.html ??.
???? ? ? ??? ?? ????? ????? html????.
37
Congratulation.html
ltbody bgcolor"FFFFFF"gt lttable width"450"
height"580" border"0"gt lttrgtlttd
align"center"gt lttable width"320" border"0"
cellspacing"0" cellpadding"0"gt lttrgt lttd
align"center"gt ltimg src"IMAGES/congratulatio
n.gif" width"332" height"300"gtlt/tdgt lt/trgt
lttrgt lttdgtnbsplt/tdgt lt/trgt lttr
align"center"gt ltform name"form1" gt lttdgt
ltinput type"button" name"Submit" value"
Main "onclick'javascriptparent.window.close()'gt
lt/tdgt lt/formgt lt/trgtlt/tablegtlt/tdgtlt/trgtlt/tabl
egt
38
?? ??
39
????? ??? ??? 1
?????? ????? ???? ??? ??. ??? ??????? ??? ??
????. ?? ??? ???? ??? ??? ?????? ??? ????
????(Component)?? ??? ????? ?? ? ??. ??? ???
???? ?????? ??? ??????? ??? ? ?? ??? ?????? ????
?????? ??? ??? ??? ???? ???? ??????? ??? ????
?????? ???? ??????? ??? ? ??? ??????? ?? ?? ?
??. ??? ??? ?? ???? ?? ????? ??????? ??? ???? ??
?? ?? ??? ???? ??. ? ?? ????? ???? ??? ??? ???
??. ??? ?? ??? ???? ??? ?? ????.
40
????? ??? ??? 2
lthtmlgt ltheadgt ltscript language"JavaScript"gt lt!--
function EnterCheck(i) if(event.keyCode
13 i1) document.login.passwd.
focus() if(event.keyCode 13 i2)
confirmation() ???? ????
I?? 2?? keyCode? 13??(??? ???) confirmation()?? ?
?? ??? ??.
41
????? ??? ??? 3
function confirmation() if(document.login.id.valu
e'') alert("ID? ??? ???.") document.login.id
.focus() return if(document.login.passwd.v
alue'') alert("????? ??? ???.") document.log
in.passwd.focus() return document.login.act
ion"welcome_ok.jsp" document.login.submit()
ID?? ???? ???? ???? ?? ?????? ????
passwd???? ???? ??. ?? ? ?? ?????
welcome_ok.jsp ??? ??? ????. ??? ? ?? ?? ??? ??
????? ??.
42
????? ??? ??? 4
ltbodygtltcentergtltbrgtltbrgt ltfont size2gtltbgt?????lt/Bgtlt/
fontgt // ??? login??? ????? POST????. ltform
name"login" method"post"gt lttable width"156"
border"0" cellspacing"0" cellpadding"0"gt lttr
align"center"gt lttd width"156" height"94"
background"images/rightbgtop.gif"gt
lttable width"154" border"0"
cellspacing"0" cellpadding"0"gt lttrgt
lttd width"64" align"right"gtltimg
src"images/id.gif" width"44" height"11"gtlt/tdgt
lttd width"90" align"center"gt
ltinput type"text" name"id" size"8"
maxlength"20" onKeyDown"EnterCheck(1)"gt ID????
??? id?? ??? ?? ? ???? ??? ???? ???????
EnterCheck(1)??? ??? ??? ??. ??? ??? ?????????
????.
43
????? ??? ??? 5
lttd width"64" align"right"gt
ltimg src"images/pass.gif" width"56" height"11"
gtlt/tdgt lttd width"90" align"center"gt
ltinput type"password" name"passwd"
size"8" maxlength"8" onKeyDown"EnterCheck(2)"gt
lt/tdgtlt/trgt ????? ??? ??? ???? ??????
EnterCheck(2)?? ??? ????. lta href"javascriptco
nfirmation()"gt ltimg src"images/botton1.g
if" width"45" height"20" border0gtlt/agtlt/tdgt
lttd width"90" height"34" align"center"gt
lta href"member.jsp"gt ltimg
src"images/botton2.gif" width"68" height"20"
border"0"gtlt/agt lt/tdgtlt/trgt
lt/tablegt ???????? ???????? ?? ??? ? ????. ???
????? ????.
44
???? Login_Bean.java 1
import java.io. import java.sql. public
class Login_Bean private Connection dbCon
private Statement stmt private ResultSet
rs private String id private String
passwd ???? ??? Login_Bean ???? ??
???. ??????? ???, SQL ??? ???, ??? ??? ?? ???
???? ????. ??? ???? ???(id) ? ????(passwd)? ??
?? ????.
45
???? Login_Bean.java 2
public Login_Bean() try Class.forName("
sun.jdbc.odbc.JdbcOdbcDriver")
catch(ClassNotFoundException e) e.printStackTr
ace() ???? ???. ??? ???? ??? ??
??? JDBC? ???? ??? ???? ???? JDBC????? ????.
46
???? Login_Bean.java 3
public String getId() return id public
String getPasswd() return passwd public
void setId(String id) this.id id
public void setPasswd(String passwd)
this.passwd passwd ??????? ????? ?? ??? ??.
????? ??? ??? ???? ? ltjspsetProportygt??? ????
??? ?? ??? ?? ltjspgetPropertygt? ????. ? ???
ltjspsetProportygt ??? ??? ?? ??? ?? ?????
??????. public void setId(String id)? id?? ?? ???
? ???? ?????, public void setPasswd(String
passwd)? ?????? ?? ??? ? ????. ?? ????? setId?
getId? ????? ???? ???. setID?? ?? setId?? ??. ??
setid? ????. ??? ???? ???? ??? ??? ???????
set??? ??? ??? ???? ???? ???? ????. ??? setId,
setPasswd? ?? ??? ???? ??. ??? JSP? ?? ??? ??
ltjspgetProportygt ? ????. ????? ??? ??? setXXX?
getXXX????? ? ????? ???? ??. ?? ??? ?? setId??
??? getId?? ?? ?? setID?? getID ?? ?? ??.
47
???? Login_Bean.java 4
public boolean idCheck(String id, String
passwd) try ?????? ?????. String url
"jdbcodbcdsn_create21" ??????? ?????.
Connection dbCon
DriverManager.getConnection(url, "", "")
stmt dbCon.createStatement() ?? ??? id??
??? ?? member???? ?? ?? ????. ?? ??? passwd??
????. String sql"SELECT passwd FROM member
WHERE id '" id "'" ??? ???? ResultSet?
???. rs stmt.executeQuery(sql)
48
???? Login_Bean.java 5
?? ?? ??? if(rs.next()) ??????? ?? ???? ??
???? ??? ?? ????. ????? true??
if(passwd.equals(result.getString("passwd").trim()
)) session.setAttribute("id",id)
return true ??? ???
false? ????. ?? ???? ??? id?? ??? DB? ???? ???
???? ??? id? ??? ????? ???? ?????? ??? true?? ??
???? ??? ?? ???. ??? ? ?? ??? ???? ???
?? lt????gt\WEB-INF\classes\Login_Bean.java? ????
??. return false else
return false
49
???? welcome_ok.jsp 1
lt_at_ page contentType"text/htmlcharseteuc-kr"
import"java.sql.,java.util."gt ltjspuseBean
id"Login" scope"page" class"Login_Bean"/gt JSP?
? ?? ???? ???? ??? ???? ??? ?? ?????. ?? ??
ltjspuserBeangt? ?? ??? ???? ??? ??? ????. ? ?????
id, scope, page? ?? ? id? ? ? ???? ???? ??
????. ???? Login_Bean????? Login??? ???? ?? ???
??? ??. Scope??? ? ?? ??? ??? ? ????
page,request,session, application? ? ? ??. Page?
? ??? ?? ??? ???? ???? ? ??? ??? ?? ??? ?? ?????
??. Request? ???? ?? ???? ?? JSP????? ? ??
Request?? ? ?? ??? ??? ?? ???? ??. Session? ?
?? ????? ???? ???? ??? ?? ?? ??? ?? ????.
Application? ?? ? ??? ??? application? ???? ?? ??
????. ??? class? ??? ?? ??? ???? ? ???? ??? ????
????. ??? type??? ??? ??? ?? ???? ???? ??? ??
????.
50
???? welcome_ok.jsp 2
ltjspsetProperty name"Login" property"id"
param"id"/gt ltjspsetProperty name"Login"
property"passwd" param"passwd"/gt ??? ??? ?? ??
ltjspsetPropertygt? Property? ?? ??? ? ????. Name?
???? ?? ???? ??, property? ????? ??? ???? ??
Param? ????? ??? ???? ??? ??. ??? ??? ????
Login?? ??? ? id,passwd????? id, passwd ????
??? ?? ???? ? ??. lthtmlgt ltheadgtlt/headgtltbodygt lt
String id request.getParameter("id") String
passwdrequest.getParameter("passwd") ???? ??
???? ???? ??? ??? ???? ??? ? ?? ????.
51
???? welcome_ok.jsp 3
if(Login.idCheck(id,passwd)) Login??
idCheck?? ???? id? passwd?? ??? ??? ???. ?????
????? idCheck?? ???? ??????? ???? ?? id? Passwd?
???? ?? ? ?? ?? ???? ?????. ??? ????? true? , ???
??? false? ????. session.setAttribute("id",id)
response.sendRedirect("main.jsp") else gt ?
? true? ??? ??? ?????id? ????. ???? ??? Love? ???
???? ???? ???? session(id) Love ? ?? ???.
??? ? ?? ??? ?? main.jsp? ????.
52
???? welcome_ok.jsp 4
ltscript language"javascript"gt alert("? ID? ???
ID? ???? ? ????? ????. \n\n??? ??? ??? ???
????.") history.back() lt/scriptgt lt gt lt/bodygt
?? ??? ??? ???? ????? ??? ?? ??? ?? ??????
????. ?? ??? ??? ??? ? main.jsp? ???? ??.
53
Main.jsp 1
lt_at_ page contentType"text/htmlcharseteuc-kr"
import"java.sql., java.util."gt lthtmlgtltb
odygtltcentergt lttable border0gt lttrgtlttdgt ????
???????. lt/tdgtlt/trgt lttrgtlttdgtnbsplt/tdgtlt/trgt lttrgtlt
tdgt ??? ?? ID? ltbgtltsession.getAttribute("id")gt
lt/bgt ???. getAttribute()???? ??? ????? ?? ????.
54
Main.jsp 2
lt/tdgtlt/trgt lttrgtlttdgtnbsplt/tdgtlt/trgt lttrgtlttdgt ltfont
size2gt lta href"editMember.jsp"gt????lt/agt lta
href"delMember.jsp"gt????lt/agt lt/fontgt lt/bodygt lt/h
tmlgt ????? ???? ???? ???? ??? ???.
55
????? 1
Login_Bean.java ??? ??? ?? ???? ?? ?? ???? ??.
c\jakarta-tomcat\webapps\Ch9\WEB-INF\classes
Class??? ??? ????? ????.
56
????? 2
http//localhost/Ch9/welcome.jsp ??? ????. ???
???? ????? ????. ?? ????? ?? ??? ??? ?????
??? Main.asp? ???? ??. ???? ??? ????? ??? ? ??.
57
?? ?? ?? 1
? ??? ??? ??? ??? ???? ??? main.jsp ?? ????? ????
editMember.jsp ? ???? ????.
58
?? ?? ?? 2
lt/scriptgtlt/headgt lt String sid
(session.getAttribute("id")).toString() ??????
id ?? ???? sid?? ??? ???. try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
// ?????? ?????. String url
"jdbcodbcdsn_create21" // ??????? ?????.
Connection dbCon DriverManager.getConnection(
url, "", "") String sql"select
from member" sqlsql " where id '" sid
"'" // ????? id??? ?? sid? ???? ?? ?? ??
?? ???? ??? ???. Statement stmt
dbCon.createStatement() // ??? SQL??? ????.
ResultSet rs stmt.executeQuery(sql)
59
?? ?? ?? 3
if (rs.next()) ???? ???? ??? ? ????? id??
??? ?? DB??? ?? ???? String id
rs.getString("id") String passwd
rs.getString("passwd") .. ..
String officeaddr1 rs.getString("officeaddr1")
String officeaddr2 rs.getString("officeaddr2
") stmt.close() dbCon.close() gt
. ltform name"member" method"post"gt ?? ???
member ????? post??. .. lttd width"315"
bgcolor"DADBDB"gt ltfont size"2"gt nbsp
ltidgt ???? ????. ?????? ???? ???? ??? ?????.
60
?? ?? ?? 4
ltinput type"password" name"passwd" size"15"
maxlength"8" class"input"
value"ltpasswdgt"gt lt/fontgtlt/tdgt
lt/trgt lttrgt lttd
width"125" bgcolor"E4E3BE" height"28"gtltbgtltfont
size"2" color"000000"gtnbsp ltfont
size"2" color"800080"gtlt/fontgt
??????lt/fontgtlt/bgtlt/tdgt lttd
width"315" bgcolor"DADBDB"gt ltfont size"2"gt
nbsp ltinput type"password"
name"passwd2" size"15"
maxlength"8" class"input" value"ltpasswdgt"gt
lt/fontgtlt/tdgt ?????? ???? ?? ??
???? ???? ????. lttd width"315"
bgcolor"DADBDB"gtltbgtltfont size"2"gt nbsp
ltnamegt lt/fontgt
lt/bgt ???? ????. ?????? ??? ??? ??? ?????.
61
?? ?? ?? 5
lt if (sex.equals("M"))gt
ltinput type"radio" name"sex" value"M" checkedgt
ltbgtltfont size"2"
color"000000"gt? ltinput
type"radio" name"sex" value"F"gt
? lt/fontgtlt/bgtlt/tdgt lt elsegt
ltinput type"radio" name"sex"
value"M" gt ltbgtltfont size"2"
color"000000"gt? ltinput
type"radio" name"sex" value"F" checkedgt
? lt/fontgtlt/bgtlt/tdgt
ltgt ?? ?? M ?? ??? ???? ??? ??? ?? ???? ???
??. lttd width"315" bgcolor"DADBDB"gtltfont
color"000000"gtltbgtltfont size"2"gt
nbspnbspltssn1gt -ltssn2gt
lt/fontgtlt/bgtlt/fontgtlt/tdgt ??????? ????. ??????
??? ??? ??? ?????.
62
?? ?? ?? 6
lttd width"315" bgcolor"DADBDB"gtltbgtltfont
color"000000"gtltbgtltfont size"2"gt
nbspnbspltselect name"job"gt ltoption
value"ltjobgt" selectedgtltjobgtlt/optiongt
ltoption value"?????/??"gt??? ??/??lt/optiongt
ltoption value"???/????"gt???/????lt/optiongt
. . ltoption value"??"gt??lt/optiongt
ltoption value"??"gt??lt/optiongt
lt/selectgt ???? ???? ? ???? ???? selected ? ??
??. ??? ?? ?????? ? ?? ???? ??? ??? ??? ??? ??.
lttd width"315" bgcolor"DADBDB"gt ltfont
size"2"gt nbsp ltinput
type"text" name"email" size"25"
maxlegth"50" class"input" value"ltemailgt"gt
lt/fontgtlt/tdgt E-mail ?? ???? ????
???? ??.
63
?? ?? ?? 7
lttd width"315" bgcolor"DADBDB"gt ltfont
size"2"gt nbsp ltinput
type"text" name"company" size"25"
maxlegth"50" class"input" value"ltcompanygt"gtlt
/fontgtlt/tdgt ?? ? ???? ????. lttd width"315"
bgcolor"DADBDB"gt ltfont size"2"gt nbsp
ltinput type"text" name"depart"
size"25" maxlegth"50"
class"input" value"ltdepartgt"gtlt/fontgtlt/tdgt
?? ? ???? ????. lttd width"315"
bgcolor"DADBDB"gt ltfont size"2"gt nbsp
ltinput type"text" name"tel1" size"4"
maxlegth"4" class"input"
value"lttel1gt"gt -ltinput
type"text" name"tel2" size"4"
maxlegth"4" class"input" value"lttel2gt"gt
-ltinput type"text" name"tel3"
size"4" maxlegth"4"
class"input" value"lttel3gt"gt
lt/fontgtlt/tdgt ????? ????.
64
?? ?? ?? 8
lt if (mailing.equals("Y"))gt lttd
width"125" bgcolor"E4E3BE" height"28"gtltbgtltfont
size"2" color"F791AF"gtnbsplt/fontgtltfont
size"2" color"000000"gt Mailing
?? nbsplt/fontgtlt/bgtlt/tdgt lttd
width"315" bgcolor"DADBDB"gt ltfont size"2"gt
lt/fontgt ltinput type"radio"
name"mailing" value"Y" checkedgt
ltbgtnbspnbspltfont color"000000"gt?
lt/fontgtltfont size"2"gt ltinput
type"radio" name"mailing" value"N" gt
nbspnbspltfont color"000000"gt???lt/fontgtlt
/bgtlt/fontgtlt/tdgt lt else gt
lttd width"125" bgcolor"E4E3BE"
height"28"gtltbgtltfont size"2" color"F791AF"gtnbs
plt/fontgtltfont size"2" color"000000"gt Mailing
?? nbsplt/fontgtlt/bgtlt/tdgt
lttd width"315" bgcolor"DADBDB"gt ltfont
size"2"gt lt/fontgt ltinput
type"radio" name"mailing" value"Y" gt
ltbgtnbspnbspltfont color"000000"gt?
lt/fontgtltfont size"2"gt ltinput
type"radio" name"mailing" value"N" checkedgt
nbspnbspltfont color"000000"gt???
lt/fontgtlt/bgtlt/fontgtlt/tdgt ltgt ??? ?? Y ??? ????
?????? ????.
65
?? ?? ?? 9
ltinput type"text" name"circle" size"25"
maxlegth"50" class"input"
value"ltcirclegt"gt ltbrgtltfont
size"2" color"000000"gt(??? ???? ??
???)lt/fontgtlt/tdgt ???? ?? ????. ltinput
type"text" name"officezip1" size"3"
maxlength"3" value"ltofficezip1gt"
onFocus"this.blur()"gt - ltinput type"text"
name"officezip2" size"3" maxlength"3"
value"ltofficezip1gt" onFocus"this.blur()"gt
lta href"javascriptofficeaddr()"gt ?????? ????
value ? ?? ?? ????. ltinput type"text"
name"officeaddr1" size"20" maxlength"50"
value"ltofficeaddr1gt" onFocus"this.blur()"gt
ltinput type"text" name"officeaddr2"
size"20" maxlength"50" value"ltofficeaddr2gt"gt
????? ?? ????.
66
?? ?? ?? 10
ltinput type"button" value" ? ? "
onclick"javascriptconfirmation()"gt
lt/fontgtltfont size"2"gtltfont color"000000"gt
ltinput type"reset" value" ???? " gt
lt/fontgtlt/fontgtlt/pgt ?? ??? ??? ???? ????
??????? ????. ???? ??? ??? ??? ???? ?? ??? ??.
lt else out.println("??? ????") catch
(SQLException e) out.println(e) gt lt/formgt
lt/bodygt lt/htmlgt ??? if? ? ??? ?????.
67
?? ?? ?? 11
function confirmation() . document
.member.action"editmemberSave.jsp" document.mem
ber.submit() ???? ?????? ????. ???? ???
???? editmemberSave.jsp ? ??? ????.
68
??? ?? ?? ?? 1
lt_at_ page contentType"text/htmlcharseteuc-kr"
import"java.sql., java.util." gt lt try
????? ????? ????? ??? ???? ??? ??? ??? ?????
id ?? ???? ??. String id
session.getAttribute("id").toString()
String passwd makeKor(request.getParameter("pass
wd")) String name makeKor(request.getParame
ter("name")) String sex makeKor(request.get
Parameter("sex")) String ssn1
makeKor(request.getParameter("ssn1"))
String officeaddr1
makeKor(request.getParameter("officeaddr1"))
String officeaddr2 makeKor(request.getParameter(
"officeaddr2")) ????? ???? ???? ?? ??? ????.
???, ??, ??????? ??? ? ???? ???? ???.
69
??? ?? ?? ?? 2
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
// ?????? ?????. String url
"jdbcodbcdsn_create21" // ??????? ?????.
Connection dbCon DriverManager.getConnection(u
rl, ,) // ??? ??? PreparedStatement???
?????. PreparedStatement pstmt null
Calendar calendar Calendar.getInstance()
String wdate Integer.toString(calendar.get(Calen
dar.YEAR)) "-" wdate wdate
Integer.toString(calendar.get(Calendar.MONTH))
"-" wdate wdate Integer.toString(calendar
.get(Calendar.DATE)) " " wdate wdate
Integer.toString(calendar.get(Calendar.HOUR_OF_DAY
)) "" wdate wdate Integer.toString(cal
endar.get(Calendar.MINUTE)) "" wdate
wdate Integer.toString(calendar.get(Calendar.SEC
OND)) ??? ??? ??????? ?? ??? ???? ??.
70
??? ?? ?? ?? 3
// ??? ?????. String sql "UPDATE member
SET passwd ?, job?, email?, company?, "
sql sql "depart?, tel1?, tel2?, tel3?,
mailing?, circle?, officezip1?, " sql
sql "officezip2?, officeaddr1?,
officeaddr2?, wdate?, sex? " sql sql
"WHERE id'" id "'" pstmt
dbCon.prepareStatement(sql)
out.println(sql) ??? ?? ???? ??? ??? ???
PreparedStatement ??? ???? ???? ??. ??? ?? ???
UPDATE? ???? ???? ??. pstmt.setString(1,
passwd) pstmt.setString(2, job)
pstmt.setString(16, sex)
pstmt.executeUpdate() ? ????? ??? ?? ????
PreparedStatement ??? executeUpdate()???? ????.
71
??? ?? ?? ?? 4
response.sendRedirect("main.jsp")
pstmt.close() dbCon.close() catch
(SQLException e) out.println(e) gt ? ????
main.jsp? ??? ??. ?? ???? ??? ???? ??.
72
?? ?? ?? (????) 1
lt_at_ page contentType"text/htmlcharseteuc-kr"
import"java.sql."gt lthtmlgt ltheadgt lttitlegt ??
??lt/titlegt ltscript language"JavaScript"gt
lt!-- function DeleteSave() ????? ??????
???? ????. if(document.del.passwd.value'') al
ert("????? ??????.") document.del.passwd.focus()
return delMemberSave.jsp ???
????. document.del.action"delMemberSave.jsp" d
ocument.del.submit() // --gt lt/scriptgt
73
?? ?? ?? (????) 2
ltinput type"password" name"passwd" size"8"
maxlength"8"gtlt/fontgtnbsp ltpgt ltinput
type"button" value" ? ? " OnClick"javascript
DeleteSave()"gt ltinput type"button" value" ????
" OnClickhistory.back(-1)gt lt/tdgtlt/trgt
lt/tablegt ????? ??? ???? ???
passwd??. ?? ??? ??? ??? ??? DeleteSave()?
????. ???? ??? ??? ????? ????.
74
?? ?? ?? (????) 3
lt_at_ page contentType"text/htmlcharseteuc-kr"
import"java.sql."gt ltHTMLgt ltHEADgt ltTIT
LEgt? ????lt/TITLEgt lt/HEADgt ltBODYgt lt try
String sid session.getAttribute("id").toString()
// ?? ??? id?? ????. Class.forName("sun.jdbc
.odbc.JdbcOdbcDriver") String url
"jdbcodbcdsn_create21" Connection dbCon
DriverManager.getConnection(url, "", "")
String sql "SELECT passwd FROM member WHERE
id'" sid "'" ??? ??? ??? ???? ??? ?????
DB?? ????? ???? ??? ????. Statement stmt
dbCon.createStatement() ResultSet rs
stmt.executeQuery(sql)
75
?? ?? ?? (????) 4
rs.next() PreparedStatement pstmt null
String passwd rs.getString("passwd").trim()
??? ??? DB??? ??? ??? ???? ????? passwd?? ???
????. stmt.close() if
(passwd.equals(request.getParameter("passwd")))
?? ???? ??? ???? ?? ??? ????? passwd? ????
???? ???, ? DB? ???? ????? ?? ??? ????? ???
sql "DELETE FROM member WHERE id'" sid
"'" pstmt dbCon.prepareStatement(sql) Delete?
? ???? member???? ???? ??? ??? ??.
pstmt.executeUpdate()gt ltscript
language"javascript"gt alert("????
???????.") ???? ????. lt/scriptgt
76
?? ?? ?? (????) 5
else ????? ?? ??? ??? ???? ????.
gt ltscript language"javascript"gt
alert("????? ?? ????.")
history.go(-1) lt/scriptgt lt
catch (SQLException e)
out.println(e) gt lt/BODYgt lt/HTMLgt
77
?? ?? ?? (????) 5
else ????? ?? ??? ??? ???? ????.
gt ltscript language"javascript"gt
alert("????? ?? ????.")
history.go(-1) lt/scriptgt lt
catch (SQLException e)
out.println(e) gt lt/BODYgt lt/HTMLgt
78
?? ?? ??
  • Member.jsp ? ??
  • lt_at_ page contentType"text/htmlcharseteuc-kr"gt?
    ????.
  • welcome.jsp 68?? ?? member.jsp? Member.jsp? ???.
  • idcheck.jsp ??? idcheck_real.jsp ? idcheck.jsp?
    ??? ???? 23?? ?? ltsqlgt? ????.
  • office.jsp ? ?? lt_at_ page contentType"text/htmlch
    arseteuc-kr"gt? ????.
  • congratulation.html ???? ?? ??? ??? ??
  • ltinput type"button" name"Submit" value" Main
    " onclick'javascriptparent.window.close()'gt?
  • lta href welcome.jsp target_self gt?????lt/agt
  • ? ????.
  • Login_Bean.java ?? ??? ??? ???? ????.
  • welcome_ok.jsp ??? ?? CD? ?? ?? ??? ??? ?? ????.
  • delMemberSave.jsp ??? 57?? ??? gt? ????
  • 40?? ? ??? ?? ??? ????.
  • dbCon.close()
  • response.sendRedirect("welcome.jsp")
Write a Comment
User Comments (0)
About PowerShow.com