Introduction
/ CSS
Server side scripting, like JSP, PHP, ASP or etc.
JavaScript
HTML
Example of HTML
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</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
</body>
</html>
(From www.3schools.com)
Tag
DESCRIPTION
<b>
<big>
<em>
<i>
<small>
<strong>
<sub>
<sup>
<ins>
<del>
<s>
<strike>
<u>
(From www.3schools.com)
HTML - Link
Target page
Clickable text
(From www.3schools.com)
HTML - Table
Tables Tags
<table> ... </table>
(From www.3schools.com)
<table border="1">
<tr>
<td><h1>1,1</h1></td>
</tr>
</table>
</body>
</html>
(From www.3schools.com)
<table border="1">
<tr>
<td><h1>1,1</h1></td>
<td><h1>1,2</h1></td>
</tr>
</table>
</body>
</html>
(From www.3schools.com)
Types of CSS
Inline Styles
Embedded Styles
External Styles
Imported Styles
CSS Syntax
15
16
Inline CSS
Embedded CSS
External CSS
myCSS.css
body{ background-color: gray;}
p { color: blue; } h3{ color: white; }
HTML FORMS
Example Explanation
Text Field
Password Field
Radio Button
Checkbox
Submit button
Text Field
Password Field
Radio Button
Checkbox
Submit Button
Drop-down List
Your Task:
Registration Form
Display Form
Exit
Registration.html
SSK3408 SYSTEM
StudentID:
Name:
Gender:
Male
Skill:
C++
Java
Pyhton
Major:
Female
Software Engineering
V
Reset
Submit
Back
JavaScript
Example:
<html>
<body>
<h1>My First Web Page</h1>
<script type="text/javascript">
document.write("<p>" + Date() + "</p>");
</script>
</body>
</html>
Events:
actions taken by the Web page visitor
36
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.
Events
Event
click
Event Handler
onclick
load
onload
mouseover
onmouseover
mouseout
onmouseout
submit
onsubmit
unload
onunload
37
Example:
Display an alert box when the mouse is
placed over a hyperlink.
<a href="home.htm" onmouseover="alert('Click to go home')">Home</a>
38
Function
function <function_name>()
{
... JavaScript statements
}
39
Using Functions
Defining the Function
40
function showAlert()
{
alert("Please click OK to continue.");
}
Confirm Box
<html>
<head>
<script type="text/javascript">
function show_confirm()
{
var r=confirm("Press a button!");
if (r==true)
{
alert("You pressed OK!");
}
else
{
alert("You pressed Cancel!");
}
}
</script>
</head>
<body>
<input type="button" onclick="show_confirm()" value="Show a confirm box" />
</body>
</html>
Prompt Box
<html>
<head>
<script type="text/javascript">
function show_prompt()
{
var name=prompt("Please enter your name","");
if (name!=null && name!="")
{
document.write("Hello " + name + "! How are you today?");
}
}
</script>
</head>
<body>
<input type="button" onclick="show_prompt()" value="Show prompt box" />
</body>
</html>
Form Validation
44
{
alert(Field cannot be empty.");
return false;
}
Example
<html>
<head>
<script type="text/javascript">
function validateForm()
{
var x=document.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>
Example
<html>
<head>
<script type="text/javascript">
function validateForm()
{
if (( document.myForm.gender[0].checked == false ) && ( document.myForm.gender[1].checked == false ) )
{
alert ( "Please choose your Gender: Male or Female" );
return false;
}
}
</script>
</head>
<body>
<form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post">
Gender: <input type="radio" name="gender" value="Male">Male <input type ="radio" name="gender"
value="Female">Female<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
if ( document.<form_name>.<drop_down_list_name>.selectedIndex == 0 )
{
alert ( "Please select your choice." );
return false;
}
Example
<html>
<head>
<script type="text/javascript">
function validateForm()
{
if ( document.myForm.age.selectedIndex == 0 )
{
alert ( "Please select your Age." );
return false;
}
}
</script>
</head>
<body>
<form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post">
Your Age: <select name="age">
<option value="">Please Select an Option:</option>
<option value="0-18 years">0-18 years</option>
<option value="18-30 years">18-30 years</option>
<option value="30-45 years">30-45 years</option>
<option value="45-60 years">45-60 years</option>
<option value="60+ years">60+ years</option>
</select>
<input type="submit" value="Submit">
</form>
</body>
</html>
if ( document.<form_name>.<checkbox_name>.checked == false )
{
alert ( "Please check the box." );
return false;
}
Example
<html>
<head>
<script type="text/javascript">
function validateForm()
{
if ( document.myForm.terms.checked == false )
{
alert ( "Please check the Terms & Conditions box." );
return false;
}
}
</script>
</head>
<body>
<form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post">
Do you agree to the Terms and Conditions?<input type="checkbox" name="terms" value="Yes"> Yes
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Your Task
Male
Skill:
C++
Java
Pyhton
Major:
Female
Software Engineering
V
Reset
Submit
Back
JSP files are HTML files with special Tags containing Java
source code that provide the dynamic content.
JSP source code runs on the web server in the JSP Servlet
Engine.
tag
Expression tag
Scriptlet tag
<%!
private int counter = 0 ;
private String getAccount ( int accountNo) ;
%>
Register.jsp
1/8
Register.jsp
2/8
Register.jsp
3/8
Register.jsp
4/8
Register.jsp
5/8
//If everythings OK
PreparedStatement stmt = null;
Connection conn = null;
if (firstName!=null && lastName!=null && email!=null && userName!=null && password!=null) {
//Call method to register student
try {
//Connect to the database
Class.forName("oracle.jdbc.driver.OracleDriver");
String hostname = "172.16.60.13";
int port = 1521;
String sid = "orcl";
String oracleURL = "jdbc:oracle:thin:@"+hostname+":"+port+":"+sid;
String user = "salmi";
String pass = "salmi";
conn = DriverManager.getConnection(oracleURL, user, pass);
Register.jsp
6/8
Register.jsp
7/8
Register.jsp
8/8
<html>
<head><title>Register</title></head>
<body>
<% if (message!=null) { %>
<font color = 'red'> <%=message%></font>
<% } %>
<form name ="myForm" method ="post">
<h2> Enter your information in the form below </h2>
<p><b>First Name: </b>
<input type = "text" name = "first_name" values = "" /></p>
<p><b>Last Name: </b>
<input type = "text" name = "last_name" values = "" /></p>
<p><b>Email: </b>
<input type = "text" name = "email" values = "" /></p>
<p><b>User Name: </b>
<input type = "text" name = "username" values = "" /></p>
<p><b>Password: </b>
<input type = "text" name = "password1" values = "" /></p>
<p><b>Confirm Password: </b>
<input type = "text" name = "password2" values = "" /></p>
<p><input type="submit" name ="submit" value="Register" />
</form>
</body>
</html>
Version 2
RegisterForm.html
1/3
<html>
<head>
<title>Register</title>
<script type="text/javascript">
function validateForm()
{
if (document.myForm.first_name.value == null || document.myForm.first_name.value =="") {
alert("Please key-in first-name");
return false;
}
if (document.myForm.last_name.value == null || document.myForm.last_name.value =="") {
alert("Please key-in last-name");
return false;
}
if (document.myForm.email.value == null || document.myForm.email.value =="") {
alert("Please key-in email");
return false;
}
if (document.myForm.username.value == null || document.myForm.username.value =="") {
alert("Please key-in username");
return false;
}
RegisterForm.html
2/3
RegisterForm.html
3/3
</form>
insStudent.jsp
1/2
insStudent.jsp
2/2
Your Task
Modify your HTML codes to add JSP code in order to insert the
information into STUDENT table. Remain the use of JavaScript
code for form validation.
SSK3408 SYSTEM
StudentID:
Name:
Gender:
Male
Skill:
C++
Java
Pyhton
Major:
Female
Software Engineering
V
Reset
Submit
Back