Lecture 14 Slides
Download
Report
Transcript Lecture 14 Slides
Programming for Beginners
Lecture 14: An Introduction to Scripting Languages
Martin Nelson
Elizabeth FitzGerald
Session 14 – aims and objectives
An introduction to scripting languages
HTML
CSS
XML/XSLT
php
Javascript
Choice of exercises – which language do you want to
use?
Web-based Programming – 1
HTML = HyperText Markup Language
CSS = Cascading Style Sheet
HTML is used to ‘mark up’ content and display it to web
browsers
HTML has presentation tags within it
e.g.
<b>this is bold text</b>
<i>this is italic text</i>
CSS contains styles for fonts, tables, background etc
Example of HTML
<HTML>
<HEAD>
<TITLE>My favourite recipe</TITLE>
</HEAD>
<BODY>
<P>Lime Jelly Marshmallow Surprise</P>
<U>My grandmother's favourite recipe!</U>
<H1>Instructions</H1>
<OL>
<LI>Prepare lime jelly according to packet
instructions.</LI>
</OL>
</BODY>
</HTML>
An example of CSS
p {
font-family: Verdana, Arial, Helvetica, sans-serif;
color: #050505;
font-size: 11pt;
}
h1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 13pt;
font-style: italic;
text-decoration: underline;
color: #006699;
margin-bottom: 0pt;
}
Web-based Programming – 2
XML = eXtensible Mark-up Language
XSLT = eXtensible Style Language Transformation
XML allows users to define their own specific tags
e.g.
<book>Guide to Programming</book>
XSLT transforms the tags into HTML and provides rules
for presentation
An example of XML
<?xml version="1.0"?>
<USERSUPPORTML>
<HEADING>Neville Computers - User Support</HEADING>
<SUBHEADING>Hints and tips</SUBHEADING>
<PARA>It has come to our attention that a small percentage of customers
are having problems configuring the Neville Excel computer system. Below
are some handy hints that will have you back on the web in a
jiffy.</PARA>
<ULIST>
<LISTITEM>Do not paint your computer. Wallpaper is also a bad
idea.</LISTITEM>
<LISTITEM>Power interuptions can damage computers. If you live in an area
with a fluctuating power supply be sure to purchase a generator for
backup purposes. If you cannot afford a generator then consider buying a
treadmill and a hamster</LISTITEM>
<LISTITEM>Never let your hamster use your computer. Small rodents are
messy and cheat at games</LISTITEM>
</ULIST>
<PARA>If you are still having problems please refer to our handy
troubleshooters guide.</PARA>
</USERSUPPORTML>
An example of XSLT
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="USERSUPPORTML">
<html>
<head>
<title>Neville User Support</title>
</head>
<body background="tile.jpg">
<xsl:apply-templates/>
<hr width="100%"/>
</body>
</html>
</xsl:template>
<xsl:template match="HEADING">
<center><h1><xsl:value-of select="."/></h1></center>
<hr width="100%"/>
</xsl:template>
<xsl:template match="ULIST">
<ul>
<xsl:for-each select="LISTITEM">
<li><xsl:value-of select="."/></li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
Web-based Programming – 3
CGI = Common Gateway Interface
Specification for transferring data between a web server and a
CGI program
Not a programming language in itself
CGI programs are designed to accept and return data
Used for creating dynamic web pages
Processing of data occurs on the server and is known as serverside solutions (c.f. client-side solution)
Web-based Programming – 4
php = PHP Hypertext Preprocessor
One of many languages used for CGI scripts
Especially good for database interaction and creating dynamic
web pages
User cannot view the PHP code
ASP = Active Server Pages
Utilises ActiveX scripting (usually VBScript or JScript)
Creates dynamic web pages based on user interaction
Similar to CGI scripts but enable Visual Basic programmers to
work with familiar Microsoft tools
An example of php
#!/usr/local/bin/php
<html>
<head>
<title>PHP-DB script</title>
</head>
<body>
<?php
$connection = mysql_connect(“sql-servername",“username",“password");
mysql_select_db(“dbname",$connection);
$result = mysql_query ("SELECT * FROM user", $connection);
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
foreach ($row as $attribute)
print "{$attribute} ";
print "\n";
}
?>
</body>
</html>
Web-based Programming – 5
JavaScript
Scripting language developed by Netscape
Allows authors to design interactive sites
NOT THE SAME AS JAVA
Can interact with HTML source code
IE supports Jscript (a subset)
JavaScript contains lines of executable computer code
JavaScript is usually embedded directly in HTML pages
An Example of Javascript
<html>
<body>
<script type="text/javascript">
document.write("Hello World!")
</script>
</body>
</html>
Web-based Programming – 6
VBScript
Short for Visual Basic Scripting Edition
Scripting language developed by Microsoft
Based on Visual Basic but much simpler
Similar to JavaScript
Allows web authors to include interactive controls
e.g. buttons, scrollbars etc on their webpages
Exercises
Choice of exercises for the rest of today’s session:
Continue to work on your Java Address Book.
Try one or more of the markup languages discussed
today:
HTML
Javascript
php
Continue with the C++ exercises from last session.
Pick whichever language you prefer!
Coming up in Session 15
A brief discussion of some more-advanced programming
concepts.
Where to go next? Future programming courses...