0% found this document useful (0 votes)
3 views

wt (1)

The document contains multiple HTML and JSP templates for web applications, including a Technology Forum, Online Programming Courses, and an Online Banking System. Each section provides a structured layout with interactive elements, forms for user registration and login, and dynamic content display using JavaScript. Additionally, it outlines steps for setting up a web application using Apache Tomcat, creating databases, and implementing servlets for a Railway Reservation system.

Uploaded by

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

wt (1)

The document contains multiple HTML and JSP templates for web applications, including a Technology Forum, Online Programming Courses, and an Online Banking System. Each section provides a structured layout with interactive elements, forms for user registration and login, and dynamic content display using JavaScript. Additionally, it outlines steps for setting up a web application using Apache Tomcat, creating databases, and implementing servlets for a Railway Reservation system.

Uploaded by

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

1.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Technology Forum</title>

<style>

body {

font-family: Arial, sans-serif;

text-align: center;

.info {

margin-top: 20px;

display: none;

</style>

</head>

<body>

<h1>Technology Forum</h1>

<p>Click on the hotspots to explore technologies.</p>

<div>

<!-- Embedding an image with hotspots -->

<img src="technology-forum.jpg" alt="Technology Forum" usemap="#techmap" width="600">

<map name="techmap">

<area shape="rect" coords="50,50,150,150" href="#" alt="AI" onclick="showInfo('ai')">

<area shape="rect" coords="200,50,300,150" href="#" alt="IoT" onclick="showInfo('iot')">

<area shape="rect" coords="350,50,450,150" href="#" alt="Blockchain" onclick="showInfo('blockchain')">

</map>

</div>

<!-- Sections for technology information -->

<div id="ai" class="info">

<h2>Artificial Intelligence</h2>

<p>AI involves creating intelligent machines that can mimic human behavior and decision-making.</p>

</div>

<div id="iot" class="info">

<h2>Internet of Things (IoT)</h2>

<p>IoT connects devices to the internet, enabling data collection and automation.</p>

</div>

<div id="blockchain" class="info">

<h2>Blockchain</h2>

<p>Blockchain is a distributed ledger technology for secure and transparent transactions.</p>


</div>

<script>

function showInfo(id) {

// Hide all info sections

document.querySelectorAll('.info').forEach(section => section.style.display = 'none');

// Show the selected info section

document.getElementById(id).style.display = 'block';

</script>

</body>

</html>

Image jpg: drive

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Online Programming Courses</title>

<style>

body {

font-family: Arial, sans-serif;

margin: 0;

padding: 0;

background-color: #f9f9f9;

color: #333;

header {

background-color: #4CAF50;

color: white;

padding: 20px;

text-align: center;

nav {

text-align: center;

margin: 20px 0;

nav a {

margin: 0 15px;

text-decoration: none;

color: #4CAF50;

font-weight: bold;
}

nav a:hover {

color: #2d7032;

.container {

max-width: 1200px;

margin: auto;

padding: 20px;

section {

margin-bottom: 40px;

padding: 20px;

background: white;

border-radius: 8px;

box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

h2 {

color: #4CAF50;

margin-bottom: 20px;

ul {

list-style-type: none;

padding: 0;

ul li {

margin-bottom: 10px;

padding: 10px;

border-bottom: 1px solid #ddd;

.rating {

color: gold;

footer {

text-align: center;

padding: 20px;

background: #333;

color: white;

</style>

</head>

<body>

<header>

<h1>Learn Programming Online</h1>


<p>Master the skills to code like a pro!</p>

</header>

<nav>

<a href="#courses">Courses</a>

<a href="#features">Features</a>

<a href="#topics">Popular Topics</a>

<a href="#instructors">Instructors</a>

</nav>

<div class="container">

<section id="courses">

<h2>Course Details</h2>

<ul>

<li><strong>Web Development:</strong> HTML, CSS, JavaScript, and React</li>

<li><strong>Data Science:</strong> Python, Machine Learning, and AI</li>

<li><strong>Mobile Development:</strong> Flutter and Swift</li>

</ul>

</section>

<section id="features">

<h2>Course Features</h2>

<ul>

<li>Interactive video lessons</li>

<li>Assignments and quizzes</li>

<li>24/7 mentor support</li>

<li>Certificate of completion</li>

</ul>

</section>

<section id="topics">

<h2>Popular Topics</h2>

<ul>

<li>Machine Learning</li>

<li>Web Development</li>

<li>Blockchain Technology</li>

<li>Cloud Computing</li>

</ul>

</section>

<section id="instructors">

<h2>Popular Course Instructors</h2>

<ul>
<li>John Doe - Expert in Python</li>

<li>Jane Smith - Web Development Specialist</li>

<li>Mike Lee - AI and ML Mentor</li>

</ul>

</section>

<section>

<h2>Ratings</h2>

<ul>

<li>Web Development: <span class="rating">★★★★★</span></li>

<li>Data Science: <span class="rating">★★★★☆</span></li>

<li>Mobile Development: <span class="rating">★★★★☆</span></li>

</ul>

</section>

</div>

<footer>

<p>&copy; 2024 Online Programming Courses. All rights reserved.</p>

</footer>

</body>

</html>

<!DOCTYPE html>

<html>

<head>

<title>Online Banking</title>

<style>

body { font-family: Arial, sans-serif; text-align: center; }

form { margin: 20px auto; width: 300px; padding: 20px; border: 1px solid #ccc; border-radius: 8px; }

input { width: 90%; padding: 10px; margin: 10px 0; }

button { background: green; color: white; padding: 10px 20px; border: none; cursor: pointer; }

button:hover { background: darkgreen; }

</style>

<script>

function validateRegistration() {

const name = document.getElementById("name").value;

const email = document.getElementById("email").value;

const password = document.getElementById("password").value;

if (!name || !email || !password) {

alert("All fields are required!");

return false;

return true;
}

function validateLogin() {

const email = document.getElementById("loginEmail").value;

const password = document.getElementById("loginPassword").value;

if (!email || !password) {

alert("Please fill in all fields!");

return false;

return true;

function validateTransaction() {

const amount = document.getElementById("amount").value;

if (!amount || isNaN(amount) || amount <= 0) {

alert("Enter a valid amount!");

return false;

alert("Transaction Successful!");

return true;

</script>

</head>

<body>

<h1>Online Banking System</h1>

<!-- Home Page -->

<section>

<h2>Welcome to Online Banking</h2>

<p><a href="#register">Register</a> | <a href="#login">Login</a> | <a href="#transaction">Make a Transaction</a></p>

</section>

<!-- Registration Form -->

<section id="register">

<h2>Registration</h2>

<form onsubmit="return validateRegistration()">

<input type="text" id="name" placeholder="Full Name"><br>

<input type="email" id="email" placeholder="Email"><br>

<input type="password" id="password" placeholder="Password"><br>

<button type="submit">Register</button>

</form>

</section>
<!-- Login Form -->

<section id="login">

<h2>User Login</h2>

<form onsubmit="return validateLogin()">

<input type="email" id="loginEmail" placeholder="Email"><br>

<input type="password" id="loginPassword" placeholder="Password"><br>

<button type="submit">Login</button>

</form>

</section>

<!-- Transaction Form -->

<section id="transaction">

<h2>Amount Transaction</h2>

<form onsubmit="return validateTransaction()">

<input type="text" id="amount" placeholder="Enter Amount"><br>

<button type="submit">Send</button>

</form>

</section>

</body>

</html>

4.

Step 1: Install Apache Tomcat

1. Download Tomcat: Go to Tomcat Download and download the latest version of Tomcat.
2. Install: Extract the downloaded file and set the environment variable CATALINA_HOME to the Tomcat
installation directory.
3. Start Tomcat:
o Navigate to the bin folder in the Tomcat directory.
o Run startup.bat (Windows) or ./startup.sh (Linux/Mac).
o Access the Tomcat server at http://localhost:8080.

Step 2: Create a Dynamic Web Application

1. Set Up a Web Application:


o Navigate to the webapps folder in your Tomcat directory.
o Create a folder named OnlineShopping.
2. Create web.xml (Deployment Descriptor): Save the following file as
webapps/OnlineShopping/WEB-INF/web.xml:

xml
Copy code
<web-app>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>user1</param-name>
<param-value>password1</param-value>
</context-param>
<context-param>
<param-name>user2</param-name>
<param-value>password2</param-value>
</context-param>
</web-app>

3. Create Static Pages: Convert the static pages into JSP.

Step 3: Create JSP Files

1. Login Page (index.jsp): Save this file as webapps/OnlineShopping/index.jsp:

jsp
Copy code
<html>
<head><title>Online Shopping - Login</title></head>
<body>
<h1>Login</h1>
<form action="shoppingCart.jsp" method="post">
User ID: <input type="text" name="userid"><br>
Password: <input type="password" name="password"><br>
<input type="submit" value="Login">
</form>
</body>
</html>

2. Shopping Cart Page (shoppingCart.jsp): Save this file as


webapps/OnlineShopping/shoppingCart.jsp:

jsp
Copy code
<%
String userId = request.getParameter("userid");
String password = request.getParameter("password");
String validPassword = getServletContext().getInitParameter(userId);

if (validPassword != null && validPassword.equals(password)) {


Cookie userCookie = new Cookie("userId", userId);
response.addCookie(userCookie);
%>
<h1>Welcome, <%= userId %>!</h1>
<h2>Your Shopping Cart</h2>
<form action="addItem.jsp" method="post">
Item: <input type="text" name="item"><br>
<input type="submit" value="Add to Cart">
</form>
<%
} else {
%>
<h1>Invalid Login. Please try again.</h1>
<a href="index.jsp">Go Back to Login</a>
<%
}
%>

3. Add Item Page (addItem.jsp): Save this file as webapps/OnlineShopping/addItem.jsp:

jsp
Copy code
<%
Cookie[] cookies = request.getCookies();
String userId = null;
for (Cookie cookie : cookies) {
if (cookie.getName().equals("userId")) {
userId = cookie.getValue();
break;
}
}

if (userId != null) {
String item = request.getParameter("item");
%>
<h1>Item Added to Cart</h1>
<p>User: <%= userId %></p>
<p>Item: <%= item %></p>
<a href="shoppingCart.jsp">Go Back to Shopping Cart</a>
<%
} else {
%>
<h1>Session Expired. Please log in again.</h1>
<a href="index.jsp">Login</a>
<%
}
%>

Step 4: Run the Application

1. Start Tomcat if it isn’t running already.


2. Access the app at http://localhost:8080/OnlineShopping.
3. Use user1/password1 or user2/password2 for testing

5.

Step 1: Set Up Environment

1. Install Apache Tomcat as the web server.


2. Install MySQL for the database (or any preferred RDBMS).
3. Set up JDBC Connector for database access in Tomcat.

Step 2: Create a Database

Run the following SQL commands to create the database and tables:

sql
Copy code
CREATE DATABASE RailwayReservation;

USE RailwayReservation;

CREATE TABLE users (


user_id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
password VARCHAR(50) NOT NULL
);

CREATE TABLE tickets (


ticket_id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
train_name VARCHAR(100),
departure_date DATE,
seat_number INT,
FOREIGN KEY (user_id) REFERENCES users(user_id)
);

Step 3: Directory Structure


arduino
Copy code
RailwayReservation/
├── WEB-INF/
│ ├── web.xml
│ ├── lib/ (JDBC driver here)
├── index.jsp
├── login.jsp
├── register.jsp
├── bookTicket.jsp
├── viewTickets.jsp
└── servlets/
├── LoginServlet.java
├── RegisterServlet.java
├── BookTicketServlet.java
└── ViewTicketsServlet.java

Step 4: Deployment Descriptor (web.xml)

Save this as WEB-INF/web.xml:

xml
Copy code
<web-app>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>servlets.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>RegisterServlet</servlet-name>
<servlet-class>servlets.RegisterServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegisterServlet</servlet-name>
<url-pattern>/register</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>BookTicketServlet</servlet-name>
<servlet-class>servlets.BookTicketServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BookTicketServlet</servlet-name>
<url-pattern>/bookTicket</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>ViewTicketsServlet</servlet-name>
<servlet-class>servlets.ViewTicketsServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ViewTicketsServlet</servlet-name>
<url-pattern>/viewTickets</url-pattern>
</servlet-mapping>
</web-app>

Step 5: JSP Pages

1. index.jsp (Home Page)


jsp
Copy code
<html>
<head><title>Railway Reservation</title></head>
<body>
<h1>Welcome to Railway Reservation</h1>
<a href="login.jsp">Login</a> | <a href="register.jsp">Register</a>
</body>
</html>
2. login.jsp (Login Page)
jsp
Copy code
<html>
<head><title>Login</title></head>
<body>
<h2>Login</h2>
<form action="login" method="post">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" value="Login">
</form>
</body>
</html>
3. register.jsp (Registration Page)
jsp
Copy code
<html>
<head><title>Register</title></head>
<body>
<h2>Register</h2>
<form action="register" method="post">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" value="Register">
</form>
</body>
</html>
4. bookTicket.jsp (Book Ticket)
jsp
Copy code
<html>
<head><title>Book Ticket</title></head>
<body>
<h2>Book a Ticket</h2>
<form action="bookTicket" method="post">
Train Name: <input type="text" name="trainName"><br>
Departure Date: <input type="date" name="departureDate"><br>
Seat Number: <input type="number" name="seatNumber"><br>
<input type="submit" value="Book Ticket">
</form>
</body>
</html>
5. viewTickets.jsp (View Tickets)
jsp
Copy code
<html>
<head><title>View Tickets</title></head>
<body>
<h2>Your Tickets</h2>
<table border="1">
<tr>
<th>Train Name</th>
<th>Departure Date</th>
<th>Seat Number</th>
</tr>
<%
// Retrieve tickets from session and display them
java.util.List tickets = (java.util.List) session.getAttribute("tickets");
if (tickets != null) {
for (Object ticket : tickets) {
out.print(ticket);
}
}
%>
</table>
</body>
</html>

Step 6: Servlets

1. LoginServlet
java
Copy code
package servlets;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class LoginServlet extends HttpServlet {


protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");

// Validate against database (dummy check here)


if ("user".equals(username) && "pass".equals(password)) {
HttpSession session = request.getSession();
session.setAttribute("username", username);
response.sendRedirect("bookTicket.jsp");
} else {
response.getWriter().println("Invalid Login!");
}
}
}
2. RegisterServlet
java
Copy code
package servlets;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class RegisterServlet extends HttpServlet {


protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Save username and password into DB
response.getWriter().println("User Registered Successfully!");
}
}
3. BookTicketServlet
java
Copy code
package servlets;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class BookTicketServlet extends HttpServlet {


protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String trainName = request.getParameter("trainName");
String departureDate = request.getParameter("departureDate");
String seatNumber = request.getParameter("seatNumber");

HttpSession session = request.getSession();


session.setAttribute("ticket", trainName + " | " + departureDate + " | " +
seatNumber);
response.sendRedirect("viewTickets.jsp");
}
}

Step 7: Run the Application

1. Start the Tomcat server.


2. Access the app at http://localhost:8080/RailwayReservation.

6.

Directory Structure
scss
Copy code
credit-card-app/
├── index.html (Home Page)
├── login.html (Login Page)
├── register.html (Registration Page)
├── profile.html (Profile Setup Page)
├── payment.html (Payment Details Page)
└── script.js (JavaScript Validation)

1. index.html (Home Page)


html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Credit Card System</title>
</head>
<body>
<h1>Welcome to Credit Card System</h1>
<a href="register.html">Register</a> | <a href="login.html">Login</a>
</body>
</html>

2. register.html (Registration Page)


html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register</title>
</head>
<body>
<h1>Register</h1>
<form id="registerForm">
Full Name: <input type="text" id="fullName"><br><br>
Email: <input type="email" id="email"><br><br>
Password: <input type="password" id="password"><br><br>
Confirm Password: <input type="password" id="confirmPassword"><br><br>
<button type="submit">Register</button>
</form>
<script src="script.js"></script>
</body>
</html>

3. login.html (Login Page)


html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
</head>
<body>
<h1>Login</h1>
<form id="loginForm">
Email: <input type="email" id="loginEmail"><br><br>
Password: <input type="password" id="loginPassword"><br><br>
<button type="submit">Login</button>
</form>
<script src="script.js"></script>
</body>
</html>

4. profile.html (Profile Setup Page)


html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Profile</title>
</head>
<body>
<h1>Set Up Profile</h1>
<form id="profileForm">
Address: <input type="text" id="address"><br><br>
Phone: <input type="tel" id="phone"><br><br>
Credit Card Number: <input type="text" id="creditCard"><br><br>
<button type="submit">Save Profile</button>
</form>
<script src="script.js"></script>
</body>
</html>

5. payment.html (Payment Page)


html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Payment</title>
</head>
<body>
<h1>Payment Details</h1>
<form id="paymentForm">
Amount: <input type="number" id="amount"><br><br>
Expiry Date: <input type="month" id="expiryDate"><br><br>
CVV: <input type="password" id="cvv" maxlength="3"><br><br>
<button type="submit">Pay</button>
</form>
<script src="script.js"></script>
</body>
</html>

6. script.js (JavaScript for Validation)


javascript
Copy code
// Registration Validation
document.getElementById('registerForm')?.addEventListener('submit', function (e) {
e.preventDefault();

const fullName = document.getElementById('fullName').value;


const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
const confirmPassword = document.getElementById('confirmPassword').value;

if (fullName === '' || email === '' || password === '' || confirmPassword === '') {
alert('All fields are required!');
return;
}
if (password !== confirmPassword) {
alert('Passwords do not match!');
return;
}
alert('Registration Successful!');
});

// Login Validation
document.getElementById('loginForm')?.addEventListener('submit', function (e) {
e.preventDefault();

const email = document.getElementById('loginEmail').value;


const password = document.getElementById('loginPassword').value;

if (email === '' || password === '') {


alert('All fields are required!');
return;
}
alert('Login Successful!');
});

// Profile Validation
document.getElementById('profileForm')?.addEventListener('submit', function (e) {
e.preventDefault();

const address = document.getElementById('address').value;


const phone = document.getElementById('phone').value;
const creditCard = document.getElementById('creditCard').value;

if (address === '' || phone === '' || creditCard === '') {


alert('All fields are required!');
return;
}
if (!/^\d{16}$/.test(creditCard)) {
alert('Invalid Credit Card Number!');
return;
}
alert('Profile Saved Successfully!');
});

// Payment Validation
document.getElementById('paymentForm')?.addEventListener('submit', function (e) {
e.preventDefault();

const amount = document.getElementById('amount').value;


const expiryDate = document.getElementById('expiryDate').value;
const cvv = document.getElementById('cvv').value;

if (amount === '' || expiryDate === '' || cvv === '') {


alert('All fields are required!');
return;
}
if (!/^\d{3}$/.test(cvv)) {
alert('Invalid CVV!');
return;
}
alert('Payment Successful!');
});

How to Run

1. Save all files in a folder.


2. Open the index.html in any browser to start the application.
3. Follow the links to register, log in, set up the profile, and make a payment.

7.

1. students.xml (XML File)


xml
Copy code
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="students.xsl"?>
<students>
<student>
<id>1</id>
<name>John Doe</name>
<age>20</age>
<grade>A</grade>
</student>
<student>
<id>2</id>
<name>Jane Smith</name>
<age>22</age>
<grade>B</grade>
</student>
<student>
<id>3</id>
<name>Mike Johnson</name>
<age>21</age>
<grade>A</grade>
</student>
<student>
<id>4</id>
<name>Emily Davis</name>
<age>19</age>
<grade>C</grade>
</student>
<student>
<id>5</id>
<name>Chris Brown</name>
<age>23</age>
<grade>B</grade>
</student>
<student>
<id>6</id>
<name>Sarah Wilson</name>
<age>20</age>
<grade>A</grade>
</student>
<student>
<id>7</id>
<name>David Lee</name>
<age>22</age>
<grade>C</grade>
</student>
<student>
<id>8</id>
<name>Anna Moore</name>
<age>21</age>
<grade>B</grade>
</student>
<student>
<id>9</id>
<name>Paul Taylor</name>
<age>24</age>
<grade>A</grade>
</student>
<student>
<id>10</id>
<name>Laura Harris</name>
<age>20</age>
<grade>B</grade>
</student>
</students>

2. students.xsl (XSLT File)


xml
Copy code
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<head>
<title>Student Information</title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid black;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h1>Student Information</h1>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
<th>Grade</th>
</tr>
<xsl:for-each select="students/student">
<tr>
<td><xsl:value-of select="id"/></td>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="age"/></td>
<td><xsl:value-of select="grade"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

How to Run

1. Save the students.xml and students.xsl files in the same directory.


2. Open the students.xml file in any browser that supports XSLT (e.g., Chrome or Firefox).
3. The data will be displayed in a tabular format using the XSLT transformation.

HTML and JavaScript Code


html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>E-Learning Library Registration</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
form {
max-width: 400px;
margin: auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.1);
}
input {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 5px;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<h1>E-Learning Library Registration</h1>
<form id="registrationForm" onsubmit="return validateForm()">
<label for="username">Username:</label>
<input type="text" id="username" name="username" placeholder="Enter your
username">

<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Enter your email">

<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Enter your
password">

<label for="confirmPassword">Confirm Password:</label>


<input type="password" id="confirmPassword" name="confirmPassword"
placeholder="Confirm your password">

<button type="submit">Register</button>
</form>

<script>
function validateForm() {
const username = document.getElementById('username').value.trim();
const email = document.getElementById('email').value.trim();
const password = document.getElementById('password').value;
const confirmPassword = document.getElementById('confirmPassword').value;

if (username === "") {


alert("Username is required.");
return false;
}
if (email === "") {
alert("Email is required.");
return false;
}
if (!email.includes("@") || !email.includes(".")) {
alert("Enter a valid email address.");
return false;
}
if (password === "") {
alert("Password is required.");
return false;
}
if (password.length < 6) {
alert("Password must be at least 6 characters long.");
return false;
}
if (password !== confirmPassword) {
alert("Passwords do not match.");
return false;
}

alert("Registration successful!");
return true;
}
</script>
</body>
</html>

Features

1. Validates fields for empty values.


2. Ensures a valid email format.
3. Checks that the password is at least 6 characters long.
4. Ensures the password and confirm password fields match.
5. Displays appropriate alert messages for errors or successful registration.

How to Use

1. Copy the code into an .html file.


2. Open the file in a browser.
3. Fill in the registration form fields.
4. Click "Register" to see the validation in action.

9.

HTML Code
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>College Information</title>
<style>
/* Embedded Style Sheets */
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f4f4f9;
}
header {
text-align: center;
background-color: #007bff;
color: white;
padding: 10px 0;
border-radius: 5px;
}
section {
margin: 20px 0;
}
.info {
background-color: #eaf7ff;
padding: 15px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<header>
<h1>Welcome to ABC College</h1>
</header>

<section>
<h2>About Us</h2>
<p class="info" style="color: #333; font-size: 16px; line-height: 1.5;">
ABC College was established in 1990 with the aim of providing quality
education in science, arts, and technology.
Located in a serene environment, our college offers state-of-the-art
facilities and a vibrant campus life.
</p>
</section>

<section>
<h2>Departments</h2>
<ul class="info" style="font-size: 14px;">
<li style="color: #007bff;">Computer Science</li>
<li style="color: #007bff;">Electronics</li>
<li style="color: #007bff;">Business Administration</li>
<li style="color: #007bff;">Arts and Humanities</li>
</ul>
</section>

<section>
<h2>Contact Us</h2>
<p class="info" style="font-size: 16px;">
Email: <span style="color: #007bff;">info@abccollege.edu</span><br>
Phone: <span style="color: #007bff;">+123 456 7890</span><br>
Address: 123 College Lane, City, Country.
</p>
</section>
</body>
</html>

Key Features

1. Embedded CSS:
o Applied in the <style> tag within the <head> section for global styles (e.g., body, header,
section).
2. Inline CSS:
o Added directly to elements using the style attribute for specific styles (e.g., text color, font
size in <p> and <li>).
How to Use

1. Copy and paste the code into an .html file.


2. Open the file in a web browser to view the styled college information page.

9.

HTML with Embedded, External, and Inline CSS

HTML File (hospital_management.html):

html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hospital Management System</title>
<link rel="stylesheet" href="styles.css"> <!-- External CSS -->
<style>
/* Embedded CSS */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f9;
}
h1, h2 {
color: #2c3e50;
}
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
}
th, td {
border: 1px solid #bdc3c7;
padding: 10px;
text-align: center;
}
th {
background-color: #3498db;
color: white;
}
tr:nth-child(even) {
background-color: #ecf0f1;
}
footer {
margin-top: 20px;
text-align: center;
background-color: #2c3e50;
color: white;
padding: 10px;
}
</style>
</head>
<body>
<header style="background-color: #3498db; color: white; padding: 20px; text-align:
center;">
<!-- Inline CSS -->
<h1>Hospital Management System</h1>
</header>

<section>
<h2>Doctor Details</h2>
<table>
<tr>
<th>Doctor ID</th>
<th>Name</th>
<th>Specialization</th>
<th>Contact</th>
</tr>
<tr>
<td>101</td>
<td>Dr. Smith</td>
<td>Cardiology</td>
<td>123-456-7890</td>
</tr>
<tr>
<td>102</td>
<td>Dr. Johnson</td>
<td>Neurology</td>
<td>987-654-3210</td>
</tr>
</table>

<h2>Patient Records</h2>
<table>
<tr>
<th>Patient ID</th>
<th>Name</th>
<th>Age</th>
<th>Diagnosis</th>
</tr>
<tr>
<td>P001</td>
<td>John Doe</td>
<td>35</td>
<td>Flu</td>
</tr>
<tr>
<td>P002</td>
<td>Jane Smith</td>
<td>42</td>
<td>Diabetes</td>
</tr>
</table>

<h2>Appointment Details</h2>
<table>
<tr>
<th>Appointment ID</th>
<th>Patient Name</th>
<th>Doctor Name</th>
<th>Date</th>
<th>Time</th>
</tr>
<tr>
<td>A001</td>
<td>John Doe</td>
<td>Dr. Smith</td>
<td>2024-12-02</td>
<td>10:00 AM</td>
</tr>
<tr>
<td>A002</td>
<td>Jane Smith</td>
<td>Dr. Johnson</td>
<td>2024-12-03</td>
<td>11:00 AM</td>
</tr>
</table>

<h2>Pharmacy Inventory</h2>
<table>
<tr>
<th>Medicine ID</th>
<th>Medicine Name</th>
<th>Quantity</th>
<th>Price</th>
</tr>
<tr>
<td>M001</td>
<td>Paracetamol</td>
<td>50</td>
<td>$2</td>
</tr>
<tr>
<td>M002</td>
<td>Insulin</td>
<td>20</td>
<td>$25</td>
</tr>
</table>

<h2>Billing Records</h2>
<table>
<tr>
<th>Bill ID</th>
<th>Patient Name</th>
<th>Total Amount</th>
<th>Status</th>
</tr>
<tr>
<td>B001</td>
<td>John Doe</td>
<td>$150</td>
<td>Paid</td>
</tr>
<tr>
<td>B002</td>
<td>Jane Smith</td>
<td>$200</td>
<td>Pending</td>
</tr>
</table>
</section>

<footer>
<p>&copy; 2024 Hospital Management System. All Rights Reserved.</p>
</footer>
</body>
</html>

CSS File (styles.css):


css
Copy code
/* External CSS */
section {
margin: 20px auto;
width: 90%;
background-color: #ffffff;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
padding: 20px;
}
h2 {
text-align: left;
margin-left: 10%;
color: #2980b9;
}

Features

1. Inline CSS: Used for the header background and text styling.
2. Embedded CSS: Styled tables, body, and footer within the <style> tag in the <head>.
3. External CSS: Used for sections and headings in the linked styles.css.

10.

PROGRAM:
//index.jsp
<html>
<head>
<title>Processing get requests with data</title>
</head>
<body>
<form action = "Servlet3" method = "get">
<b><p><label>Enter Your name Please!!
<br />
<input type = "text" name = "firstname" />
<input type = "submit" value = "Submit" />
</label></p></b>
</form>
</body>
</html>
//Servlet3.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Servlet3 extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponseresponse)
throws ServletException, IOException
{
String firstName = request.getParameter( "firstname" );
response.setContentType( "text/html" );
PrintWriter out = response.getWriter();
// send XHTML document to client
// start XHTML documentout.println( "<html>" );
// head section of documentout.println( "<head>" );
out.println("<title>Processing get requests with data</title>" );
out.println( "</head>" );
// body section of documentout.println( "<body>" );
out.println( "<h1>Hello " + firstName + ",<br />" );
out.println( "Welcome to Servlets!</h1>" );
out.println( "</body>" );
// end XHTML document
out.println( "</html>" );
out.close(); // close stream to complete the page
}
public String
getServletInfo() {
return "Short
description";
}
}
Program (ii)
Session tracking
GfgSession.java
// Java Program to Illustrate Creation and last-accessed
// Times for a Session
// Import required java libraries
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
// Extend HttpServlet class
public class GfgSession extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws
ServletException, IOException
{
// Create a session object if it is already not
// created.
HttpSession session = request.getSession(true);
// Get session creation time.
Date createTime= new Date(session.getCreationTime());
// Get last access time of this web page.
Date lastAccessTime = new Date(session.getLastAccessedTime());
String title = "Welcome Back to GraceCollege";
Integer visitCount = new Integer(0);
String visitCountKey = new String("visitCount");
String userIDKey = new String("userID");
String userID = new String("GFG");
// Check if this is new comer on your web page.
if (session.isNew()) {
title = "Welcome to GraceCollege";
session.setAttribute(userIDKey, userID);
}
else {
visitCount = (Integer)session.getAttribute(visitCountKey);
visitCount = visitCount + 1;
userID= (String)session.getAttribute(userIDKey);
}
session.setAttribute(visitCountKey, visitCount);
// Set response content
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String docType= "<!doctype html public \"-//w3c//dtd html 4.0
"+"transitional//en\">\n";
out.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n"+
"<body bgcolor = \"#f0f0f0\">\n"
+ "<h1 align = \"center\">" + title + "</h1>\n"
+ "<h2 align = \"center\">Gfg Session Information</h2>\n"
+ "<table border = \"1\" align = \"center\">\n"
+
"<tr bgcolor = \"#949494\">\n"
+ " <th>Session info</th><th>value</th>"
+ "</tr>\n"
+
"<tr>\n"
+ " <td>id</td>\n"
+ " <td>" + session.getId() + "</td>"
+ "</tr>\n"
+
"<tr>\n"
+ " <td>Creation Time</td>\n"
+ " <td>" + createTime + " </td>"
+ "</tr>\n"
+
"<tr>\n"
+ " <td>Time of Last Access</td>\n"
+ " <td>" + lastAccessTime + "</td>"
+ "</tr>\n"
+
"<tr>\n"
+ " <td>User ID</td>\n"
+ " <td>" + userID + "</td>"
+ "</tr>\n"
+
"<tr>\n"
+ " <td>Number of visits</td>\n"
+ " <td>" + visitCount + "</td>"
+ "</tr>\n"
+ "</table>\n"
+ "</body>"
+ "</html>");
}
}
web.xml
<web-app>
<servlet>
<servlet-name>GfgSession</servlet-name>
<servlet-class>GfgSession</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>GfgSession</servlet-name>
<url-pattern>/GfgSession</url-pattern>
</servlet-mapping>

</web-app>
11

Step 1: XML Document (products.xml)


xml
Copy code
<?xml version="1.0" encoding="UTF-8"?>
<inventory>
<product>
<id>101</id>
<name>Smartphone</name>
<category>Electronics</category>
<price>300</price>
<stock>50</stock>
</product>
<product>
<id>102</id>
<name>Wireless Earbuds</name>
<category>Accessories</category>
<price>50</price>
<stock>100</stock>
</product>
<product>
<id>103</id>
<name>Laptop</name>
<category>Computers</category>
<price>800</price>
<stock>20</stock>
</product>
</inventory>

Step 2: HTML and JavaScript Code

Save this file as index.html.

html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inventory Management System</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
form {
margin-bottom: 20px;
}
#result {
background-color: #f4f4f9;
padding: 15px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<h1>Inventory Management System</h1>
<form onsubmit="fetchProductDetails(event)">
<label for="productId">Enter Product ID:</label>
<input type="text" id="productId" required>
<button type="submit">Get Product Details</button>
</form>
<div id="result"></div>

<script>
function fetchProductDetails(event) {
event.preventDefault();

const productId = document.getElementById('productId').value;

// Load XML document


fetch('products.xml')
.then(response => response.text())
.then(data => {
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(data, "text/xml");

const products = xmlDoc.getElementsByTagName('product');


let found = false;

for (let product of products) {


const id = product.getElementsByTagName('id')[0].textContent;

if (id === productId) {


const name =
product.getElementsByTagName('name')[0].textContent;
const category =
product.getElementsByTagName('category')[0].textContent;
const price =
product.getElementsByTagName('price')[0].textContent;
const stock =
product.getElementsByTagName('stock')[0].textContent;

document.getElementById('result').innerHTML = `
<h2>Product Details</h2>
<p><strong>Name:</strong> ${name}</p>
<p><strong>Category:</strong> ${category}</p>
<p><strong>Price:</strong> $${price}</p>
<p><strong>Stock:</strong> ${stock} units</p>
`;
found = true;
break;
}
}

if (!found) {
document.getElementById('result').innerHTML = '<p>Product not
found.</p>';
}
})
.catch(error => {
console.error('Error fetching XML:', error);
document.getElementById('result').innerHTML = '<p>Error loading
product data.</p>';
});
}
</script>
</body>
</html>

How It Works

1. The XML file (products.xml) stores product information.


2. The HTML page provides an input form for the product ID.
3. When the user submits the form:
o JavaScript fetches and parses the XML file.
o It searches for the product with the matching ID.
o Displays the product details if found, or an error message if not.

How to Use

1. Save products.xml and index.html in the same directory.


2. Open index.html in a browser.
3. Enter a product ID (e.g., 101, 102, 103) and click "Get Product Details."
4. The product details will be displayed below the form

12

1. Conducting Recruitment Examination

Database Structure (MySQL)


sql
Copy code
CREATE DATABASE RecruitmentDB;

USE RecruitmentDB;

CREATE TABLE candidates (


candidate_id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
password VARCHAR(100) NOT NULL
);

CREATE TABLE questions (


question_id INT PRIMARY KEY AUTO_INCREMENT,
question_text TEXT NOT NULL,
option_a VARCHAR(100),
option_b VARCHAR(100),
option_c VARCHAR(100),
option_d VARCHAR(100),
correct_option CHAR(1)
);
JSP for Exam Page ( exam.jsp)
jsp
Copy code
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<title>Recruitment Examination</title>
</head>
<body>
<h1>Recruitment Examination</h1>
<form method="post" action="submit_exam.jsp">
<%
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/RecruitmentDB", "root",
"password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM questions");
while (rs.next()) {
out.println("<div>");
out.println("<p>" + rs.getString("question_text") + "</p>");
out.println("<input type='radio' name='q" +
rs.getInt("question_id") + "' value='A'> " + rs.getString("option_a") + "<br>");
out.println("<input type='radio' name='q" +
rs.getInt("question_id") + "' value='B'> " + rs.getString("option_b") + "<br>");
out.println("<input type='radio' name='q" +
rs.getInt("question_id") + "' value='C'> " + rs.getString("option_c") + "<br>");
out.println("<input type='radio' name='q" +
rs.getInt("question_id") + "' value='D'> " + rs.getString("option_d") + "<br>");
out.println("</div>");
}

con.close();
} catch (Exception e) {
out.println("Error: " + e.getMessage());
}
%>
<button type="submit">Submit Exam</button>
</form>
</body>
</html>
JSP for Exam Submission ( submit_exam.jsp)
jsp
Copy code
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<title>Exam Results</title>
</head>
<body>
<h1>Exam Results</h1>
<%
int score = 0;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/RecruitmentDB", "root",
"password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM questions");

while (rs.next()) {
String correctOption = rs.getString("correct_option");
String userAnswer = request.getParameter("q" +
rs.getInt("question_id"));

if (correctOption.equals(userAnswer)) {
score++;
}
}

out.println("<p>Your Score: " + score + "</p>");


con.close();
} catch (Exception e) {
out.println("Error: " + e.getMessage());
}
%>
</body>
</html>

2. Displaying Candidate Mark List


Database Structure Update

Add a marks column to store candidate marks:

sql
Copy code
ALTER TABLE candidates ADD marks INT DEFAULT 0;
JSP for Displaying Mark List ( mark_list.jsp)
jsp
Copy code
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<title>Candidate Mark List</title>
</head>
<body>
<h1>Candidate Mark List</h1>
<table border="1">
<tr>
<th>Candidate ID</th>
<th>Name</th>
<th>Email</th>
<th>Marks</th>
</tr>
<%
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/RecruitmentDB", "root",
"password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM candidates");

while (rs.next()) {
out.println("<tr>");
out.println("<td>" + rs.getInt("candidate_id") + "</td>");
out.println("<td>" + rs.getString("name") + "</td>");
out.println("<td>" + rs.getString("email") + "</td>");
out.println("<td>" + rs.getInt("marks") + "</td>");
out.println("</tr>");
}

con.close();
} catch (Exception e) {
out.println("Error: " + e.getMessage());
}
%>
</table>
</body>
</html>

How It Works

1. Three-Tier Architecture:
o Database Tier: MySQL database stores candidates, questions, and their marks.
o Application Tier: Java code in JSP interacts with the database to fetch/store data.
o Presentation Tier: HTML/CSS displays the data to the user.
2. Process:
o Candidates take the exam through exam.jsp.
o The system evaluates and displays their score in submit_exam.jsp.
o Admins or authorized users view the mark list via mark_list.jsp.
3. Setup:
o Configure a Tomcat server and deploy the JSP files.
o Update the database connection credentials in the JSP code ( username, password).
o Test the system using localhost.

This ensures a seamless and modular recruitment examination system.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy