4 Internet Programming
4 Internet Programming
4. Internet Programming
1
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
Reference
H.M. Deitel, P.J. Deitel and T.R. Nieto, Internet
and World Wide Web: How to Program, Prentice
Hall, 2002
2
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
3
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
Internet Programming
Web service is a kind of client / server process
Need interaction between client and server
Programming for providing Web service can
also be divided into
– Client-side programming: to define the operation to
be performed on the client’s machine
– Server-side programming: to define the operation to
be performed on the server
4
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
Internet
Database Web Server Web Client
Server-side Programming Client-side Programming
Skills that are often required: Skills that are often required:
• CGI • XHTML
• PHP • Javascript
• ASP • Java
• Perl • Dreamweaver
• Java Servlet, … • Flash
• SMIL, XML …
5
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming - XHTML
6
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming - XHTML
What is XHTML?
Unlike procedural programming languages, e.g. C,
C++, XHTML is a markup language that specifies the
format of document to be seen in browser
XHTML has replaced the HTML as the primary means
of describing the Web page content
Become a World Wide Web Consortium (W3C)
recommendation
– W3C is an industry consortium
– Seeks to promote standards for the evolution of the Web and
interoperability between WWW products by producing
specifications and reference software
Compared with HTML, XHTML provides more robust,
richer and extensible features
8
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming - XHTML
Features of XHTML
Platform independent
– The same piece of code can give the same display in Mac,
Linux and Windows
Text-based
– Program is written with ASCII characters
– Can be written using a text editor, such as notepad
An XHTML file must have an extension of .html or .htm
Information is generally enclosed inside paired tags
– E.g. <html> … </html>
– There are many tags in XHTML. They specify different
information required to display the Web page content
13
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
Tags
Tags: case sensitive
– For XHTML, <center> is different from <CENTER>
– For HTML, it is case insensitive
Browse will not display information within tag that does
not understand
Tags: no precise positioning
Many start tags define attributes that provide additional
information
E.g. <html xmlns = "http://www.w3.org/1999/xhtml">
15
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
</body>
</html>
16
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
17
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
Meta Tag
HTML interacts with the search engines
through using meta tag
These words are compared
with words in search requests
<head>
<meta name=“keywords” content=“lecture notes, html,
form, feedback”>
<meta name=“description” content = “this web site
describes …”>
</head>
Description of a page seen on searching
18
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
Linking Webpage
One of the most important XHTML features is
the hyperlink
– Link to another resources, such as web page, image,
etc.
Achieve by using the anchor tag <a>:
– To a web page:
<a href=“http://www.eie.polyu.edu.hk”>PolyU</a>
anchor attribute The name on the Web
page that represents this
Value of the attribute:
link
19 The address of the Web page
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
strong tag lets the text to be
<body> displayed with bold font
<h1>Here are my favorite Other similar tags include
sites</h1> <u> underline and <em> italic
<p><strong>Click a name to go to that page.
</strong></p>
Four links create
<!-- Create four test hyperlinks -->
21
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
Linking Images
Background Image can be defined as an
attribute of the body tag:
<body background=“image.gif”>
To show an Image inside a page:
<img src=“image.gif” border=“0” height=“256”
width=“256” alt=“text description of the image”/>
We can create an image hyperlink
<a href=“page1.html”>
<img src=“image.gif” …/>
</a>
23
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
25
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
Color
2 ways to specify:
– Use hexadecimal numbers
– RGB format: FF: strongest, 00 weakest
#FF0000
#00FF00
#0000FF
– Use color names
Black, White, Red, Cyan, Green, Purple,
Magenta, Blue, Yellow, OrangeRed,
SpringGreen, BlueViolet, Gold, DarkGoldenrod,
Burlywood, …
26
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
Color
Background color:
– <body bgcolor=“#00FF00”> … </body>
– <body bgcolor =“green”> … </body>
Text color, links, visited links and activated links:
– <body bgcolor =“white” text=“black” link=“purple”
vlink=“blue” alink=“yellow”>
Font color:
– <font color=“green”> … </font>
27
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
Formatting Text
The format of displayed text can be changed by using
<font> … </font>
Attributes:
– Color:
– Size:
Relative: +1, +2, -3, …
Absolute: 10, 12, …
– Face:
Font used
Arial, Verdana, Helvetica, Times, …
Multiple fonts:
size = 24
default size
30
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
Lists
Unordered list
– a list that does not order its items by letter or number
– <ul> … </ul> creates a list where each item begins
with a bullet
– List items: <li> … </li>
– For example
<ul>
<li>Apple</li>
<li>Orange</li>
<li>Banana</li>
</ul>
31
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
Lists
Ordered list
– List that order their items by letter
or number
– <ol type=“style”> … </ol>
When style equals to
1: decimal, 1, 2, 3, …
I: uppercase Roman, I, II, III, …
i: lowercase Roman, i, ii, iii, …
A: uppercase Latin, A, B, C, …
a: lowercase Latin, a, b, c, …
Table
Organize data into rows and columns
Table caption
Table header
Table body
Table footer
33 Table border
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
<caption><strong>Price of Fruit</strong></caption>
<thead>
<tr> <!-- <tr> inserts a table row -->
<th>Fruit</th> <!-- insert a heading cell -->
<th>Price</th>
</tr> The use of th tag
</thead> defines the
The tr tag insert content of header
<tbody> a new row or footer cells
<tr>
<td>Apple</td> <!-- insert a data cell -->
<td>$0.25</td>
35 </tr>
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
<tr> <tfoot>
<td>Orange</td> <tr>
<td>$0.50</td> <th>Total</th>
</tr> <th>$3.75</th>
<tr> </tr>
<td>Banana</td> </tfoot>
<td>$1.00</td> </table>
</tr>
<tr>
<td>Pineapple</td>
<td>$2.00</td> The use of th tag
</tr> defines the
</tbody> The use of td tag
defines the content of header
content of body or footer cells
36 cells
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
37
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
38
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
<table border=“1” width=“60%”>
<caption> Average Grades </caption>
<tr>
<th colspan=“4”> Report </th> first row
</tr>
<tr>
<th> </th> <th> 2000 </th> <th> 2001 </th>
<th> 2002 </th>
</tr> 2nd row
<tr>
<td> Maths </td> <td> A </td> <td rowspan=“2”
valign=“center”> B </td> <td> C </td>
</tr>
vertical alignment 3rd row
<tr>
<td> English </td> <td> C </td> <td> A </td>
</tr>
4th row
39 </table>
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
40
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
Forms
When browsing
web sites, users
often need to
provide information
such as email
address, search
keywords, etc
Forms allows user
to input information
41
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
App CGI
Internet
Web Server Web Client
1
www.abc.com/form.htm
2
www.abc.com
method = post or get
3
action = program name
(script) in server to
receive the data
Name = ???
42 and others
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
43
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
Forms
Elements inside a form are introduced by the
<input> tag
<input>
– type=“hidden” name=“variable name”
value=“value that sends to the server”
– type =“text” name=“” value =“” size=“25”
– type =“submit” value =“”
– type =“reset” value =“”
– type =“checkbox” value =“” name=“”
45
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
Thing that sends back to server
Form example I
<input type=“checkbox” name=“things”
value=“ham”/> Ham
<input type=“checkbox” name=“things”
value=“sweetcorn”/> Sweet Corn Indicate all 5
<input type=“checkbox” name=“things” checkboxes
value=“mushroom”/> Mushroom belong to the
<input type=“checkbox” name=“things” same group
value=“chicken”/> Chicken
<input type=“checkbox” name=“things”
value=“peas”/> Peas
46
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
Form example II
Data that would send to
server but do not display on
screen
<p><label>Name:
<input type= "text" name= "name" size="25"
maxlength="30"/>
</label>
</p>
send the input the textbox to server
<input type= "submit" value="Submit your entries"/>
<input type= "reset" value="Clear Your Entries"/>
47 clear the content of textbox
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
Masked by asterisk
Space is counted here
<p><label>Comments:<br />
<textarea name= "comments" rows="4" cols="36">
Enter your comments here.
</textarea> </label></p>
<p><label>Please input your password:
<input name= "secret" type="password" size="25"/>
</label></p>
<input type= "submit" value="Submit Your Entries"/>
48
<input type= "reset" value="Clear Your Entries"/>
ENG224
INFORMATION TECHNOLOGY – Part I
4. Internet Programming
Form example IV
The “selected” value here
mean Amazing is selected
default value
<p><label>Rate our site:
<select name= "rating">
<option value=“Amazing”
selected="selected">Amazing</option>
<option value=“3”>3</option>
<option value=“2”>2</option> Change to default
<option value=“1”>1</option> value when reset
<option value=“0”>0</option>
</select></p>
<input type= "submit" value="Submit Your Entries"/>
<input type= "reset" value="Clear Your Entries"/>
49