ServerSide Scripts - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

ServerSide Scripts

Description:

Client-side scripts run within a web ... html head meta http-equiv='Content-Type' content='text/html; charset=windows ... http://nytimes.com/story.asp?S=1031 ... – PowerPoint PPT presentation

Number of Views:70
Avg rating:3.0/5.0
Slides: 24
Provided by: chri106
Category:

less

Transcript and Presenter's Notes

Title: ServerSide Scripts


1
(No Transcript)
2
Server-Side Scripts
  • Several types of server-side scriptinglanguages
  • Examples Active Server Pages (ASP)
    PHP Cold Fusion
    Perl Java Server Pages (JSP)
  • We will focus on Active Server Pages

3
Client vs. Server-Side Scripts
  • Client-side scripts run within a web browser, on
    the client computer

4
Client vs. Server-Side Scripts
  • Client-side scripts run within a web browser, on
    the client computer

5
Client vs. Server-Side Scripts
  • Server-side scripts are processed onthe server
    then sent toclient as a flat-file.

lthtmlgtltheadgtltmeta http-equiv"Content-Type"
content"text/html charsetwindows-1252"gtlttitlegtO
klahoma's NewsChannel 4's e-Storelt/titlegtlt/headgtltf
rameset framespacing"0" border"0" rows"129,"
frameborder"0"gt
6
Active Server Pages
  • Microsoft Technology
  • Based on Visual Basic
  • Runs on PWS and IIS, but also ported to run on
    non IIS servers (iASP from ChiliSoft)
  • ASP code embedded in an otherwise normal HTML
    file, using .asp extension.

7
Active Server Pages
  • Active server pages are basically HTML documents
    with ASP script placed amongst HTML code.
  • ASP code delimited like thislta
    hrefindex.htmlgtlt asp code here gtlt/agt
  • Code can also be written in block form anywhere
    in the file, again delimited by lt and gt

8
Basic ASP Page
  • Hello World Examplelthtmlgt ltheadgt
    lttitlegtHello World!lt/titlegt lt/headgt ltbodygt lt
    Response.Write(Hello World!ltbr/gt)gtlt/bodygtlt/ht
    mlgt

9
Basic ASP Page
  • Output

10
Doing More with ASP
  • Connecting to Databases- Displaying, updating,
    inserting
  • Processing form data
  • Using cookies
  • Passing parameters from page to page
  • Interfacing with file system

11
Data Access with ASP
  • To retrieve data, using ADO
  • Create server object
  • Open connection to the database
  • Create recordset
  • Display fields of records returned in query

12
Data Access with ASP
  • ASP can access data from various data sources
  • Any ODBC data source- Access, Oracle, MS SQL
    Server, ect
  • Comma-delimited text files
  • XML files
  • Using DSN or simply directly connecting to file

13
Data Access with ASP
  • Examplelt accessdb"/data/users.mdbmyDSN"DRIV
    ERMicrosoft Access Driver (.mdb)myDSNmyDSN
    "DBQ" server.mappath(accessdb)Set Conn
    Server.CreateObject("ADODB.Connection")Conn.open
    myDSNset myRS Conn.Execute(SELECT FROM
    users WHERE firstname LIKE Chris) gtlt Do
    While Not myRS.EOF write some code here
    myRS.MoveNext Loop gtlt
    myRS.close Conn.close gt

14
Data Access with ASP
  • To Display Data in a Table Cellslttablegtlt Do
    While Not myRecordset.EOF Response.Write
    (lttrgtlttdgt) Response.Write(myRecordset(F
    irstName)) Response.Write(lt/tdgtlt/trgt)
    myRecordset.MoveNext Loop
    gtlt/tablegt

15
Data Access with ASP
  • Using SQL to Insert Recordslt set myConnection
    Server.CreateObject(ADODB.Connection)
    myConnection.Open DriverMicrosoft Access
    Driver(.mdb)
    DBQc\inetpub\wwwroot\data\user.mdb myQuery
    INSERT INTO users (userID, passwd) _
    VALUES (chrisway, easymoney)
    myConnection.Execute(myQuery) gt

16
Data Access with ASP
  • Using SQL to Update Recordslt set myConnection
    Server.CreateObject(ADODB.Connection)
    myConnection.Open DriverMicrosoft Access
    Driver(.mdb)
    DBQc\inetpub\wwwroot\data\user.mdb myQuery
    UPDATE users SET age age 1 WHERE userID
    _ uid myConnection.Execute(
    myQuery) gt

17
Processing Form Data
  • ASP scripts can read data from forms that use the
    POST method
  • Form Code Exampleltform METHODPOST
    NAMEmyForm ACTIONprocessID.aspgtltinput
    type"text" name"Contact_Name" size"20"gtltinput
    type"text" name"Contact_email"
    size"20"gtlt/formgt
  • Code from processID.asp used to read form data
    using request objectlt var1
    Request.Form(Contact_Name) var2
    Request.Form(Contact_email) gt

18
Processing URL String Parameters
  • You can pass parameters to ASP scripts though the
    URL string
  • URL Example http//nytimes.com/story.asp?S1031
  • To retrieve parameter from URL, the following ASP
    code is used (again using the Request Object)lt
    storyID Request.Querystring(s) gt
  • The storyID variable can now be used in later
    code, such as a database query.

19
Using Cookies with ASP
  • Cookies are valuable when variable values must be
    maintained over multiple pages during a user
    session.
  • When using cookies with ASP, the request to
    create a cookie must be in the header message.
  • Therefore, in an ASP script, thecookie is
    written before ANYhtml.

20
Using Cookies with ASP
  • Example code used to write a cookielt All ASP
    output is buffered on server before sent to
    clientResponse.BufferTrueResponse.Cookies(NYTL
    ogin)(userID) Request.Form(UID)Response.Co
    okies(NYTLogin)(passwd) Request.Form(PW)
    gt
  • To create a persistent cookie, weuse Expires
    propertyResponse.Cookies(NYTLogin).ExpiresDe
    c 31, 2001

21
Using Cookies with ASP
  • Example code used to READ a cookielt UID
    Request.Cookies(NYTLogin)(userID) PW
    Request.Cookies(NYTLogin)(passwd)gt

22
File system Access
  • To open and read text file exampleSet fso
    Server.CreateObject("Scripting.FileSystemObject")
    ConfigFile Server.MapPath ("something.txt")
    Set TheFile fso.OpenTextFile (ConfigFile,
    1)ALineOfText TheFile.ReadLine TheFile.Close
  • To write to a text fileSet fso
    Server.CreateObject("Scripting.FileSystemObject")
    Set ConfigFile Server.MapPath (RockFileName)
    Set TheFile fso.OpenTextFile (ConfigFile,
    2)TheFile.write Request.Form("nickname")
    vbCrLf TheFile.write Request.Form("color")
    vbCrLf TheFile.write Request.Form("type")
    vbCrLf TheFile.close

23
The End
Write a Comment
User Comments (0)
About PowerShow.com