Class #13

backwad forwad Contents

Class #13: À¥ µ¥ÀÌŸº£À̽º ÀÀ¿ë½Ã½ºÅÛ °³¹ß
in place June 2, 2002, last modified June 2, 2002, working ...


MS Active Server Pages(ASP) ¼Ò°³

Server Side Script

ASP Architecture

±×¸² 13-3 ASP¸¦ ÀÌ¿ëÇÑ HTML ÆÄÀÏ ¼­ºñ½º
±×¸² 13-1 ASP¸¦ ÀÌ¿ëÇÑ µ¿Àû HTML ¼­ºñ½º

  • Visual Interdev
    ASP °³¹ßÀ» Áö¿øÇϱâ À§ÇÑ Visual Studio ³»ºÎÀÇ IDE

    ASP ±â´É

    • Request - FORMÀÇ INPUT Tag¿¡¼­ ÀÔ·ÂµÈ Parameter °ªÀ» Return
    • Response - Web È­¸é¿¡ Ãâ·Â
    • Database Connections - Database Connection, SQL ½ÇÇà, °á°ú Record Set Return
    • Session º¯¼ö - Session ÀÌ ÁøÇàµÇ´Â µ¿¾È ÇØ´ç º¯¼öÀÇ °ªÀ» ¼­¹ö¿¡¼­ ÀúÀå°ü¸®ÇØ ÁÜ
    • Server Component - ¼­¹öÀÇ ¿©·¯°¡Áö ÀÏÀ» ó¸®ÇÏ´Â Componet - Upload, Treeµî

    ASP Example (1) - »ç¿ëÀÚ µî·Ï

    • HTML Form file °ú ¿¬µ¿µÈ ASP ÆÄÀÏ - Request °´Ã¼
    • µ¥ÀÌŸº£À̽º Connection - ADO °´Ã¼

    ÀÔ·ÂFORM

    <B>»ç¿ëÀÚ µî·Ï</B></P>
    <HR>
    <UL>
    <LI>»ç¿ëÀÚ Login ÀÌ Áߺ¹µÇÁö ¾Êµµ·Ï ÇÒ°Í <A HREF="example02.asp">user list</A>
    <LI>°ø¶õÀ» µÎÁö ¸»°Í.
    <LI>passwd´Â ³ëÃâµÉ¼ö ÀÖÀ¸¹Ç·Î Æò¼Ò¾²Áö ¾Ê´Â ÀÓÀÇÀÇ ³»¿ëÀ» ³ÖÀ»°Í
    </UL>
    <TABLE border=0>
    <FORM NAME=NEW_USER ACTION=example0302.asp METHOD=POST >
    <TR><TD>user id<TD><INPUT NAME=user_id TYPE=TEXT>
    <TR><TD>¼º<TD><INPUT NAME=last_name TYPE=TEXT>
    <TR><TD>À̸§<TD><INPUT NAME=first_name TYPE=TEXT>
    <TR><TD>¸ÞÀÏÁÖ¼Ò<TD><INPUT NAME=email TYPE=TEXT>
    <TR><TD>ÈÞ´ëÀüÈ­¹øÈ£<TD><INPUT NAME=celphone TYPE=TEXT>
    <TR><TD>Æнº¿öµå<TD><INPUT NAME=passwd TYPE=PASSWORD>
    <TR><TD><TD><INPUT TYPE=SUBMIT value="INSERT">
    </FORM>
    

    »ç¿ëÀÚ µî·Ï

    • »ç¿ëÀÚ Login ÀÌ Áߺ¹µÇÁö ¾Êµµ·Ï ÇÒ°Í user list
    • °ø¶õÀ» µÎÁö ¸»°Í.
    • passwd´Â ³ëÃâµÉ¼ö ÀÖÀ¸¹Ç·Î Æò¼Ò¾²Áö ¾Ê´Â ÀÓÀÇÀÇ ³»¿ëÀ» ³ÖÀ»°Í
    user id
    ¼º
    À̸§
    ¸ÞÀÏÁÖ¼Ò
    ÈÞ´ëÀüÈ­¹øÈ£
    Æнº¿öµå

    example0302.asp ÆÄÀÏ - ½ÇÁ¦ µ¥ÀÌŸº£À̽º¿¡ Á¢±ÙÇÏ¿© ÀÔ·Â

    <%
    user_id = Request("user_id")
    last_name = Request("last_name")
    first_name = Request("first_name")
    email = Request("email")
    celphone = Request("celphone")
    passwd = Request("passwd")
    
    
    Dim DbCon, strDbCon
    
    Set DbCon = Server.CreateObject("ADODB.Connection")
        strDbCon = "Provider=sqloledb;Data Source=murano;Initial Catalog=MAIN;User Id=kedb;Password='';"
        DbCon.Open strDbCon
    
    sql="INSERT INTO USERS(user_id ,last_name,first_name,e_mail,celphone, passwd) "
    sql = sql + "VALUES('"
    sql = sql +user_id+"', '"+last_name+"','"+first_name+"', "
    sql = sql + "'"+email+"','"+celphone+"','"+passwd+"' "
    sql = sql + ")"
    
    Set Result=DbCon.Execute(sql)
    
    response.redirect("example02.asp")
    %>
    

    ASP Example (2) -example02.asp ÆÄÀÏ - µî·ÏµÈ »ç¿ëÀÚ Ãâ·Â

    • ADO °´Ã¼¸¦ ÀÌ¿ëÇÑ Query °ü¸®
    • Response °´Ã¼¸¦ ÀÌ¿ëÇÑ È­¸é Ãâ·Â
    <%
    Dim DbCon, strDbCon
    
    Set DbCon = Server.CreateObject("ADODB.Connection")
        strDbCon = "Provider=sqloledb;Data Source=murano;Initial Catalog=MAIN;User Id=kedb;Password='';"
        DbCon.Open strDbCon
    
    sql="SELECT user_id, last_name, first_name, e_mail, celphone  "
    sql = sql+ " FROM USERS "
    
    Set rs = Server.CreateObject("ADODB.RecordSet")
      rs.Open sql, DbCon
    
    IF rs.EOF OR rs.BOF THEN
    	response.write("<P>No user exist !")
    END IF
    Response.Write("<blockqutoe>")
    Response.write("<TABLE border=1 cellpadding=2 cellspacing=0>")
    Response.Write("<TR><TD class=TH>id<TD class=TH>name<TD class=TH>email<TD class=TH>celphone")
    	DO WHILE NOT rs.EOF 
    	Response.Write("<TR><TD>"+CStr(rs("user_id"))+"<TD>"+CStr(rs("last_name"))+" 
    "+CStr(rs("first_name"))+"<TD>"+CStr(rs("e_mail"))+"<TD>"+CStr(rs("celphone"))+" ")
    rs.MoveNext LOOP Response.Write("</TABLE>") %>

    °á°ú

    idnameemailcelphone
    dncµµ³²Ã¶namchul@hanmail.net016-437-2305

    ASP Example (3) - Á¦Ç°±¸Á¶ Ãâ·Â

    • Recursive Query
    • Server Side Component - Tree component

    Á¦Ç°±¸Á¶¸¦ ³ªÅ¸³»´Â µ¥ÀÌŸº£À̽º ±¸Á¶

    ºÎÇ° ¸ñ·Ï PART_MASTER Table
    OID part_no part_name
    1 A table
    2 B board
    3 C leg
    4 D mount
    5 E foot

    ºÎÇ°°£ÀÇ °ü°è - Á¦Ç° ±¸Á¶ STRUCTURE Table
    OID parent child
    1 1 2
    2 1 3
    3 3 4
    4 3 5

    A
    - B
    - C
    - - D
    - - E

    Á¦Ç°±¸Á¶¿¡ °üÇÑ Query

    • A ºÎÇ°ÀÇ ÀÚ½Ä ³ëµå¸¦ ã´Â Query

      SELECT c.part_no FROM a.PART_MASTER a, STRUCTURE b, PART_MASTER c
      WHERE a.part_no = 'A' AND a.OID = b.parent AND b.child = c.part_no

    • A ºÎÇ°ÀÇ ¸ðµç ÇÏÀ§ ³ëµå¸¦ ã´Â Application
      - A ºÎÇ°ÀÇ ÀÚ½Ä ³ëµå¸¦ ã´Â Query¸¦ RecursiveÇÏ°Ô ÀÌ¿ë


      FUNCTION print_node(Parent_part)
      {
      PRINT Parent_part;
      RECORD_SET = SELECT c.part_no FROM a.PART_MASTER a, STRUCTURE b, PART_MASTER c
      WHERE a.part_no =Parent_part AND a.OID = b.parent AND b.child = c.part_no;


      FOR RECORD_SET[i] {
      print_node(RECORD_SET[i])
      }

      }

    Server Side Component

    • 3rd PartyÀÇ ¼­¹ö »çÀ̵å Componet Ãß°¡
    • Active X Componet ¸¦ ÀÌ¿ëÇÑ Tree ¸Þ´º »ý¼º
    • µ¥ÀÌŸº£À̽º¿¡¼­ Á¦Ç°±¸Á¶¸¦ QueryÇÑ ÈÄ °á°ú·Î Tree ±¸Á¶ »ý¼º

    Ãâ·Â ¿¹

    ASP ÇÁ·Î±×·¥

    <%
    
    '====================================
    ' Navigate without Effectivity
    '====================================
    SUB Tree_Navi(part_no,part_version,part_name,struct_str,name_str,off_img,on_img,sibling_count,qty, oid, edge_id, vpmdb)
    off_img= off_img & "7"& ";"
    on_img= on_img & "7"& ";"
    name_str = name_str & part_no &" "&part_version& " "&part_name&";"
    
    query = "SELECT c.part_no, c.part_version, c.part_name, b.qty, b.child_oid, b.oid "
    query = query + " FROM PART_ASSY a, REL_ASSY b, PART_ASSY c "
    query = query + "where a.oid = '"+oid+"' "
    query = query + " and a.oid =b.parent_oid and b.child_oid =c.oid  "
    
    'Response.Write(" " + query + " ")
    Call db_connection(vpmdb)
    Set rs = vpmdb.execute(query)
    sibling_num = 0
    Do Until rs.EOF 
      sibling_num = sibling_num+1
      length=len(cstr(sibling_num))
      temp = String(4-length,"0")
      
      new_sibling_count = sibling_count + temp+cstr(sibling_num)
      struct_str = struct_str& new_sibling_count  & ";"
      CALL Tree_Navi(rs(0),rs(1),rs(2),struct_str, name_str,off_img,on_img, new_sibling_count, CStr(rs(3)), CStr(rs(4)), Cstr(rs(5)) ,vpmdb)
    	rs.MoveNext
    loop
    
    rs.close 
    Set rs = Nothing 
    END SUB
    '====================================
    ' END of SUBROUTINE
    '====================================
    
    oid=request("oid") 
    part_no=request("part_no")
    part_version=request("part_version")
    part_name=request("part_name")
    
    struct_str="10;"
    name_str= ""
    off_img = ""
    on_img = ""
    
    Call db_connection(DbCon) 
    Call Tree_Navi(part_no,part_version,part_name,struct_str,name_str,off_img,on_img,"10"," ",oid," ",DbCon)
    %>
    
    
    <HTML>
    <HEAD>
    <SCRIPT language=Javascript>
    <!--
    //-->
    </SCRIPT>
    
    <!-- ¿À¸¥ÂÊ ¹öÆ° Ŭ¸¯½Ã -->
    <SCRIPT LANGUAGE=javascript FOR=jwTB EVENT=OnItemRClicked(menuID)>
    <!--
    	Node = document.frm.jwTB.GetSelNodeCode();
    	Name = document.frm.jwTB.GetSelNodeName();
    	
    	/* extracts part no, version from displayed labels */
    	delim_loc = Name.indexOf(" ");
    	/* env = Name.substr(0,1); */
    	parent_part_no_ = frm.parent_part_no.value;
    	parent_part_version_ = frm.parent_part_version.value;
    	part_no=Name.substring(0,delim_loc);
    	part_version =Name.substr(delim_loc+1,3);
    	
    	switch (menuID)
    	{
    		case 1000: //Copy
    			alert ("Same function is implemented in the part list window.\r\n Please use that function.");
    			break;
    		case 1001: //Add
    			alert ("Same function is implemented in the part list window.\r\n Please use that function.");
    			break;
    		case 1002: //Cut
    			window.open ("../edit/CutPart.asp?part_no="+part_no+"&part_version="+part_version+"&parent_part_no="+parent_part_no_+"&parent_part_version="+parent_part_version_,null,"height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");	
    			break;
    		case 1003: //Replace
    			window.open ("../edit/ReplacePart.asp?part_no="+part_no+"&part_version="+part_version+"&parent_part_no="+parent_part_no_+"&parent_part_version="+parent_part_version_,null,"height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
    			break;
    	}
    //-->
    </SCRIPT>
    
    <SCRIPT language=Javascript FOR=jwTB EVENT=NodeClicked(Node,Name)>
    <!--
    /* extracts part no, version from displayed labels */
    delim_loc = Name.indexOf(" ");
    part_no=Name.substring(0,delim_loc);
    part_version =Name.substr(delim_loc+1,3);
    
    parent.doc.location = "../search/StrBrowsePart.asp?env=ASSY&part_no="+part_no+"&part_version="+part_version;
    //-->
    </SCRIPT>
    
    </HEAD>
    <body topmargin="0" leftmargin="0">
    <FORM name="frm">
      <table border="0" width="100%"  cellspacing="0" cellpadding="0">
        <tr>
          <td width="100%" height="263" valign="top" bgcolor="#FFFFFF" colspan="2">
    	<OBJECT CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331">
    		<PARAM NAME="LPKPath" VALUE="../bin/jwTreeBar_ETRI.lpk">
    	</OBJECT>	
                  		              
    	<OBJECT id=jwTB codeBase="../bin/jwTreeBar_ETRI.cab#version=1,0,0,18"
    	classid="clsid:742EFB3F-4361-42F3-89C9-5DF104EC8245" width=98% height=300>		
    	            <param name="NodeCode" value="<%=struct_str%>">
    	            <param name="NodeName" value="<%=name_str%>">
    	            <param name="OffImg" value="<%=off_img%>">
    	            <param name="OnImg" value="<%=on_img%>">
    	            <param name="TextColor" value="0,0,0">
    	            <param name="BgColor" value="255,255,255">
    	            <param name="MenuName" value="copy part;-;add part;cut part;replace parts;">
    	            <param name="IsRMenu" value="true">
    	</OBJECT>                   ¡¡           
          </td>
        </tr>
      </table>   
      <INPUT TYPE=HIDDEN NAME=parent_part_no VALUE=<%=part_no%>>
      <INPUT TYPE=HIDDEN NAME=parent_part_version VALUE=<%=part_version%>>   
      </FORM> 
    </body>
    
    </html>
    
  • Clinet Side Script - Java Script

    Client Side Script ¶õ

    Java Script ¶õ

  • ¿¹Á¦

    
    %>
    <HTML>
    <script language="javascript">
    function ch_input() {
    if((form1.path.value=="")||(form1.title.value==""))
    	{
    	alert("Á¦¸ñ°ú uploadÇÒ ÆÄÀÏ À̸§À» ÀÔ·ÂÇØ¾ß ÇÕ´Ï´Ù.")
    	form1.path.focus()
    	}
    else
    	{
    	form1.submit()
    	}
    }
    </script>
    <HEAD>
    </HEAD>
    <BODY>
    <blockquote>
    <TABLE border=0 cellpadding=4 cellspacing=1 bgcolor=gray width=80%>
    <TR><TD class=TH>À̸§<TD><%=CStr(rs("std_name"))%> 
    <TD class=TH>Çйø<TD><%=std_id%> 
    <TD class=TH>°ú¸ñ<TD> 
    <%
    rs.close
    
    query = "SELECT a.class_no, a.class_name, b.id FROM CLASS a, COURSE b, STUDENT c "
    query = query + "WHERE c.std_id='"+std_id+"' AND b.std_id = c.std_id "
    query = query + " AND b.class_id = a.class_id "
    
    Set rs = Server.CreateObject("ADODB.RecordSet")
      rs.Open query, DbCon
    
    IF rs.EOF OR rs.BOF THEN
    	response.write("<P>Á¸ÀçÇÏÁö ¾Ê´Â ¼ö¾÷ÀÔ´Ï´Ù.")
    END IF
    Response.Write("<FORM method=post action=upload.asp id=form1 name=form1 ENCTYPE='multipart/form-data'>")
    Response.Write("<SELECT NAME=course_id>")
    	DO WHILE NOT rs.EOF 
    	Response.Write("<OPTION value="+CStr(rs("id"))+">"+CStr(rs("class_name"))+"("+CStr(rs("class_no"))+")")	
    	rs.MoveNext
    	LOOP
    Response.Write("</SELECT>")
    
    %>
    
    </TABLE>
    <P>
    °ú¸ñ¶õ¿¡¼­ ÇØ´çÇÏ´Â <B>°ú¸ñ</B>À» ¼±ÅÃÇÑ ÈÄ,
    <BR>¼÷Á¦ÀÇ Á¦¸ñÀ» ÀÔ·ÂÇÏ°í ÆÄÀÏÀ»  Upload Çϼ¼¿ä.
    <TABLE border=0>
    <TR><TD>
    <TR><TD>Á¦¸ñ: <TD><INPUT TYPE=TEXT width=100 cols=100 name=title> (100ÀÚÀÌÇÏ)
    <TR><TD>ÆÄÀÏ: <TD><INPUT TYPE=FILE name=path id=path>
    <TR><TD><TD><INPUT TYPE=button value='ÀÔ·Â' id=submit1 name=submit1 onclick=ch_input()>
    
    </FORM>
    </TABLE>
    </blockquote>
    <% call footnote() %>
    </BODY>
    </HTML>
    
  • Example of a Tree menu Java Script

    DHTML °ú CSS Class 12 ÂüÁ¶

  • backwad forward Contents


    Knowledge & Engineering Databases (c) copyright Namchul Do, 2002