Download Server side slides

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Open Database Connectivity wikipedia , lookup

Clusterpoint wikipedia , lookup

Team Foundation Server wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Transcript
Servers
& Server Side Processing
Winter 2001
C.Watters
1
Objectives
Understand the server’s role
Understand how processing is executed on
the server for dynamic web page content
CGI scripts
Active server pages
Database access
Servlets
Quick look at the role of agents
Winter 2001
C.Watters
2
Client-Server Model
Winter 2001
C.Watters
3
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
Winter 2001
C.Watters
4
Server Side Processing
•
•
•
•
CGI – server applications
Server side scripts
servlets
JDBC/ODBC
• and databases
Winter 2001
C.Watters
5
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
Winter 2001
socket is an abstract
representation of a network endpoint.
C.Watters
6
Dynamic Content
Browser
Server
Province ONT
NS
Get province from form
<html>
<html>
<h1>Catalog
<h1>Catalogfor
for NS</h1>
Ontario <h1>
<ul>
<ul>
<li>BlueRocks
<li>Niagara Falls
<li>Peggys Cove
<li>Bruce Trail
<li>Lunenburg
<li>Goderich
</ul>
</ul>
</html>
</html>
Winter 2001
Query database
Generate tags around the
query results
Send this text as body of
HTTP response
C.Watters
7
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
Winter 2001
C.Watters
8
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>
Submit
Price:
• user enters data or selects options
• Data from form goes to server program called
Winter 2001
C.Watters
9
Form calling Simple CGI Example
<HTML><BODY>hi
Where to find the program?
<FORM action
="http://www.cs.dal.ca/~watters/cgibin/hello2.cgi” method =post>
<Input type = "submit">
</FORM>
</BODY>
</HTML>
Winter 2001
How to get data
to the server
Do it!
C.Watters
10
Script for hello2.cgi
#!/opt/bin/perl
print
print
print
print
print
print
Print
print
Response doc type
"Content-type: text/html\n\n";
"<head>\n";
"<title>Hello</title>\n";
"</head>\n";
"<body>\n";
"<h1>Hello, Ottawa</h1>\n";
“<img src=“cancaphd.gif”>
"</body></html>\n";
HTML
doc
• try it
Winter 2001
C.Watters
11
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
Winter 2001
C.Watters
12
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";
Winter 2001
C.Watters
13
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!
Winter 2001
C.Watters
14
Server Side Example
Client puts tshirt in
shopping cart form on
web page
Cart.cgi is called
Makes purchase
(Tshirt)
Generates new page &form
Add a book
Cart.cgi is called
Makes purchase
( book)
Winter 2001
C.Watters
15
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!!
Winter 2001
C.Watters
16
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
Winter 2001
C.Watters
17
Servlets and State
 Cookies can be used to maintain information over
multiple HTTP connections
 Information on session is saved in cookie and retrieved
by servlet during the session
 Works over multiple browser sessions
 A session is a continuous connection from the
same browser (period fixed by server)
 Use HttpSession class
 Information saved over single browser session only
Winter 2001
C.Watters
18
Other ways to process on Server
to generate dynamic data for web pages
Server side includes
Active server pages
Java server pages
Winter 2001
C.Watters
19
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
Winter 2001
C.Watters
20
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
Winter 2001
C.Watters
21
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>
Winter 2001
C.Watters
22
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!
Winter 2001
C.Watters
23
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>
Winter 2001
C.Watters
24
JSP (Java server pages)
Winter 2001
C.Watters
25
• <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() %>
Winter 2001
C.Watters
26
• </UL>
Winter 2001
C.Watters
27
Winter 2001
C.Watters
28
<%@ 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>
Winter 2001
C.Watters
29
NOT the same as Active X
• Active X Components are “roughly” the
same as applets
Winter 2001
C.Watters
30
Servers and Agents
• Agent
– autonomous execution of task
• Mobile Agent
– dynamic internet routing
• Used for: comparisons, filtering, web
crawling, auctions
Winter 2001
C.Watters
31
Agent Definition
An agent is a software program that is
capable of autonomous action in its
environment in order to meet its objectives.
Winter 2001
C.Watters
32
Agent Examples
• Buyer agents and seller agents each with
goals and constraints can negotiate deals on
behalf of the users
• Agents can monitor health indicators and
alert personnel under given conditions
• Agents can run background checks
• Agents can be avatars in simulations
Winter 2001
C.Watters
33
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
Winter 2001
C.Watters
34