0% found this document useful (0 votes)
19 views16 pages

web-application programs

Uploaded by

Abhay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views16 pages

web-application programs

Uploaded by

Abhay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Program 1: Create an XHTML web page that demonstrates the use of the

following XHTML tags – Paragraphs, headings, and character entities.

Code:

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">


<head>
<title>Program 1: XHTML Tags Demonstration</title>
</head>
<body>
<h1>Welcome to XHTML Tags Demonstration</h1>
<h2>This is an H2 heading</h2>
<h3>This is an H3 heading</h3>
<p>This is a paragraph showcasing the use of character entities
in XHTML:</p>
<p>
&lt; (Less than) <br />
&gt; (Greater than) <br />
&amp; (Ampersand) <br />
&quot; (Double Quote) <br />
&apos; (Single Quote) <br />
</p>
<p>Thank you for viewing this demonstration!</p></body></html>

Output:
Program 2: Create an XHTML web page that demonstrates the use of
Hyperlinks.

Code:

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">


<head>
<title>Program 2: Hyperlinks Demonstration</title>
</head>
<body>
<h1>Hyperlinks Demonstration</h1>
<p>Here are some useful links:</p>
<ul>
<li><a href="https://www.google.com" target="_blank">Visit
Google</a></li>
<li><a href="https://www.wikipedia.org" target="_blank">Visit
Wikipedia</a></li>
<li><a href="#section2">Jump to Section 2</a></li>
</ul>
<h2 id="section2">Section 2</h2>
<p>This is Section 2 of the page, linked from
above.</p></body></html>

Output:
Program 3: Create an XHTML web page that demonstrates the use of
images.

Code:

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>


<title>Program 3: Images Demonstration</title></head><body>
<h1>Images in XHTML</h1>
<p>Here is an image of nature:</p>
<img src="nature.jpg" alt="Beautiful Nature" width="500"
height="300" />
<p>Below is another image:</p>
<img src="flower.jpg" alt="Flower Image" width="300"
height="200" /></body></html>

Output:
Program 4: Create an XHTML web page that demonstrates the usage of
ordered, unordered, and definition lists.

Code:

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>


<title>Program 4: Lists Demonstration</title></head><body>
<h1>Lists in XHTML</h1>
<h2>Ordered List</h2>
<ol>
<li>First Item</li>
<li>Second Item</li>
<li>Third Item</li>
</ol>
<h2>Unordered List</h2>
<ul>
<li>First Item</li>
<li>Second Item</li>
<li>Third Item</li>
</ul>
<h2>Definition List</h2>
<dl>
<dt>HTML</dt>
<dd>Hypertext Markup Language</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets</dd>
</dl></body></html>

Output:
Program 5: Create an XHTML web page that demonstrates the usage of
simple tables in XHTML.

Code:

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>


<title>Program 5: Simple Tables</title></head><body>
<h1>Simple Table in XHTML</h1>
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
<tr>
<td>Alice</td>
<td>25</td>
<td>New York</td>
</tr>
<tr>
<td>Bob</td>
<td>30</td>
<td>Los Angeles</td>
</tr>
</table></body></html>

Output:
Program 6: Create an XHTML web page that demonstrates the usage of
tables in XHTML using cellspacing, cellpadding, rowspan, and colspan
attributes.

Code:

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>


<title>Program 6: Advanced Tables</title></head><body>
<h1>Advanced Table with Cellspacing and Rowspan</h1>
<table border="1" cellspacing="5" cellpadding="10">
<tr>
<th rowspan="2">Name</th>
<th colspan="2">Details</th>
</tr>
<tr>
<th>Age</th>
<th>City</th>
</tr>
<tr>
<td>Alice</td>
<td>25</td>
<td>New York</td>
</tr>
<tr>
<td>Bob</td>
<td>30</td>
<td>Los Angeles</td>
</tr>
</table></body></html>

Output:
Program 7: Create an XHTML page that displays a form with all types of
controls.

Code:

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>


<title>Program 7: Form Controls</title></head><body>
<h1>Form Controls</h1>
<form action="#" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" /><br /><br />

<label for="gender">Gender:</label>
<input type="radio" id="male" name="gender" value="Male" />
Male
<input type="radio" id="female" name="gender"
value="Female" /> Female<br /><br />

<label for="city">City:</label>
<select id="city" name="city">
<option value="newyork">New York</option>
<option value="losangeles">Los Angeles</option>
</select><br /><br />

<label>Hobbies:</label>
<input type="checkbox" name="hobbies" value="Reading" />
Reading
<input type="checkbox" name="hobbies" value="Traveling" />
Traveling<br /><br />

<input type="submit" value="Submit" />


<input type="reset" value="Reset" />
</form></body></html>

Output:
Program 8: Develop a webpage and demonstrate the usage of inline,
internal, and external styles.

