Professional Documents
Culture Documents
Chapter 5
Web-based Database
Application
Introduction
The development of a basic web-based database
application requires:
DBMS
HTML / CSS
Server side scripting, like JSP, PHP, ASP or etc.
JavaScript
HTML & CSS
HTML (the Hypertext Markup Language) and CSS
(Cascading Style Sheets) are two of the core
technologies for building Web pages.
HTML provides the structure of the page, CSS the
(visual and aural) layout, for a variety of devices.
Along with graphics and scripting, HTML and CSS
are the basis of building Web pages and Web
Applications.
HTML
HTML is a language for describing web pages.
HTML stands for Hyper Text Markup Language
HTML is not a programming language, it is a markup
language
A markup language is a set of markup tags
</body>
</html>
Example Explained
The text between <html> and </html> describes the web page
The text between <body> and </body> is the visible page content
The text between <h1> and </h1> is displayed as a heading
The text between <p> and </p> is displayed as a paragraph
HTML – Header & Paragraph
<html>
<body>
(From www.3schools.com)
HTML – Text Formatting Tag
(From www.3schools.com)
HTML - Link
HTML links are defined with the <a> tag.
Example:
<html>
<body>
<h3>Universiti Putra Malaysia (UPM)</h3>
<p>UPM is a Malaysia’s leading research intensive public university</p>
<a href="http://www.upm.edu.my">Click here to know more about UPM</a>
</body>
</html> Target page Clickable text
(From www.3schools.com)
HTML - Table
Tables Tags
◼ <table> ... </table>
– - define table in HTML
◼ <tr> ... </tr>
– - specifies a table row within a table
◼ <th> ... </th>
– - defines a table header cell
◼ <td> ... </td>
– - defines a table data cell
(From www.3schools.com)
Table – One Row & One Column
<html>
<body>
<table border="1">
<tr>
<td><h1>1,1</h1></td>
</tr>
</table>
</body>
</html>
(From www.3schools.com)
Table – One Row & Two Columns
<html>
<body>
<h1>One Row and Two Columns</h1>
<table border="1">
<tr>
<td><h1>1,1</h1></td>
<td><h1>1,2</h1></td>
</tr>
</table>
</body>
</html>
(From www.3schools.com)
Table – Two Rows & Two Columns
<html>
<body>
<h1>Two Rows and Two Columns:</h1>
<table border="1">
<tr>
<td><h1>1,1</td>
<td><h1>1,2</td>
</tr>
<tr>
<td><h1>2,1</td>
<td><h1>2,2</td>
</tr>
</table>
</body>
</html>
Table – Rowspan Colspan
❑ Tables – rowspan, colspan
❑ rowspan = X,
- to merge two or more rows into a single row
❑ colspan = X
- to merge two or more columns into a single column
<table border="1">
<tr>
<th>Column 1</th> <th>Column 1</th> <th>Column 1</th>
</tr>
<tr>
<td rowspan="2">Row 1 Cell 1</td><td>Row 1 Cell 2</td><td>Row 1 Cell 3</td>
</tr>
<tr>
<td>Row 2 Cell 2</td><td>Row 2 Cell 3</td>
</tr>
<tr>
<td colspan="3">Row 3 Cell 1</td>
</tr>
</table>
</body>
</html>
HTML - List
❑ HTML supports unordered, ordered and definition lists
❑ Unordered List
❑ marked with bullets (typically small black circles).
❑ starts with the <ul> tag.
❑ each list item starts with the <li> tag
❑ Ordered Lists
❑ marked with numbers.
❑ starts with the <ol> tag
❑ each list item starts with the <li> tag
❑ Definition List
❑ It is a list of items (terms), with a description of each item (term).
❑ starts with a <dl> tag (definition list).
❑ each term starts with a <dt> tag (definition term).
❑ each description starts with a <dd> tag (definition description).
Styling HTML with CSS
CSS was introduced to provide a better way to
style HTML elements.
CSS can be added to HTML in the following ways:
Inline Styles
Embedded Styles
External Styles
Imported Styles
Types of CSS
Inline Styles
◦ Configured in the body of the Web page
◦ Use the style attribute of an HTML tag
◦ Apply only to the specific element
Embedded Styles
◦ Configured in the header section of a Web page.
◦ Use the HTML <style> element
◦ Apply to the entire Web page document
External Styles
◦ Configured in a separate text file with .css file extension
◦ The HTML <link /> element in the header section of a Web page
associates it with the .css file
Imported Styles
◦ Similar to External Styles
◦ We’ll concentrate on the other three types of styles.
CSS Syntax
Style sheets are composed of "Rules" that describe
the styling to be applied.
18
CSS Syntax Sample
Configure a Web page to display blue text and
yellow background.
body { color: blue;
background-color: yellow; }
This could also be written using hexadecimal color
values as shown below.
body { color: #0000FF; background-color: #FFFF00; }
19
Inline CSS
The style attribute is used with the value of the style
rule declaration that need to be set.
Recall, declaration consists of a property and a
value.
Example on how to use inline CSS in HTML
<p style="background: blue; color: white;">A new
background and font color with inline CSS</p>
<h1 style =“color:#cc0000”>This is displayed as a red
heading</h1>
Embedded CSS
It is placed within a <style> element located in the header section of web
page.
Example on how to use embedded CSS in HTML
<html>
<head>
<style type="text/css">
p {background-color: blue; color:white;}
h1 {background-color:#cc0000;}
</style>
</head>
<body>
<h1>Embedded Styles</h1>
<p>Your page's content!</p>
</body>
</html>
External CSS
External style sheets contained in a separate file from HTML document.
The <link /> element is a self-contained tag used in the header section of
an HTML document to associate the style sheet with the Web page.
Example on how to use external CSS in HTML
<html>
<head>
<link rel="stylesheet" type="text/css" href=“myCSS.css"
</head>
<body>
<h3> A White Header </h3>
<p> This paragraph has a blue font. The background color of this page is
gray because we changed it with CSS! </p>
</body>
</html>
myCSS.css
body{ background-color: gray;}
p { color: blue; } h3{ color: white; }
Example Explanation
HTML Forms - The Input Element
Text Field
Password Field
Radio Button
Checkbox
Submit button
Text Field
Password Field
Radio Button
Checkbox
Submit Button
Drop-down List
Your Task:
Write two (2) HTML codes to produce the three following
forms.
MainMenu.html
Registration.html
SSK3408 SYSTEM
Registration Form
Display Form
Exit
Registration.html
SSK3408 SYSTEM
StudentID:
Name:
Skill: C++
Java
Pyhton
Major: Software Engineering V
36
Writing JavaScript to The HTML Document
The HTML <script> tag is used to insert a JavaScript into an HTML page.
JavaScripts can be put in the <body> and in the <head> sections of an
HTML page.
Example:
<html>
<body>
<h1>My First Web Page</h1>
<script type="text/javascript">
document.write("<p>" + Date() + "</p>");
</script>
</body>
</html>
Display a message with JavaScript
<html>
<head>
<script type="text/javascript">
alert(“Welcome to my web page!!");
</script>
</head>
<body>
</body>
</html>
JavaScript and Events
Events:
actions taken by the Web page visitor
◦ clicking (onclick),
◦ placing the mouse on an element (onmouseover),
◦ removing the mouse from an element (onmouseout),
◦ loading the page (onload),
◦ unloading the page (onunload), etc.
39
Events
mouseout onmouseout
submit onsubmit
unload onunload
40
JavaScript and Events
JavaScript can be configured to perform
actions when events occur.
The event name is coded as an attribute of an HTML tag
The value of the event attribute contains the JavaScript code
Example:
Display an alert box when the mouse is placed
over a hyperlink.
41
Form Validation
It is common to use JavaScript to validate form
information before submitting it to the Web
server.
Is the name entered?
Is the e-mail address of correct format?
42
Validating Form Fields
Use the "" or null to check to determine if a form field
has information
if (document.forms[“<form_name>”].<txtfield_name>.value == "" )
{
alert("Name field cannot be empty.");
return false;
} // end if
Example Form Validation
<html>
<head>
<script type="text/javascript">
function validateForm()
{
var x=document.forms["myForm"]["fname"].value;
if (x==null || x=="")
{
alert("First name must be filled out");
return false;
}
}
</script>
</head>
<body>
<form name="myForm" action="demo_form.asp" onsubmit="return validateForm()"
method="post">
First name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>
</body>
</html>
Your Task
Modify your HTML codes to validate Registration.html before
submitting to the web server.
SSK3408 SYSTEM
StudentID:
Name:
Scriptlet tag
Declaration Tag ( <%! %> )
This tag allows the developer to declare variables or methods.
Before the declaration you must have <%!
At the end of the declaration the developer must have %>
Code placed in this tag must end in a semicolon ( ; ).
Declarations do not generate output so they are used with JSP
expressions or scriptlets.
For Example,
<%!
private int counter = 0 ;
private String getAccount ( int accountNo) ;
%>
Expression tag ( <%= %>)
This tag allows the developer to embed any Java
expression and is short for out.println().
A semicolon ( ; ) does not appear at the end of the
code inside the tag.
For example, to show the current date and time.
<%
String coursename = “Web Application”;
out.println ( coursename ) ;
%>
SERVER SIDE SCRIPTING FOR DATA ACCESS
message = “<p><b> You could not be registered due to a system error. We apologize for any
inconvenience. </b></p><p>” + ex.getMessage()+”</p>”;
stmt.close();
conn.close();
}
}
Else {
message = message + “<p>. Please try again </p>”;
}
} End of JSP code
%>