WT Lab Final Print
WT Lab Final Print
APPLICATIONS
REG.NO:
SEMESTER-V
NOV–2024
DEPARTMENT OF COMPUTER APPLICATIONS
SRINIVASAN COLLEGE OF ARTS & SCIENCE
(AFFILIATED TO BHARATHIDASAN
UNIVERSITY, TIRUCHIRAPPALLI)
PERAMBALUR - 621212
DEPARTMENT OF COMPUTER
APPLICATIONS
SUBMITTED BY
NAME :
REG.NO :
CLASS :
TITLE :
SEMESTER :
EXAMINERS:
1. 2.
CONTENTS
EX. PAGE REMARKS/
DATE LIST OF PROGRAMS NO. SIGNATURE
NO
Program:
1. Home Page (index.html)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Online Book Store</title>
</head>
<frameset rows="100,*">
<frame Src="header.html" name="headerFrame">
<frameset cols="200,*">
<frame src="navigation.html" name="navFrame">
<frame src="content.html" name="contentFrame">
</frameset>
</frameset>
</html>
Program:
HTML and JavaScript Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form Validation</title>
<script>
function validateForm() {
// Get values from input fields
const firstName = document.getElementById("firstName").value.trim();
const lastName = document.getElementById("lastName").value.trim();
const password = document.getElementById("password").value.trim();
const email = document.getElementById("email").value.trim();
const mobile = document.getElementById("mobile").value.trim();
const address = document.getElementById("address").value.trim();
let errors = [];
// Validate Password
if (password.length < 6) {
errors.push("Password must be at least 6 characters long."); }
// Validate Email
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailPattern.test(email)) {
errors.push("Invalid email format. It should be like [email protected]."); }
// Validate Address
if (address === "") {
errors.push("Address cannot be empty."); }
<label for="password">Password:</label>
<input type="password" id="password" required><br><br>
<label for="email">E-mail:</label>
<input type="email" id="email" required><br><br>
<label for="address">Address:</label>
<textarea id="address" required></textarea><br><br>
Registration successful!
If the user provides invalid input, for example:
- Entering "John" as the first name or a password like "12345", an error list will show:
- First Name must be at least 6 characters long and contain only alphabets.
- Password must be at least 6 characters long.
3. Inline, internal and external style sheet using CSS
Program:
1. HTML File (index.html)
<!DOCTYPE html>7
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=de77vice-width, initial-scale=1.0">
<title>CSS Styles Demonstration</title>
<link rel="stylesheet" href="styles.css"> <!-- External CSS Link -->
<style>
/* Internal CSS */
h1 {
color: blue;
}
p{
font-family: Arial, sans-serif;
font-size: 16px;
}
</style>
</head>
<body>
<h1>This is an Example of CSS Styles</h1>
<p style="color: green;">This paragraph uses inline CSS to make the text green.</p> <!-- Inline
CSS -->
<p>This paragraph uses internal CSS for styling.</p>
<p>This is another paragraph that will be styled using external CSS.</p>
</body>
</html>
/* External CSS */
p{
color: purple; /* This will override internal styles for paragraphs */
}
Output:
When you open index.html in a web browser, the output will appear as follows:
- The first heading (h1) will be blue (styled by internal CSS).
- The first paragraph will be green (styled by inline CSS).
- The second paragraph will be black (styled by internal CSS).
- The last paragraph will be purple (styled by external CSS, overriding the internal styles).
4. Conversion of Numbers to Words using JavaScript
HTML and JavaScript Program:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Number to Words Converter</title>
<script>
function convertToWords(num) {
const belowTwenty = [
"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen",
"Seventeen", "Eighteen", "Nineteen"];
const tens = [
"", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" ];
function validateAndConvert() {
const input = document.getElementById("numberInput").value;
const output = document.getElementById("output");
// Validate input
if (!/^\d{1,3}$/.test(input)) {
output.innerHTML = "Please enter a valid number between 0 and 999.";
return; }
// Convert to words
const words = convertToWords(num);
output.innerHTML = words ? words : "Zero"; }
</script>
</head>
<body>
<h1>Number to Words Converter</h1>
<label for="numberInput">Enter a number (0 - 999): </label>
<input type="text" id="numberInput">
<button onclick="validateAndConvert()">Convert</button>
<p id="output"></p>
</body>
</html>
OUTPUT:
1. index.html
<!DOCTYPE html>
<html>
<head>
<title>Online Library</title>
</head>
<body>
<h1>Welcome to the Online Library</h1>
<form action="LoginServlet" method="post">
Username: <input type="text" name="username"><br>
<input type="submit" value="Login">
</form>
</body>
</html>
2. HomeServlet.java
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/HomeServlet")
public class HomeServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
Cookie[] cookies = request.getCookies();
String username = null;
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("username")) {
username = cookie.getValue();
}
}
}
response.setContentType("text/html");
response.getWriter().println("<h1>Welcome " + (username != null ? username : "Guest") +
"</h1>");
}
}
3. LoginServlet.java
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String username = request.getParameter("username");
// Redirect to HomeServlet
response.sendRedirect("HomeServlet");
}
}
Output:
Welcome John
JavaScript Program:
let inputString = prompt("Enter a string:");
Save : Fibonacci.vbs
Function Fibonacci(n)
Dim fibSeries
Dim i
1.Opent the Terminal and change the file path(Where Your vbs File is Saved)
2.Enter The Comment (PS E:\ar>cscript Fibonacci.vbs) Replace your FileName.vbs
8. Display Date & Time using VB-Script
Save : DisplayDateTime
Program:
' Function to display the current date and time
Function DisplayDateTime()
Dim currentDate, currentTime, formattedDateTime
currentDate = Date() ' Get the current date
currentTime = Time() ' Get the current time
DisplayDateTime = formattedDateTime
End Function
' Ask the user if they want to add days to the current date
userChoice = MsgBox("Do you want to add or subtract days to the current date?", vbYesNo +
vbQuestion, "Add Days")
' Ask the user if they want to add hours to the current time
userChoice = MsgBox("Do you want to add or subtract hours to the current time?", vbYesNo +
vbQuestion, "Add Hours")
Save: ConvertToUpper
Program:
' Function to convert a string to uppercase
Function ConvertToUpper(str)
ConvertToUpper = UCase(str)
End Function
Program:
XML Document (students.xml)
Output:
When you open students.xml in a web browser, you will see a structured display of student
information. The output will look something like this:
Output:
1. *When the user accesses index.html:*
- A login form will be displayed.
Welcome John
// Redirect to HomeServlet
response.sendRedirect("HomeServlet");
}
}
Output:
1. *When the user accesses index.html:*
- A login form will be displayed.
Welcome John