Code:

HTML File:
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Program 8: CSS Demonstration</title>
<style>
h1 { color: blue; } /* Internal CSS */
.text-green { color: green; }
</style>
<link rel="stylesheet" href="styles.css" /> <!-- External CSS >
</head>
<body>
<h1>CSS Styles Demonstration</h1>
<p style="color: red;">This is an inline style paragraph.</p>
<p class="text-green">This paragraph uses internal styling.</p>
<p class="external">This paragraph uses external styling.</p>
</body>
</html>

External CSS File (styles.css):


.external {
color: purple;
font-weight: bold;
}

Output:
Program 9: Write a JavaScript function to find the second largest element
in an array.

Code:

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>


<title>Program 9: Second Largest in Array</title>
<script>
function findSecondLargest(arr) {
let uniqueArr = [...new Set(arr)].sort((a, b) => b - a);
return uniqueArr[1] || "Not available";
}
function displayResult() {
let array = [10, 20, 30, 40, 30];
let result = findSecondLargest(array);
alert("Second Largest Element: " + result);
}
</script></head><body>
<button onclick="displayResult()">Find Second
Largest</button></body></html>

Output:
Program 10: Develop a web page to demonstrate event handling
mechanisms using JavaScript.

Code:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Program 10: Event Handling</title>
<script>
function showMessage() {
alert("Button clicked!");
}
</script>
</head>
<body>
<h1>
Event Handling Demo
</h1>
<button onclick="showMessage()">Click Me</button>
</body>
</html>

Output:
Program 11: Install and configure PHP, web server, MySQL, and write
basic PHP programs.

Part a: Installation Steps

1. Install XAMPP/WAMP/MAMP: Install XAMPP or similar software to configure


PHP, MySQL, and the Apache server.
2. Start Services: Launch Apache and MySQL services using the XAMPP/WAMP control
panel.

Output:

Part b: Write a PHP program to print "Welcome to PHP".

Code:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to PHP</title>
</head>
<body>
<?php
echo "Welcome to PHP";
?>
</body>
</html>
Output:
Program 12: Write a PHP program to demonstrate the use of decision-
making control structures.

Code:

<!DOCTYPE html>
<html>
<head>
<title>Decision Making in PHP</title>
</head>
<body>
<?php
$number = 10;

// If statement
if ($number > 0) {
echo "The number is positive.<br />";
}

// If-else statement
if ($number % 2 == 0) {
echo "The number is even.<br />";
} else {
echo "The number is odd.<br />";
}

// Switch statement
switch ($number) {
case 10:
echo "The number is 10.<br />";
break;
default:
echo "The number is not 10.<br />";
}
?>
</body>
</html>
Output:
Program 13: Write a PHP program for creating and manipulating arrays.

Code:

<!DOCTYPE html>
<html>
<head>
<title>Array Manipulation</title>
</head>
<body>
<?php
// Indexed array
$indexed = [1, 2, 3, 4, 5];
echo "Indexed Array: " . implode(", ", $indexed) . "<br />";

// Associative array
$associative = ["Name" => "Alice", "Age" => 25];
echo "Name: " . $associative["Name"] . ", Age: " .
$associative["Age"] . "<br />";

// Multidimensional array
$multi = [
["Apple", "Red"],
["Banana", "Yellow"]
];
echo "First Fruit: " . $multi[0][0] . " - " . $multi[0][1];
?>
</body>
</html>

Output:
Program 14: Develop a web page with data validation.

Code:

<!DOCTYPE html>
<html>
<head>
<title>Data Validation</title>
</head>
<body>
<form method="post" action="">
<label for="email">Email:</label>
<input type="text" id="email" name="email" />
<input type="submit" value="Submit" />
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = $_POST["email"];
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Valid email address.";
} else {
echo "Invalid email address.";
}
}
?>
</body>
</html>

Output:
Program 15: Write a simple PHP program to set cookies and demonstrate
session management.

Code for Setting and Reading Cookies:

<!DOCTYPE html>
<html>
<head>
<title>Cookies Example</title>
</head>
<body>
<?php
// Set a cookie
setcookie("username", "Alice", time() + 3600, "/");

// Read the cookie


if (isset($_COOKIE["username"])) {
echo "Cookie Value: " . $_COOKIE["username"] . "<br />";
} else {
echo "Cookie not set.<br />";
}
?>
</body>
</html>

Output:
Code for Session Management:

<!DOCTYPE html>
<html>
<head>
<title>Session Management</title>
</head>
<body>
<?php
session_start(); // Start session
$_SESSION["user"] = "Alice"; // Set session variable

// Display session variable


if (isset($_SESSION["user"])) {
echo "Session Value: " . $_SESSION["user"] . "<br />";
}
?>
</body>
</html>

Output:

You might also like