fall 2000c.watters1 world wide web and e-commerce servers & server side processing

31
Fall 2000 C.Watters 1 World Wide Web and E-Commerce Servers & Server Side Processing

Upload: derick-collins

Post on 19-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 1

World Wide Web and E-Commerce

Servers & Server Side Processing

Page 2: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 2

Objectives

Understand the server’s roleUnderstand how processing is executed on

the server for dynamic web page content

CGI scriptsActive server pagesDatabase accessServlets

Page 3: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 3

Client-Server Model

Page 4: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 4

HTTP Connection

• 1. Client – makes an HTTP request for a web page– makes a TCP/IP connection

• 2. Server accepts request– Does any processing required – sends page as HTTP response

• 3. Client downloads page• 4. Server breaks the connection

Page 5: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 5

Server Side Processing

• CGI – server applications

• Server side scripts

• servlets

• JDBC/ODBC • and databases

Page 6: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 6

Servers• What does a server actually do

• 1.gets up and running in “listening mode”• creates a socket bound to its IP address & waits

• 2. Handles requests• detects attempt by client to connect

• creates a new socket for communication with client

• processes request– retrieve file

– run cgi script

• closes socket

socket is an abstract representation of a network endpoint.socket is an abstract representation of a network endpoint.

Page 7: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 7

Dynamic Content

<html>

<h1>Catalog for NS</h1>

<ul>

<li>BlueRocks

<li>Peggys Cove

<li>Lunenburg

</ul>

</html>

Get province from form

Query database

Generate tags around the query results

Send this text as body of HTTP response

Province NS

Browser Server

ONT

<html>

<h1>Catalog for Ontario <h1>

<ul>

<li>Niagara Falls

<li>Bruce Trail

<li>Goderich

</ul>

</html>

Page 8: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 8

CGI & scripts

CGI - Common Gateway Interfaceallows data from forms to be used by

programs on the serverscript is a program on the server

perl or C or C++ etc.

data returned to client as html documentmay interact with a DBMS on server

Page 9: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 9

What does an HTTP response look like?

• Server response = Header + object file (generally)

Header object file Plain text about data data

Page 10: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 10

Forms and Data• Forms are part of HTML document<form action=“http://www.dal.ca/doit.cgi” method = put >

Price: <input type=“text” name=“price”><input type=“submit”>

</form>

• user enters data or selects options• Data from form goes to server program called

SubmitPrice:

Page 11: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 11

Form calling Simple CGI Example

<HTML><BODY>hi<FORM action ="http://www.cs.dal.ca/~watters/cgi- bin/hello2.cgi” method =post>

<Input type = "submit"></FORM>

</BODY></HTML>

Do it!

Where to find the program?

How to get data to the server

Page 12: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 12

Script for hello2.cgi#!/opt/bin/perl

print "Content-type: text/html\n\n";print "<head>\n";print "<title>Hello</title>\n";print "</head>\n";print "<body>\n";print "<h1>Hello, Ottawa</h1>\n";Print “<img src=“cancaphd.gif”>print "</body></html>\n";

• try it

Response doc type

HTMLdoc

Page 13: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 13

Getting at Databases

ODBC - Open DataBase ConnectivityJDBC - java basedscript programs can use these to make

database queries from server databases Oracle, access, etc

results are sent back to client as html doc

Page 14: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 14

Perl example to ORACLE

print "<head>\n";print "</head>\n";print "<body>\n";print "<h1>Calendar</h1>\n";print "<b>Course description enrol</b><br>";

&SetOracle;&RunSQL("Select * from Calendar");&StopOracle;

print "</body></html>\n";

Page 15: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 15

BEING STATELESS!!

• Each http call is a new connection

• SO??– A new version of your script is run each time– No memory of previous events– pretty hard to implement a shopping cart when

it gets emptied everytime you contact the server!

Page 16: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 16

Example

