... to client as html document. may interact with ... html head title Hello, User /title /head ... Servlets (&other tricks)can be used to maintain state ... – PowerPoint PPT presentation
Understand how processing is executed on the server for dynamic web page content
CGI scripts
Active server pages
Database access
Servlets
3 Client-Server Model 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
5 Server Side Processing
CGI server applications
Server side scripts
servlets
JDBC/ODBC
and databases
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. 7 Dynamic Content Browser Server Province NS ONT Get province from form Query database Generate tags around the query results Send this text as body of HTTP response lthtmlgt lth1gtCatalog for Ontario lth1gt ltulgt ltligtNiaga ra Falls ltligtBruce Trail ltligtGoderich lt/ulgt lt/html gt
lthtmlgt
lth1gtCatalog for NSlt/h1gt
ltulgt
ltligtBlueRocks
ltligtPeggys Cove
ltligtLunenburg
lt/ulgt
lt/htmlgt
8 CGI scripts
CGI - Common Gateway Interface
allows data from forms to be used by programs on the server
script is a program on the server
perl or C or C etc.
data returned to client as html document
may interact with a DBMS on server
9 What does an HTTP response look like?
Server response Header object file (generally)
Header object file
Plain text about data data 10 Forms and Data
Forms are part of HTML document
ltform actionhttp//www.dal.ca/doit.cgi method put gt
Price ltinput typetext namepricegt
ltinput typesubmitgt
lt/formgt
user enters data or selects options
Data from form goes to server program called
Submit Price 11 Form calling Simple CGI Example Where to find the program?
How to get data to the server Do it! 12 Script for hello2.cgi
!/opt/bin/perl
print "Content-type text/html\n\n"
print "ltheadgt\n"
print "lttitlegtHellolt/titlegt\n"
print "lt/headgt\n"
print "ltbodygt\n"
print "lth1gtHello, Ottawalt/h1gt\n"
Print ltimg srccancaphd.gifgt
print "lt/bodygtlt/htmlgt\n"
try it
Response doc type HTML doc 13 Getting at Databases
ODBC - Open DataBase Connectivity
JDBC - java based
script programs can use these to make database queries from server databases
Oracle, access, etc
results are sent back to client as html doc
14 Perl example to ORACLE
print "ltheadgt\n"
print "lt/headgt\n"
print "ltbodygt\n"
print "lth1gtCalendarlt/h1gt\n"
print "ltbgtCourse description enrollt/bgtltbrgt"
SetOracle
RunSQL("Select from Calendar")
StopOracle
print "lt/bodygtlt/htmlgt\n"
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!
16 Example Client puts tshirt in shopping cart form on web page Cart.cgi is called Makes purchase (Tshirt) Genera tes new page form Add a book Cart.cgi is called Makes purchase ( book) 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 forth
keep everything in a database
Use Servlets
gets tricky!!
18 Servlets
java applications that are part of the server
always available (faster) than cgi scripts
provide continuity (state) for clients
written in java
can use JDBC to access databases
Used for shopping, search, certificates, agents, portals
19 Other ways to process on Serverto generate dynamic data for web pages
Server side includes
Active server pages
Java server pages
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 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
22 SSI example ssitest.shtml
lthtmlgt
lth1gtGetting the date from the server as I need itlt/h1gt
lt!--echo varDATE_LOCAL --gt
lth2gt I could do other things as welllt/h2gt
ltulgtltligta stock quote
ltligtan expected wait time
ltligta price check
ltligtetc
lt/ulgt
lt/htmlgt
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!
24 Active server Page exampletest1.asp
lt_at_ LANGUAGE"VBSCRIPT" gt
ltHTMLgt
ltBODYgt
Test1
lt If Time gt 120000 AM and Time lt120000 PM then gt
PowerShow.com is a leading presentation sharing website. It has millions of presentations already uploaded and available with 1,000s more being uploaded by its users every day. Whatever your area of interest, here you’ll be able to find and view presentations you’ll love and possibly download. And, best of all, it is completely free and easy to use.
You might even have a presentation you’d like to share with others. If so, just upload it to PowerShow.com. We’ll convert it to an HTML5 slideshow that includes all the media types you’ve already added: audio, video, music, pictures, animations and transition effects. Then you can share it with your target audience as well as PowerShow.com’s millions of monthly visitors. And, again, it’s all free.
About the Developers
PowerShow.com is brought to you by CrystalGraphics, the award-winning developer and market-leading publisher of rich-media enhancement products for presentations. Our product offerings include millions of PowerPoint templates, diagrams, animated 3D characters and more.