Web Application Programming

Download Report

Transcript Web Application Programming

Web Application Programming
Carol Wolf
Computer Science
Three tiers and their languages
Client
Html
JSP, ERB
JavaScript
Server
Java, Ruby
Visual Basic
PHP, Perl
Python
Database
SQL
MVC
Model, View, Controller

Model - Database
◦
◦

View – Web page
◦

Requests sent using SQL, Structured Query Language.
Response is either an array of data or a confirmation.
Requests sent using Html or embedded programming code
(JSP, ERB, ASP)
Controller – Program on server
◦
◦
◦
Sits between the model and view.
Receives requests from the view, sends them on to the model
and sends a response back to the view.
Most critical software and trickiest to write.
HTTP
Hypertext Transfer Protocol

Http is a stateless protocol.
◦
◦

Request
◦
◦

Stateless means that nothing is remembered.
Once a response has been sent, the server forgets where it
went.
Requests are sent by the client to the server.
They can either be requests for a new page or involve a form
with parameters.
Response
◦
◦
The server sends a response page in return.
It might be a linked page or data retrieved from a database.
Methods

Get
◦
◦
◦

Used for simple requests.
Parameters are sent in the URL string.
http://localhost:3000/library/find? title ="Oliver Twist"
Post
◦
◦
◦
Parameters are sent within the packet.
Used when there are many parameters or when security is an
issue.
Rails uses only post when there are parameters.
Action



The action contains the URL of the server and the server
program to be executed.
The URL comes before the question mark and the
parameters after.
Example of a URL string:




http://localhost:3000/library/find? title ="Oliver Twist“
http is the connection protocol.
localhost:3000 is the name of the server and the access port on
the server.
library/find gives the directory (library) for the server program
and the program (find) to use in that directory.
HTML Forms

Forms consist of data fields and a submit button.
They can also have links to JavaScript code and
formatting tags.
<form method="post" action="http://localhost:3000/library/find">
<p>
<b>Book Title:</b>
<input type = "text" name="title" value = "" size = 20 />
</p>
<p><input type= "submit" value="Find a Book“ /></p>
</form>
This shows an html table containing
three forms. The form in the center
is the one on the previous slide.
Programming Languages




Java – uses Java servlets, Java Server Pages (JSP) and Java
beans.
Ruby on Rails – uses ruby programs and Embedded Ruby
(ERB).
Visual Basic – Uses VB programs and Active Server Pages
(ASP).
Others
◦
◦
◦
◦
◦
PHP (Personal Home Page – originally)
CGI (Common Gateway Interface)
Perl (Named after the parable of the pearl)
Python (Named for the Monty Python skits)
Tcl (Tool Command Language)
Java




Developed by James Gosling at Sun
Microsystems in 1991.
Java servlets on the server control
the flow between the client and the
database.
JSP (Java Server Pages) can be
embedded in the html on the web
page. They are compiled into servlets
before they are executed.
Java server pages are connected to
Java beans on the server. The beans
handle the requests and responses.
Ruby on Rails




Ruby was developed by
Yukihiro Matsumoto in 1993
and publically released in
1995.
It is a scripting language and is
fully object oriented.
It combines Perl syntax with
Smalltalk-like features.
It is said to follow the
‘principle of least surprise.’
Ruby on Rails



Rails was developed by
David Heinemeier
Hansson and released
as open source in July
2004.
It is based on the
MVC (model, view,
controller) pattern.
Programmers work on
a higher level than with
Java servlets.
Rails




Rails relies on a number of conventions.
 JSP and Java beans have some conventions, but rails has a lot
more.
Rails translates commands into SQL, saving programmers many
hassles.
Some ‘boiler plate’ is stored separately and added to web
pages when required.
 This includes web page headers, CSS (Cascading Style
Sheets) and JavaScript.
Database modifications are systematically handled by
‘migrations.’ These are ruby programs that when executed
change the database.
Servers

The principal open-source server is Apache, hosting
49% (June 2008) of all web sites.

There are many modified versions.




Apache Tomcat – used for JSP and Java beans.
Google Web Server (GWS)
IBM WebSphere
Microsoft Internet Information Services (ISS) is the
main proprietary server, hosting 35.4% of all web
sites.
Databases

Most databases use the relational model, developed
by E. F. Codd in the 1960s and ‘70s.







Data is stored in tables with rows and columns.
Queries are usually made with SQL.
Microsoft has Access for Windows computers.
MySQL is open source and has more than 11 million
installations world-wide.
Oracle is a widely used proprietary database
developed by the Oracle Corporation.
Rails comes with sqlite3.
There are many more.
Connecting to a database



Most databases are standalone programs and so require that
each time they are accessed, you must set up a new
connection.
For Java, the connection is sun.jdbc.odbc.JdbcOdbcDriver
Odbc stands for open database connection, and the ‘J’ in Jdbc
is for Java.


Odbc is a protocol from Microsoft that is based on the X/Open SQL
specification.
InstantRails comes with SQLite3. It is part of the application
and does not require a new connection for each query.
Web Browsers




The first web browser was Mosaic, released in 1993. It was
developed by the NCSA, National Center for Supercomputing
Applications. It turned into the Netscape Navigator and was
discontinued by AOL in 2007.
Microsoft’s Internet Explorer is the most widely installed
browser with around 73% of market share world-wide.
Firefox from the Mozilla Foundation has around 19% of the
usage share (August 2008).
There are a number of other browsers, including Safari for
Macs with a market share around 6%.