Client puts tshirt inshopping cart form on

web page Cart.cgi is called Makes purchase

(Tshirt)Generates new page &form

Add a bookCart.cgi is calledMakes purchase

( book)

Page 17: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 17

Maintaining State in a Stateless Systems

Use your script to write data to a temporary file on the server and to start each time by reading any data in that file

use javascript to process activities in a given session and send results to server at end only

Hide data in forms and send it back and forthkeep everything in a databaseUse Servletsgets tricky!!

Page 18: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 18

Servlets

java applications that are part of the server always available (faster) than cgi scriptsprovide continuity (state) for clientswritten in javacan use JDBC to access databases

Used for: shopping, search, certificates, agents, portals

Page 19: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 19

Other ways to process on Serverto generate dynamic data for web pages

Server side includes

Active server pages

Java server pages

Page 20: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 20

Server Side Include Files

• Server Side Includes (.shtml)

• Active Server Pages (.asp)

• Java Server Pages (.jsp)

These functions are performed before any data are sent to the browser

Page 21: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 21

Server Side Includes (SSI)

• Shtml extension

• What happens:– Server gets request for a page (.shtml)– Server checks the page for SSI commands– Server executes those commands and inserts

new values into the page– Server sends the new page to the Browser

Page 22: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 22

SSI example: ssitest.shtml

<html><h1>Getting the date from the server as I need it</h1>

<!--#echo var=“DATE_LOCAL” -->

<h2> I could do other things as well</h2><ul><li>a stock quote<li>an expected wait time<li>a price check<li>etc</ul> </html>

Page 23: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 23

Server Pages

• Active Server Pages (microsoft) .asp

• Java Server Pages (Sun) .jsp

• Instructions for the server are included in the web page

• The server notices the extension and looks for those instructions and executes them!

Page 24: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 24

Active server Page example:test1.asp<%@ LANGUAGE="VBSCRIPT" %>

<HTML>

<BODY>

Test1

<% If Time >= #12:00:00 AM# and Time <=#12:00:00 PM# then %>

<h3>Good Morning Ottawa</h3>

<% else %>

<H3>Hello Everyone</H3>

<% end If %>

</BODY>

</HTML>

Page 25: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 25

JSP (Java server pages)

Page 26: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 26

• <UL>• <LI><B>Expression.</B><BR>• Your hostname: <%= request.getRemoteHost() %>.• <LI><B>Scriptlet.</B><BR>• <% out.println("Attached GET data: " +• request.getQueryString()); %>• <LI><B>Declaration (plus expression).</B><BR>• <%! private int accessCount = 0; %>• Accesses to page since server reboot: <%= ++accessCount

%>• <LI><B>Directive (plus expression).</B><BR>• <%@ page import = "java.util.*" %>• Current date: <%= new Date() %>• </UL>

Page 27: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 27

Page 28: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 28

Page 29: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 29

<%@ page import="hello.NameHandler" %>

<jsp:useBean id="mybean" scope="page" class="hello.NameHandler" /> <jsp:setProperty name="mybean" property="*" />

<html> <head><title>Hello, User</title></head> <body bgcolor="#ffffff" background="background.gif">

<%@ include file="dukebanner.html" %> <form method="get"> <input type="text" name="username" size="25"><br> <input type="submit" value="Submit"> <input type="reset" value="Reset"> </form> <% if ( request.getParameter("username") != null ) {%>

<%@ include file="response.jsp" %>

<% } %> </body> </html>

Page 30: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 30

NOT the same as Active X

• Active X Components are “roughly” the same as applets

Page 31: Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing

Fall 2000 C.Watters 31

Recap

• Servers process browser requests• CGI can be used to run applications on the server from

web pages including accessing DBMS data• Servers are naturally stateless• Servlets (&other tricks)can be used to maintain state• Server side includes can be used to dynamically create

web page content before sending the page to the browser

• Agents are little independent pieces of software