Title: Inleiding webprogrammeren
1Inleiding webprogrammeren
- voor
- OGO 2.2
- door
- Reinier Post
- HG 7.71
- e-mail r.d.j.post_at_tue.nl (niet r.post_at_tue.nl)
2Web technology overview
- What is the Web?
- What do we need the Web for?
- What is the Web made of?
- How does a user interact with the Web?
- What does a webserver do?
- What is a webserver made of?
- Some technologies for webserver programming
- Web-specific development issues
3What is the Web?
- The World Wide Web a set of software techniques
to support interlinked documents and applications
on the Internet, standardized by the W3
Consortium. - It is client/server technology
- documents and applications reside on the server
- the user has a client program that connects to
the server - Clients include web browsers, robots, proxies.
- Servers include webservers, FTP servers, other
servers.
4What do we need the Web for?
- to publish collections of documents, e.g.
documentation/support - as a platform for user communities, e.g.
discussion forums - as an interface to databases and other
applications - ()
5The Web as a universal user interface
- Webservers can be used to interface with
- local collections of files
- relational databases (by speaking SQL to them)
- mail servers, mailing lists
- other webservers (proxies, rewriting proxies)
- ()
- any application !3
- The webbrowser and webserver implement the user
interface.
6What is the Web made of?
- the World Wide Web a specific set of software
techniques, including - document addresses (URLs)
- document formats that support URLs (HTML, XML)
- the HTTP client/server communication protocol
7How does a user interact with the Web? (1)
- The client program receives the order to retrieve
a URL e.g. http//cgi.tue.nl/cgi-bin/WebPh?namep
ost - It determines from the URL
- the communication protocol to use (here HTTP)
- the server host to communicate with (here
cgi.tue.nl) - The client starts communication with that host,
using the remainder as extra information. (Here
it uses HTTP to ask cgi.tue.nl to return the
document Web.ph?namepost .)
8How does a user interact with the Web? (2)
- The server host responds
- it interprets the request from the client
- it prepares a document in response
- it sends the document back to the client, with
some extra info - The client finishes
- it receives and interprets the response
- it decides what to do with the received document,
based on the extra info - it does it (e.g. a browser usually displays the
document)
9How does a user interact with the Web? (3)
- This describes a stateless protocol (e.g. HTTP).
- There is a request with a response.
- By contrast, in a stateful protocol (e.g. FTP,
SSH, telnet, ) we have - client connects to server
- server accepts a session is established
- client and server exchange many messages
- the session can remain open indefinitely / it can
be closed at some point
10The HTTP protocol
- HTTP is a stateless client/server protocol for
the World Wide Web - The word webserver means HTTP server.
- 3 versions HTTP/0.9, 1.0, 1.1 (1.1 has
extensions to support sessions) - HTTP defines
- the format of a request
- the format of a response
11A HTTP request
- a HTTP request consists of
- a path (e.g. /Web.ph?namepost)
- the method to use (usually, GET)
- input data (if the method is POST or PUT)
- headers, e.g.
- the name of the client software
- the types of documents the client is prepared to
handle - the Internet address of the clients computer
- extra information to link this request to a
previous one (a cookie)
12A HTTP response
- a HTTP response consists of
- headers, e.g.
- MIME document type (e.g. plain text, HTML , PNG
image, Excel spreadsheet) - document length
- last modification time
- reusable? (if the client should need this
document again, can it reuse this copy?) - a cookie
- content (the document itself)
13What does a webserver do?
- receive a HTTP request
- decide how to handle it
- if it refers to a plain file on the file system
- find the file
- open it, read it
- if it refers to a built-in document generator
- call it with the right arguments
- read the output
- if it refers to an external program that
generates documents - find it, open it, call it with the right
arguments - read the output
- generate (extra) response headers
- pass result back to client as a HTTP response
14What does a webserver do? (example)
- URL http//cgi.tue.nl/cgi-bin/WebPh?namepost
- webserver the HTTP server on cgi.tue.nl
- receive the request, parse it method GET,
argument string /WebPh?namepost - decide how to handle it
- it refers to an external program WebPh that
generates documents - call it with the argument string namepost, read
the output - generate (extra) response headers
- e.g. last modified now, reusable no, document
type HTML - pass output back to client as a HTTP response
15What is a webserver made of?
- core functionality
- e.g. serving files from the filesystem
- simple built-in document generators
- e.g. error messages, status messages, directory
indexes - interface with external document generator
programs - CGI
- special modules for document generation
- ASP, PHP, Java servlets, etc.
16Webserver software examples
- Apache
- very popular
- free, open source
- written for Unix/Linux, also available on MS
Windows - server-side programming support for Perl, PHP,
Java, etc. - IIS
- very popular, but limited to MS Windows platform
- closed source, Microsoft only (comes with MS
Windows Server) - server-side programming with ASP, ASP.NET (in
VB, Perl, C, etc.) - many others (see webserver surveys 1, 2)
17CGI Common Gateway Interface
- CGI a standard way to call external programs
from a webserver - Such a program is usually called a CGI script,
but it can be any executable program. - The program receives the HTTP request
information. - It returns the document content and (optionally)
HTTP response headers.
18CGI examples
- CGI scripts can be written in any programming
language. - CGI script examples (use View Source to see the
exact output) - with source code (if MS IE doesnt display the
source code as text, use View Source to see it)
19Web programming which language to use?
- In general, instead of Perl, you can use any
language that - has more or less decent syntax and semantics
- provides a good range of libraries for the things
you need to do - installs and runs smoothly on the platform you
choose to use - provides good support forums and sites to answer
your questions - Examples VBA, Java, PHP, Python, C.
- Non-examples C, C, Bourne shell, LISP,
assembler.
20example webprogramming language Perl
- general-purpose scripting language
- popular on Unix, also runs on MS WIndows
- compare Unix shells, Tcl, Python, Ruby, MS VB,
PHP, Java, C/C - very flexible syntax (write-only)
- very many libraries (CPAN)
- details www.perl.org
21Web programming in Perl interfacing with the
webserver
- possible ways to connect a Perl program with a
webserver - using CGI
- via Apaches mod_perl
- faster
- better integration with server
- via IISs ASP
- (same advantages)
- other (e.g. a webserver in Perl)
- (not popular these days)
22Web programming in Perl manually
- Decode request into data structure
- Read input data, interpret arguments
- Do the processing (e.g. talk to a database
server) - Construct the output document content (usually
HTML) - Print output headers and content
- How?
- do it from scratch with string parsing and print
statements? only a good idea for very simple
programs - find libraries that do all the dirty work for
you! - use output templates, components, or website
management systems
23Web programming in Perl libraries
- the CGI.pl CGI library (argument processing,
output construction) - the URI (URL) library (processing document
addresses) - HTML processing libraries (output construction)
- Apache interfacing libraries (to control the
server from the program) - LWP web client library (to talk to web servers
from your program) - DBI database processing (to talk with SQL
database servers) - Template systems, document component systems (for
more advanced webserver programming) - XML libraries (for standardized data exchange
between programs)
24Output template technology (ASP, PHP, JSP, SSI, )
- template output document with holes that
contain executable code - Examples of template languages
- ASP (executable code in VB, Perl, etc.), ASP.NET
- PHP (executable code in the PHP language)
- SSI (for Apache very primitive language for
executable code - Cold Fusion (special purpose webserver language)
- TemplateToolkit, HTMLMason (for Perl)
- JSP (for Java)
25Server Side Includes
- SSI (http//httpd.apache.org/docs/mod/mod_include.
html) - PHP (http//www.php.net/)
- ASP (http//stardeveloper.com8080/articles/041600
-1.shtml) - JSP (http//java.sun.com/products/jsp/index.html)
- XSP (http//xml.apache.org/cocoon/xsp.html)
- ColdFusion (http//www.macromedia.com/software/col
dfusion/)
26example webprogramming language PHP
- Special web programming language.
- popular on Unix/Apache
- comparable to Perl/mod_perl, ASP/VB,
JSP/servlets, etc. - Perl-like language, but simpler (PHP vs. Perl)
- ASP-like, with special language (PHP vs. ASP)
27PHP has built-in functions for
- SQL DB access
- XML
- Web client functions
- URLs treated as files
- Cookies
- File compression
- everything Perl has
- multi-language, translation (gettext)
- etc.
28PHP examples
- my own examples (source code)
- IMP (mail client)
- phpMyAdmin (MySQL db administration) (see main
site) - phpGroupWare (content management system)
- PostNuke (content management system)
- SourceForge (example of home-grown website based
on popular open source software also a great
software resource)
29PHP versus CGI/Perl
- PHP
- GPL, www.php.net
- IIS / Apache / as CGI
- interpreted / JIT is supported
- no components GTK for GUI
- HTML (or anything) embedded PHP
- lt?php tag ?gt
- CGI/Perl
- free, www.activestate.com
- runs everywhere
- CGI has huge overhead Perl is JIT compiled
- no components Tk / GTK for GUI
- no standard for embedding code
- no tags
30ASP
- Microsoft product
- Extends HTML pages
- Tags lt and gt
- Uses VBScript, PerlScript (Perl) or Jscript
- Built-in objects Application, ASPError, Request,
Response, Server, Session
31JSP
- SUN standard
- For HTML or XML
- Tags lt, lt!, lt, lt_at_ page, etc.
- XML extensions
- predefined ltjspsetProperty .. /gt, etc.
- custom
- Uses JAVA
- Gives access to Servlet packages
32ASP versus JSP
- ASP
- Microsoft license
- IIS or PWS
- Interpreted
- ActiveX components
- HTML
- Fixed tags
- JSP
- SUN open standard
- Apache, etc.
- Compiled (JIT)
- JavaBeans
- HTML, XML
- Extensible tags
33XSP
- For XML documents
- Uses translation to byte code (JAVA)
- Tags xsppage, xsplogic, xspexpr,
xspcontents, etc. - Implementation Cocoon servlet (Apache)
- N-level processing
- Mixing of producers
34JSP versus XSP
- JSP
- SUN
- HTML XML
- Generates servlets
- No mix allowed
- XSP
- Apache
- XML
- Generates producers
- Cooperates with XSL
35component-based web programming
- Used in ready-made webprogramming systems.
- The website is programmed by extending existing
components or plugins. - A component occupies a position on the screen and
implements specific functionality. - Conceptually much superior to template-based
programming. - Many systems exist, not always very mature.
36content management systems
- Ready-to-install software packages.
- A content management system allows the website
content to be maintained without any programming. - This is still an illusion, so any decent system
is extensible, template/component based, and
comes with source code. - Many different systems exist no clear winners
yet.
37Web-specific development issues (1)
- Access control on server
- - separation of authors
- source of authentication info
- OS, general database, special database?
- - abuse / intrusion
- - use access permissions of OS
- - run programs in jail to restrict
resources - - manual checking / following
-
38Web-specific development issues (2)
- Overflow of resources
- - limits on resources
- - automatic cleanup
- - manual checking / following
-
39Web-specific development issues (3)
- Access control for client
- simple password or domain based user
authentication - truly secure transactions SSL
40Web-specific development issues (4)
- Session management
- Via URL
- Via cookies
-
41Web-specific development issues (5)
- How to test the software you write
- Run program outside webserver environment
- Use server facilities for debugging
42Web-specific development issues (6)
- What to use for programming the user interface?
Options - plain HTML (which version?)
- HTML CSS
- XML XSL
- client-side scripting (Javascript, Java applets,
Flash, plugins, ActiveX)
43Web-specific development issues (8)
- Server-side programming
- pick a language with good web programming support
- how to interface with the server? (see earlier
slides) - low performance, simple interaction CGI
- more demanding sites integrated programming
support (Apache modules, ASP, etc.)